PHPackages                             phpmath/biginteger - 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. phpmath/biginteger

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

phpmath/biginteger
==================

A PHP library to work with big integers.

2.1.0(8y ago)235.8k4[1 issues](https://github.com/phpmath/biginteger/issues)1MITPHPPHP ~7.0CI passing

Since Apr 18Pushed 8mo ago2 watchersCompare

[ Source](https://github.com/phpmath/biginteger)[ Packagist](https://packagist.org/packages/phpmath/biginteger)[ Docs](https://github.com/phpmath/biginteger)[ RSS](/packages/phpmath-biginteger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (1)

biginteger
==========

[](#biginteger)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1dd79ae7d27e3172346ad3790edc58cd78c9437ab301ceaefea3fe829435db29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706d6174682f626967696e74656765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpmath/biginteger)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/064ee99a88612e42c5e5f3f13fd345cb6b0881c6edd99e4679e4e9c21856e4a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706d6174682f626967696e74656765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpmath/biginteger/stats)

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

Install
-------

[](#install)

Via Composer

```
$ composer require phpmath/biginteger
```

Usage
-----

[](#usage)

There are two ways to create a BigInteger. A mutable or immutable BigInteger.

```
$number = new PHP\Math\BigInteger\MutableBigInteger('8273467836243255543265432745');
$number = new PHP\Math\BigInteger\ImmutableBigInteger('8273467836243255543265432745');
```

```
$a = new PHP\Math\BigInteger\ImmutableBigInteger('12345678901234567890');
$b = new PHP\Math\BigInteger\ImmutableBigInteger('98765432109876543210');

$sum = $a->add($b);

echo $sum->value();
```

Features
--------

[](#features)

This library provides a wide range of operations for working with big integers using the GMP extension:

### Basic Arithmetic

[](#basic-arithmetic)

- Add, subtract, multiply, and divide large numbers.
- Calculate powers and roots of numbers.
- Perform modulo operations.
- Negate numbers and get absolute values.

### Comparison

[](#comparison)

- Compare numbers using `cmp()` and check equality with `equals()`.
- Determine the sign of a number (positive, negative, or zero).

### Bitwise Operations

[](#bitwise-operations)

- Perform bitwise AND, OR, XOR, and NOT operations.
- Compute Hamming distance between numbers.

### Number Theory

[](#number-theory)

- Calculate factorials.
- Check if numbers are prime or likely prime.
- Compute modular inverses.
- Compute Jacobi, Legendre, and Kronecker symbols.
- Calculate greatest common divisors (GCD) and least common multiples (LCM).
- Check for perfect squares and perfect powers.
- Find the next prime number.
- Compute binomial coefficients.

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

[](#change-log)

We keep a changelog for every release, have a look at the [releases overview](https://github.com/phpmath/biginteger/releases).

Testing
-------

[](#testing)

```
$ composer test
```

To generate code coverage:

```
$ composer test-coverage
```

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

[](#contributing)

All contributions are welcome. Feel free to create a PR or open an issue.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Walter Tamboer](https://github.com/waltertamboer)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance42

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 89.2% 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

Every ~190 days

Total

4

Last Release

3111d ago

Major Versions

1.0.0 → 2.0.02016-11-14

PHP version history (2 changes)1.0.0PHP &gt;=5.3.3

2.0.0PHP ~7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ee7f711ef4d45ada0ac92c7ab2f548055a7cfbe718da6c4bbb81b2f6693c528?d=identicon)[waltertamboer](/maintainers/waltertamboer)

---

Top Contributors

[![waltertamboer](https://avatars.githubusercontent.com/u/508054?v=4)](https://github.com/waltertamboer "waltertamboer (58 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (6 commits)")[![abenevaut](https://avatars.githubusercontent.com/u/1134021?v=4)](https://github.com/abenevaut "abenevaut (1 commits)")

---

Tags

bigintegermathmathematicsphp7BigIntegermathintegerPHP7phpmath

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phpmath-biginteger/health.svg)

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

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[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)[phpseclib/bcmath_compat

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

16720.7M17](/packages/phpseclib-bcmath-compat)[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)[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)
