Introduction
Integers of any size for PHP, built on the GMP extension. Every number is an immutable value object.
Requirements#
The library needs a current PHP version and the GMP extension, which does the heavy lifting.
- PHP 8.4 or newer
- The
gmpextension
Installation#
Install the library with Composer. This also checks that the GMP extension is available.
composer require phpmath/biginteger
A first example#
Create a number from a string or an integer. Use a string for anything that does not fit in a PHP integer.
use PHPMath\BigInteger\BigInteger;
$a = new BigInteger('12345678901234567890');
$b = new BigInteger('98765432109876543210');
$sum = $a->add($b);
echo $sum->value(); // 111111111011111111100
Calling add() did not change $a. It returned a new BigInteger. This is true for every operation in the library.
Where to go next#
Start with the core concepts, or jump straight to the topic you need.