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

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:
  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




Tags:

author:  Jim Wigginton <terrafrost@php.net>
version:  $Id: BigInteger.php,v 1.1 2010/05/14 14:06:16 gruberroland Exp $
copyright:  MMVI Jim Wigginton
link:  http://pear.php.net/package/Math_BigInteger
license:  http://www.gnu.org/licenses/lgpl.txt








Documentation generated on Thu, 28 Oct 2010 21:00:08 +0200 by phpDocumentor 1.4.1