Math_BigInteger
[ class tree: Math_BigInteger ] [ index: Math_BigInteger ] [ all elements ]

File: Math_BigInteger.php

Source Location: /Math_BigInteger-1.0.0RC2/Math_BigInteger.php

Classes:

Math_BigInteger
Pure-PHP arbitrary precission integer arithmetic library. Supports base-2, base-10, base-16, and base-256 numbers. Negative numbers are supported in all publically accessable functions save for modPow and modInverse.

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).

Useful resources are as follows:

One idea for optimization is to use the comba method to reduce the number of operations performed. MPM uses this quite extensively. The following URL elaborates:

http://www.everything2.com/index.pl?node_id=1736418}}

Here's a quick 'n dirty example of how to use this library:

  1.  <?php
  2.     include('Math_BigInteger.php');
  3.  
  4.     $a = new Math_BigInteger(2);
  5.     $b = new Math_BigInteger(3);
  6.  
  7.     $c $a->add($b);
  8.  
  9.     echo $c->toString()// outputs 5
  10.   ?>

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

Includes:

require_once('PHP/Compat/Function/bcpowmod.php') [line 81]
Include PHP_Compat module bcpowmod since that function does not exist in PHP4:

http://pear.php.net/package/PHP_Compat/ http://php.net/function.bcpowmod


Documentation generated on Thu, 16 Nov 2006 21:00:04 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.