marcoconsiglio/bcmath-extended 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marcoconsiglio/bcmath-extended

Composer 安装命令:

composer require marcoconsiglio/bcmath-extended

包简介

The BCMathExtended library extends the PHP BCMath extension adding more features like abs, min, max, random, factorial, type comparison between integer and decimal or positive and negative, modulo and power modulo with negative modulus (see more on BCMath extendsion http://php.net/manual/en/book.bc.

README 文档

README

GitHub License GitHub Release Static Badge
Static Badge Static Badge Static Badge

bcmath-extended

This PHP library extends the BCMath PHP estension. Since the class BCMath\Number is a final class, this library extends through composition with a child class (Number).

It was inspired by krowinski/bcmath-extended.

Index

Installation

composer require marcoconsiglio/bcmath-extended

Features

Base features

The following list of features of the Number class are the same as those found in BCMath\Number:

  • Base instance $value
  • Base instance $scale
  • Addition
  • Subtracion
  • Multiplication
  • Division
  • Exponentiation
  • Square root
  • Ceil
  • Floor
  • Round
  • Cast to string type

Missing base features

These are the missing features:

  • Spaceship comparison
  • Comparison operator overloading
  • Serialization/unserialization

Added features

This list consists of the new features added in this library:

  • float type input **
  • Cast to float type **
  • Cast to int type
  • Modulo *
  • Power & modulo *
  • Division & modulo *
  • Absolute
  • Min
  • Max
  • Random
  • Equal comparison
  • Different comparison
  • Greater than comparison
  • Greater than or equal comparison
  • Less than comparison
  • Less than or equal comparison
  • In range comparison
  • In range min excluded comparison
  • In range max excluded comparison
  • In range both extremes excluded comparison
  • Convert to radian
  • Convert to degree
  • Opposite sign

Input types

This is the input types set available:

  • int
  • string
  • float **
  • BCMath\Number
  • MarcoConsiglio\BCMathExtended\Number

String numeric format

  • Only decimal separator . is allowed.
  • Thousand separator is not supported.
  • Scientific notation is not supported (use Number::string() method to cast very big or small float numbers to numeric string without scientific notation).

For example "1234567.89" is allowed while "1,234,567.89" is not.

Notes

* Consideration on modulo operation

As already pointed by krowinsky in PHP issue #76287

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.

the modulo operation in BCMath extension is not correct in case the modulus is negative. Therefore in this library the following formula is used:

$$ a \pmod n = a - n \times \left \lfloor {\dfrac{a}{n}} \right \rfloor $$

With this formula a negative modulus $n$ is allowed.

** Consideration on float type

If you need to convert a float to Number and back, prepare for the worst. Keep in mind that floating point arithmetic is full of hidden flaws, that's why aribtrary arithmetic is needed (in this case implemented by BcMath PHP extension).

While this library accept a float type input, it is not recommended to cast a Number instance to float, otherwise nasty things could happen.

Use this library only for end calculations, like print a report. If other subsystem of your software need float type inputs, it is strongly advised to avoid this library for intermediate calculations.

API documentation

You can find the API documentation at docs/html/index.html.

marcoconsiglio/bcmath-extended 适用场景与选型建议

marcoconsiglio/bcmath-extended 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 222 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「math」 「precision」 「bcmath」 「rand」 「Arbitrary-precision」 「bignumber」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 marcoconsiglio/bcmath-extended 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 marcoconsiglio/bcmath-extended 我们能提供哪些服务?
定制开发 / 二次开发

基于 marcoconsiglio/bcmath-extended 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 222
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 39
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-19