krowinski / bcmath-extended
扩展php BCMath库以支持floor、ceil、round、abs、min、max、rand等大数函数。同时封装了现有的BCMath函数。(更多信息:https://php.ac.cn/manual/en/book.bc.php)支持科学记数法。
7.0.0
2023-01-25 21:31 UTC
Requires
- php: ^7.4|^8.0
- ext-bcmath: *
Requires (Dev)
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.0
- symplify/easy-coding-standard: ^11.1
README
扩展php BCMath库以支持floor、ceil、round、abs、min、max、rand等大数函数。同时封装了现有的BCMath函数。(更多信息:https://php.ac.cn/manual/en/book.bc.php)
安装
composer require krowinski/bcmath-extended
功能
- config
- setTrimTrailingZeroes - 禁用/启用尾随零(默认为启用裁剪)
- 新工具方法
- convertScientificNotationToString - 将科学记数法转换为字符串
- getScale - 获取当前全局刻度
- getDecimalsLengthFromNumber - 获取小数位数
- hexdec - 十六进制转十进制
- dechex - 十进制转十六进制
- bin2dec - 二进制转十进制
- dec2bin - 十进制转二进制
- 新数学函数
- round
- abs
- rand
- max
- min
- roundDown
- roundUp
- roundHalfEven
- ceil
- exp
- log
- fact
- pow (支持分数)
- mod (支持分数 + php 5.6 及以下版本中的刻度)
- 位运算符
- bitXor
- bitOr
- bitAnd
- 原始函数的代理(https://php.ac.cn/manual/en/book.bc.php)
- 所有函数支持科学记数法
- 所有函数都是静态的,因此可以很容易地用这个库替换
信息
截至7.2版本,float可以传递给bcmod,但它们返回的值不正确(据我所知)
我在https://bugs.php.net/bug.php?id=76287中创建了关于此的bug,但它被标记为文档问题而不是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.
但我在这个库中仍然会使用不截断的floor来实现mod。