MATH_BIGINTEGER_MODE
MATH_BIGINTEGER_MODE
Pure-PHP arbitrary precision integer arithmetic library.
Supports base-2, base-10, base-16, and base-256 numbers. Uses the GMP or BCMath extensions, if available, and an internal implementation, otherwise.
PHP version 5
{@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the {@link self::MODE_INTERNAL self::MODE_INTERNAL} mode)
BigInteger uses base-226 to perform operations such as multiplication and division and base-252 (ie. two base 226 digits) to perform addition and subtraction. Because the largest possible value when multiplying two base-226 numbers together is a base-2**52 number, double precision floating point numbers - numbers that should be supported on most hardware and whose significand is 53 bits - are used. As a consequence, bitwise operators such as >> and << cannot be used, nor can the modulo operator %, which only supports integers. Although this fact will slow this library down, the fact that such a high base is being used should more than compensate.
Numbers are stored in {@link http://en.wikipedia.org/wiki/Endianness little endian} format. ie. (new \phpseclib\Math\BigInteger(pow(2, 26)))->value = array(0, 1)
Useful resources are as follows:
Here's an example of how to use this library:
<?php
$a = new \phpseclib\Math\BigInteger(2);
$b = new \phpseclib\Math\BigInteger(3);
$c = $a->add($b);
echo $c->toString(); // outputs 5 ?>
BigInteger | Pure-PHP arbitrary precision integer arithmetic library. Supports base-2, base-10, base-16, and base-256 numbers. |