PHPackages                             marcoconsiglio/bcmath-extended - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. marcoconsiglio/bcmath-extended

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

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.php).

v2.2.0(2mo ago)016↓50%1MITPHPPHP ^8.4

Since Feb 19Pushed 1mo agoCompare

[ Source](https://github.com/MarcoConsiglio/bcmath-extended)[ Packagist](https://packagist.org/packages/marcoconsiglio/bcmath-extended)[ RSS](/packages/marcoconsiglio-bcmath-extended/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (6)Versions (11)Used By (1)

[![GitHub License](https://camo.githubusercontent.com/21868e2a6a1af429172c912fd60fbaab1f4bc8286c3128a9ee0bbb53f379d9e7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d6172636f436f6e7369676c696f2f62636d6174682d657874656e646564)](https://camo.githubusercontent.com/21868e2a6a1af429172c912fd60fbaab1f4bc8286c3128a9ee0bbb53f379d9e7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d6172636f436f6e7369676c696f2f62636d6174682d657874656e646564)[![GitHub Release](https://camo.githubusercontent.com/cbb13599b0edfc414af00cd8d23c10611da489427cdb6bdb36e1dfcfdfe7ffb4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4d6172636f436f6e7369676c696f2f62636d6174682d657874656e646564)](https://camo.githubusercontent.com/cbb13599b0edfc414af00cd8d23c10611da489427cdb6bdb36e1dfcfdfe7ffb4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4d6172636f436f6e7369676c696f2f62636d6174682d657874656e646564)[![Static Badge](https://camo.githubusercontent.com/9777a865458188ee78218612fc51c098f633ec64d834c860934f94502990710d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d76322e322e312d7768697465)](https://camo.githubusercontent.com/9777a865458188ee78218612fc51c098f633ec64d834c860934f94502990710d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d76322e322e312d7768697465)
[![Static Badge](https://camo.githubusercontent.com/ad3623dee92c129d4491a09fdd2ca65ace14cdf58d3b3539435c5d2352cc2b71/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f39392532352d7267622834302532432532303136372532432532303639293f6c6162656c3d4c696e65253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)](https://camo.githubusercontent.com/ad3623dee92c129d4491a09fdd2ca65ace14cdf58d3b3539435c5d2352cc2b71/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f39392532352d7267622834302532432532303136372532432532303639293f6c6162656c3d4c696e65253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)[![Static Badge](https://camo.githubusercontent.com/f344347968ec83f9c071ab410b3d51533e8a515185c4e3486077491d22c79428/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f39312532352d7267622834302532432532303136372532432532303639293f6c6162656c3d4272616e6368253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)](https://camo.githubusercontent.com/f344347968ec83f9c071ab410b3d51533e8a515185c4e3486077491d22c79428/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f39312532352d7267622834302532432532303136372532432532303639293f6c6162656c3d4272616e6368253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)[![Static Badge](https://camo.githubusercontent.com/b3637ca69559df0cc188a2a6b794969bc43a57673abbcf7fcb67640f03556ba1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f38322532352d7267622832353525324331393325324337293f6c6162656c3d50617468253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)](https://camo.githubusercontent.com/b3637ca69559df0cc188a2a6b794969bc43a57673abbcf7fcb67640f03556ba1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f38322532352d7267622832353525324331393325324337293f6c6162656c3d50617468253230636f766572616765266c6162656c436f6c6f723d7267622832353525324332353525324332353529)

bcmath-extended
===============

[](#bcmath-extended)

This PHP library extends the [BCMath PHP estension](https://www.php.net/manual/en/book.bc.php). Since the class [`BCMath\Number`](https://www.php.net/manual/en/class.bcmath-number.php) is a final class, this library extends through composition with a child class ([`Number`](src/Number.php)).

It was inspired by [krowinski/bcmath-extended](https://github.com/krowinski/bcmath-extended).

Index
-----

[](#index)

- [Installation](#installation)
- [Features](#features)
- [Input types](#input-types)
- [Notes](#notes)
- [API documentation](#api-documentation)

Installation
------------

[](#installation)

```
composer require marcoconsiglio/bcmath-extended

```

Features
--------

[](#features)

### Base 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

### Missing base features

[](#missing-base-features)

These are the missing features:

- Spaceship comparison
- Comparison operator overloading
- Serialization/unserialization

### Added features

[](#added-features)

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

- `float` type input [\*\*](#note_2)
- Cast to `float` type [\*\*](#note_2)
- Modulo [\*](#note_1)
- Power &amp; modulo [\*](#note_1)
- Division &amp; modulo [\*](#note_1)
- Absolute
- Min
- Max
- Random
- Equal comparison
- Different comparison
- Greater than comparison
- Greater than or equal comparison
- Less than comparison
- Less than or equal comparison
- Convert to radian
- Convert to degree

Input types
-----------

[](#input-types)

The same input type set of BCMath is used:

- `int`
- [`string`](#string-numeric-format)
- `float` [\*\*](#note_2)
- `BCMath\Number`
- `MarcoConsiglio\BCMathExtended\Number`

### String numeric format

[](#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
-----

[](#notes)

### \* Consideration on modulo operation

[](#-consideration-on-modulo-operation)

As already pointed by *krowinsky* in [PHP issue #76287](https://bugs.php.net/bug.php?id=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

[](#-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
-----------------

[](#api-documentation)

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

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance89

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

7

Last Release

69d ago

Major Versions

v1.2.0 → v2.0.02026-02-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/5fb36102dfc597a74e864afc65952e328f158bff88f21ad993c1d79c51c80133?d=identicon)[MarcoConsiglio](/maintainers/MarcoConsiglio)

---

Top Contributors

[![krowinski](https://avatars.githubusercontent.com/u/1478555?v=4)](https://github.com/krowinski "krowinski (68 commits)")[![MarcoConsiglio](https://avatars.githubusercontent.com/u/39809954?v=4)](https://github.com/MarcoConsiglio "MarcoConsiglio (68 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")[![Sander-Toonen](https://avatars.githubusercontent.com/u/5106372?v=4)](https://github.com/Sander-Toonen "Sander-Toonen (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![gnutix](https://avatars.githubusercontent.com/u/310134?v=4)](https://github.com/gnutix "gnutix (1 commits)")[![mbezhanov](https://avatars.githubusercontent.com/u/785542?v=4)](https://github.com/mbezhanov "mbezhanov (1 commits)")[![aywan](https://avatars.githubusercontent.com/u/5608711?v=4)](https://github.com/aywan "aywan (1 commits)")[![jimmy4o4](https://avatars.githubusercontent.com/u/19704458?v=4)](https://github.com/jimmy4o4 "jimmy4o4 (1 commits)")

---

Tags

mathArbitrary-precisionbignumberroundprecisionbcmathrandceilfloorabs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/marcoconsiglio-bcmath-extended/health.svg)

```
[![Health](https://phpackages.com/badges/marcoconsiglio-bcmath-extended/health.svg)](https://phpackages.com/packages/marcoconsiglio-bcmath-extended)
```

###  Alternatives

[krowinski/bcmath-extended

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) Supports scientific notations

791.0M19](/packages/krowinski-bcmath-extended)[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[phpseclib/bcmath_compat

PHP 5.x-8.x polyfill for bcmath extension

16720.7M17](/packages/phpseclib-bcmath-compat)[prestashop/decimal

Object-oriented wrapper/shim for BC Math PHP extension. Allows for arbitrary-precision math operations.

178.2M5](/packages/prestashop-decimal)[php-decimal/php-decimal

Correctly-rounded arbitrary precision decimal floating point

781.0M9](/packages/php-decimal-php-decimal)[aza/math

AzaMath - Anizoptera CMF mathematic component. Arbitrary precision arithmetic (for huge integers; BCMath wrapper) and universal convertor between positional numeral systems (supported bases from 2 to 62 inclusive, and systems with custom alphabet; pure PHP realisation, can use GMP and core PHP functions for speed optimization).

1921.9k1](/packages/aza-math)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
