PHPackages                             bardoqi/bigmath - 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. bardoqi/bigmath

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

bardoqi/bigmath
===============

A PHP library to work with big integers and big decimals in most easy way.

0.0.2(5y ago)10111MITPHPPHP ~7.0CI failing

Since Nov 26Pushed 5y ago2 watchersCompare

[ Source](https://github.com/BardoQi/BigMath)[ Packagist](https://packagist.org/packages/bardoqi/bigmath)[ Docs](https://github.com/BardoQi/BigMath)[ RSS](/packages/bardoqi-bigmath/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

```
_______   __            __       __             __      __
|       \ |  \          |  \     /  \           |  \    |  \
| $$$$$$$\ \$$  ______  | $$\   /  $$  ______  _| $$_   | $$____
| $$__/ $$|  \ /      \ | $$$\ /  $$$ |      \|   $$ \  | $$    \
| $$    $$| $$|  $$$$$$\| $$$$\  $$$$  \$$$$$$\\$$$$$$  | $$$$$$$\
| $$$$$$$\| $$| $$  | $$| $$\$$ $$ $$ /      $$ | $$ __ | $$  | $$
| $$__/ $$| $$| $$__| $$| $$ \$$$| $$|  $$$$$$$ | $$|  \| $$  | $$
| $$    $$| $$ \$$    $$| $$  \$ | $$ \$$    $$  \$$  $$| $$  | $$
 \$$$$$$$  \$$ _\$$$$$$$ \$$      \$$  \$$$$$$$   \$$$$  \$$   \$$
              |  \__| $$
               \$$    $$
                \$$$$$$

```

BigMath
=======

[](#bigmath)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d7ce9bd103962a8a4a9d7a61fe4b498ea3601e65aeb235794f3de43ea3e1189c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626172646f71692f6269676d617468)](https://packagist.org/packages/bardoqi/bigmath)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/b70e24b842f95ff367d8dca639859b53ffc7faac5c4b6d53a79f65e8696a6c2d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626172646f71692f6269676d6174682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bardoqi/bigmath)

A PHP library to work with big integers. This library makes use of the GMP extension and bcmath to do its calculations.

Introduction
------------

[](#introduction)

Maybe you ara a developer of blockchain using php. Maybe you often coding encrypt and decrypt. And you fund that there is no library easy to use for big integer or high precision number in php. Now you could coding in most easy way with the BigMath!

Install
-------

[](#install)

Via Composer

```
$ composer require bardoqi/bigmath:dev-master
```

Usage
-----

[](#usage)

```
    //with pecl Operator overloading extension:
    $number = BInt('8273467836243255543265432745') + BInt('2');
    //without pecl Operator overloading extension:
    $number = BInt('8273467836243255543265432745')->add(BInt('2'));
```

Features
--------

[](#features)

This library supports the following operations:

- Big Intgeger and high precision decimal support ....Class BigInteger: using with GMP. ....Class BigDecminal: using with bcmath.
- Global type converting functions; .... You need not use 'new' operator to create new object. .... You Only need use:

```
     //to get a new BigInteger instance of $var;
     BInt($var);
     //to get a new BigDecimal instance of $var;
     BDec($var);
```

- Simple init Mothod: of(string $value)
- Support using with [pecl Operator overloading extension](https://github.com/php/pecl-php-operator), there are operators could be used:

OperatorMethod$o + $arg`__add($arg)`$o - $arg`__sub($arg)`$o \* $arg`__mul($arg)`$o / $arg`__div($arg)`$o % $arg`__mod($arg)`$o \*\* $arg`__pow($arg)`$o . $arg`__concat($arg)`$o | $arg`__bw_or($arg)`$o &amp; $arg`__bw_and($arg)`$o ^ $arg`__bw_xor($arg)`$o === $arg`__is_identical($arg)`$o !== $arg`__is_not_identical($arg)`$o == $arg`__is_equal($arg)`$o != $arg`__is_not_equal($arg)`$o &lt; $arg`__is_smaller($arg)`$o &lt;= $arg`__is_smaller_or_equal($arg)`$o &gt; $arg`__is_greater($arg)` \*$o &gt;= $arg`__is_greater_or_equal($arg)` \*$o &lt;=&gt; $arg`__cmp($arg)`++$o`__pre_inc()`$o++`__post_inc()`--$o`__pre_dec()`$o--`__post_dec()`$o = $arg`__assign($arg)`$o += $arg`__assign_add($arg)`$o -= $arg`__assign_sub($arg)`$o \*= $arg`__assign_mul($arg)`$o /= $arg`__assign_div($arg)`$o %= $arg`__assign_mod($arg)`$o \*\*= $arg`__assign_pow($arg)`$o |= $arg`__assign_bw_or($arg)`$o &amp;= $arg`__assign_bw_and($arg)`$o ^= $arg`__assign_bw_xor($arg)`- If without [pecl Operator overloading extension](https://github.com/php/pecl-php-operator), there are mothods of operators could be used:

Operatorsmethod+add()-sub(), substract()\*mul(), multiply()/div(), divide()%mod()\*\*pow(), power()++plus(), increment()--minus(), devrement==eq(), equals()!=ne(), notEquals()===identical()!==notIdentical(()&gt;gt(), greaterThan()&gt;=gte() greaterThanOrEqualsTo()&lt;lt(), lessThan()&lt;=lte(), lessThanOrEqualsTo()&lt;=&gt;cmp(), compareTo()-negate().concat()- Mothods for coding simple: max(); min(); even(); odd(); sign(); isOne(); isZero(); randomRange();
- Mothods of Mathematics: abs(); divideRem; powMod(); squareRoot();
    factorial(); gcd();
- Mothods for bit orpeator(Only in BigInteger) andBits(); orBits(); clearBits(); complement() invert(); setBit(); testBit(); scan0(); scan1();
- Mothods of Math Theory(Only in BigInteger) isPrime(); jacobi(); legendre(); perfectSquare() popcount(); root();
- Chain Operators support: You can just use:

```
    //with pecl Operator overloading extension:
    $x=($a+$b)*($c-$d);
    //without pecl Operator overloading extension:
    $x=BInt($a)->add(BInt($b))->multiply(BInt($c)->substract(BInt($d)));
```

Sample Code
-----------

[](#sample-code)

```
    //with Operator overloading extension:
    //if sample:
    if(abs($big_g)>abs($big_m)){
        $big_g = $big_g % $big_m;
    }

    //while sample:
    While (rt_v!=1){
        $x = $rd_v/$rt_v;
        //...
    }

    //for sample:
    for($i=$xstart; $iabs($big_m)){...}
    if ($big_g->abs()->gt($big_m->abs())){
        $big_g = $big_g->mod($big_m);
    }

    //while sample:
    //While (rt_v!=1){...}
    while (!($rt_v->isOne())){ //rt!=1
        //x=rd/rt
        $x = $rd_v->div($rt_v);
        //...
    }

    //for sample:
    //for($i=$xstart; $ilt(BInt($xMax)); $i->plus($step)){
        $item = &$data[];
        $item['x']=$i;
    }

    //More samples please read the code in exanples!
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Road Map
--------

[](#road-map)

Add: '&lt;&lt;' and '&gt;&gt;' Operator to class BigInteger

Add: '~' Operator to class BigInteger

Add: trigonometric functions such as sin cos etc to class BigDecimal

Add: inverse trigonometric function such as asin acos etc to class BigDecimal

Add: hyperbolic trigonometric functions such as sinh cosh etc to class BigDecimal

Add: high precision math constant such as e and pi.

Add: rational number class

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please create an issue in the issue tracker.

Credits
-------

[](#credits)

- [Bardo Qi](https://github.com/bardoqi)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

1995d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bfb2d0271845406a6b777d824993d97eec9f249b61ffa43b86994698b988e30?d=identicon)[bardoqi](/maintainers/bardoqi)

---

Top Contributors

[![BardoQi](https://avatars.githubusercontent.com/u/409367?v=4)](https://github.com/BardoQi "BardoQi (15 commits)")

---

Tags

arithmeticbcmathbigdecimalbigintegerbigmathgmphigh-precisionmathmathsphp7BigIntegermathintegerbigdecimalPHP7phpmathbigmathbigcomplex

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bardoqi-bigmath/health.svg)

```
[![Health](https://phpackages.com/badges/bardoqi-bigmath/health.svg)](https://phpackages.com/packages/bardoqi-bigmath)
```

###  Alternatives

[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)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[phpmath/biginteger

A PHP library to work with big integers.

235.8k1](/packages/phpmath-biginteger)[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2751.4M5](/packages/rubix-tensor)[prestashop/decimal

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

178.2M5](/packages/prestashop-decimal)

PHPackages © 2026

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