The Wayback Machine - https://web.archive.org/web/20230307132201/https://github.com/krowinski/bcmath-extended
Skip to content

krowinski/bcmath-extended

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

bcmath-extended

PHP Tests Code Coverage Latest Stable Version Total Downloads License

Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions. (more http://php.net/manual/en/book.bc.php)

Installation

composer require krowinski/bcmath-extended

Features

  • config
    • setTrimTrailingZeroes - disable|enable trailing zeros (default trimming is enabled)
  • new tool methods
    • convertScientificNotationToString - converts scientific notation to string
    • getScale - gets current global scale
    • getDecimalsLengthFromNumber - gets amount of decimals
    • hexdec - converting from hexadecimal to decimal
    • dechex - converting from decimal to hexadecimal
    • bin2dec - converting from binary to decimal
    • dec2bin - converting from decimal to binary
  • new math functions
    • round
    • abs
    • rand
    • max
    • min
    • roundDown
    • roundUp
    • roundHalfEven
    • ceil
    • exp
    • log
    • fact
    • pow (supports fractional)
    • mod (supports fractional + scale in php 5.6 <)
    • bitwise operators
      • bitXor
      • bitOr
      • bitAnd
  • proxy for original functions (http://php.net/manual/en/book.bc.php)
  • all functions supports scientific notation
  • all functions are static, so it can be easily replaced by this lib

Info

As of 7.2 float can be passed to bcmod, but they don't return correct values (IMO)

I created bug for this in https://bugs.php.net/bug.php?id=76287, but it was commented as documentation issue not a bug.

bcmod() doesn't use floor() but rather truncates towards zero,
which is also defined this way for POSIX fmod(), so that the
result always has the same sign as the dividend.  Therefore, this
is not a bug, but rather a documentation issue.

But I still will use floor not truncated for mod in this lib.

About

Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages