Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2025-06-27 (8 days ago)  | |    64% | | Total: 221 | | All time: 8,265 This week: 126 |
|
Description | | Author |
This class adds missing functions missing in BCMath.
It uses the BCMath extension functions to add more math operation functions that the extension is missing.
Currently it adds functions like floor, ceil, round, abs, min, max and rand. Innovation Award
 March 2016
Number 7 |
The BCMath extension can perform several types of operations with numbers of unlimited precision.
This class can implement several types of arbitrary precision operations not yet implemented by the BCMath extension like floor, ceil, round, abs, min, max and rand.
Manuel Lemos |
| |
 |
|
Innovation award
 Nominee: 8x |
|
Details
bcmath-extended

Extends php BCMath lib for missing functions like abs, min, max, rand, fact, log for big numbers.
Handles scientific notation like 1.0E+35 to be used with BCMath.
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
- convertToNumber - converts scientific notation, string and int to BcMath\Number
- 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)
- bitwise operators
- bitXor
- bitOr
- bitAnd
-
proxy for original functions
-
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.
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.