Procedural File: BigInteger.php
Source Location: /lib/3rdParty/phpseclib/Math/BigInteger.php
Classes:
Math_BigInteger
Pure-PHP arbitrary precision integer arithmetic library. Supports base-2, base-10, base-16, and base-256 numbers.
Page Details:
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 versions 4 and 5 {@ mode) Math_BigInteger uses base-2**26 to perform operations such as multiplication and division and base-2**52 (ie. two base 2**26 digits) to perform addition and subtraction. Because the largest possible value when multiplying two base-2**26 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. When PHP version 6 is officially released, we'll be able to use 64-bit integers. This should, once again, allow bitwise operators, and will increase the maximum possible base to 2**31 (or 2**62 for addition / subtraction). Numbers are stored in little endian format. ie. (new 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
include('Math/BigInteger.php');
$c = $a->add($b);
echo $c->toString(); // outputs 5
?>
LICENSE: This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Tags:
|