A PHP library to work with big integers. This library makes use of the GMP extension to do its calculations.
The full documentation is at https://phpmath.github.io/biginteger/. Every change is listed in the changelog and every release on the releases page.
composer require phpmath/biginteger- PHP 8.4 or newer
- The
gmpextension
Every BigInteger is an immutable value object. Operations never change the instance they are
called on, they return a new instance.
$number = new PHPMath\BigInteger\BigInteger('8273467836243255543265432745');$a = new PHPMath\BigInteger\BigInteger('12345678901234567890');
$b = new PHPMath\BigInteger\BigInteger('98765432109876543210');
$sum = $a->add($b);
echo $sum->value();This library provides a wide range of operations for working with big integers using the GMP extension:
- Add, subtract, multiply, and divide large numbers.
- Calculate powers and roots of numbers.
- Perform modulo operations.
- Negate numbers and get absolute values.
- Compare numbers using
cmp()and check equality withequals(). - Determine the sign of a number (positive, negative, or zero).
- Perform bitwise AND, OR, XOR, and NOT operations.
- Compute Hamming distance between numbers.
- 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.
composer test
composer test-coverage
composer analyse
composer check-style
composer fix-styleAll contributions are welcome. Open an issue or a pull request on GitHub. Please follow the coding standard and add tests.
If you discover a security issue, please create an issue in the issue tracker.
The MIT License (MIT). Please see License File for more information.