Math_BigInteger

# 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: Handbook of Applied Cryptography (HAC) Multi-Precision Math (MPM) Java's BigInteger classes. See /j2se/src/share/classes/java/math in jdk-1_5_0-src-jrl.zip Here's an example of how to use this library: <?php include('Math/BigInteger.php'); $a = new Math_BigInteger(2); $b = new Math_BigInteger(3); $c = $a->add($b); echo $c->toString(); // outputs 5 ?> LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #### Tags:
author: | Jim Wigginton <terrafrost@php.net>
version: | $Id: BigInteger.php,v 1.2 2011/05/19 18:02:11 gruberroland Exp $
copyright: | MMVI Jim Wigginton
link: | http://pear.php.net/package/Math_BigInteger
license: | MIT License
Documentation generated on Tue, 22 Nov 2011 16:29:33 +0100 by phpDocumentor 1.4.1