PHP Classes

PHP BCMath Extension: Add missing functions missing in BCMath

Recommend this page to a friend!
  Info   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-01-25 (2 days ago) RSS 2.0 feedStarStarStarStar 64%Total: 216 This week: 3All time: 8,270 This week: 170Up
Version License PHP version Categories
bcmath-extended 1.3.25MIT/X Consortium ...5.3PHP 5, Utilities and Tools, Math
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
PHP Programming Innovation award nominee
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
Picture of Kacper Rowinski
  Performance   Level  
Name: Kacper Rowinski <contact>
Classes: 14 packages by
Country: Poland Poland
Innovation award
Innovation award
Nominee: 8x

Details

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.

  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 directory)
Files folder imagetests (1 directory)
Accessible without login Plain text file badge-coverage.svg Data Auxiliary data
Accessible without login Plain text file clover.xml Data Auxiliary data
Accessible without login Plain text file CODE_OF_CONDUCT.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file ecs.php Example Example script
Accessible without login Plain text file ISSUE_TEMPLATE.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file tests.yml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageBCMathExtended (1 file)

  Files folder image Files  /  src  /  BCMathExtended  
File Role Description
  Plain text file BC.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageUnit (1 file)

  Files folder image Files  /  tests  /  Unit  
File Role Description
  Accessible without login Plain text file BCTest.php Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:216
This week:3
All time:8,270
This week:170Up
 User Ratings  
 
 All time
Utility:91%StarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:-
Examples:-
Tests:91%StarStarStarStarStar
Videos:-
Overall:64%StarStarStarStar
Rank:940