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

Class: Math_BigInteger

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

Class Overview


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.


Author(s):

Version:

  • 1.0.0RC1

Methods


Inherited Variables

Inherited Methods


Class Details

[line 156]
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.


[ Top ]


Method Detail

Math_BigInteger (Constructor)   [line 206]

Math_BigInteger Math_BigInteger( [optional $x = 0], [optional $base = 10])

Converts base-2, base-10, base-16, and binary strings (eg. base-256) to BigIntegers.

Here's a quick 'n dirty example:

  1.  <?php
  2.     include('Math_BigInteger.php');
  3.  
  4.     $a = new Math_BigInteger('0x32'16)// 50 in base-16
  5.  
  6.     echo $a->toString()// outputs 50
  7.  ?>

  • Access: public

Parameters:

optional   $x   —  base-10 number or base-$base number if $base set.
optional   $base   —  integer $base

[ Top ]

abs   [line 1524]

Math_BigInteger abs( )

Returns the absolute value.
  • Access: public

[ Top ]

add   [line 480]

Math_BigInteger add( Math_BigInteger $y)

Adds two BigIntegers.

Here's a quick 'n dirty example:

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

  • Access: public

Parameters:

Math_BigInteger   $y   — 

[ Top ]

compare   [line 1550]

Integer compare( Math_BigInteger $x)

Compares two numbers.
  • Return: < 0 if $this is less than $x; > 0 if $this is greater than $x, and 0 if they are equal.
  • Access: public

Parameters:

Math_BigInteger   $x   — 

[ Top ]

divide   [line 806]

Array divide( Math_BigInteger $y)

Divides two BigIntegers.

Returns an array whose first element contains the quotient and whose second element contains the "common residue". If the remainder would be positive, the "common residue" and the remainder are the same. If the remainder would be negative, the "common residue" is equal to the sum of the remainder and the divisor.

Here's a quick 'n dirty example:

  1.  <?php
  2.     include('Math_BigInteger.php');
  3.  
  4.     $a = new Math_BigInteger('10');
  5.     $b = new Math_BigInteger('20');
  6.  
  7.     list($quotient,$remainder$a->divide($b);
  8.  
  9.     echo $quotient->toString()// outputs 0
  10.     echo "\r\n";
  11.     echo $remainder->toString()// outputs 10
  12.  ?>

  • Access: public

Parameters:

Math_BigInteger   $y   — 

[ Top ]

modInverse   [line 1376]

mixed modInverse( Math_BigInteger $n)

Calculates modular inverses.

Here's a quick 'n dirty example:

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

  • Return: false, if no modular inverse exists, Math_BigInteger, otherwise.
  • Access: public

Parameters:

Math_BigInteger   $n   — 

[ Top ]

modPow   [line 989]

Math_BigInteger modPow( Math_BigInteger $e, Math_BigInteger $n)

Performs modular exponentiation.

Here's a quick 'n dirty example:

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

  • Access: public

Parameters:

Math_BigInteger   $e   — 
Math_BigInteger   $n   — 

[ Top ]

multiply   [line 667]

Math_BigInteger multiply( Math_BigInteger $x)

Multiplies two BigIntegers

Here's a quick 'n dirty example:

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

  • Access: public

Parameters:

Math_BigInteger   $x   — 

[ Top ]

subtract   [line 567]

Math_BigInteger subtract( Math_BigInteger $y)

Subtracts two BigIntegers.

Here's a quick 'n dirty example:

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

  • Access: public

Parameters:

Math_BigInteger   $y   — 

[ Top ]

toBytes   [line 357]

String toBytes( )

Converts a BigInteger to a byte string (eg. base-256).

Here's a quick 'n dirty example:

  1.  <?php
  2.     include('Math_BigInteger.php');
  3.  
  4.     $a = new Math_BigInteger('65');
  5.  
  6.     echo $a->toBytes()// outputs chr(65)
  7.  ?>

  • Access: public

[ Top ]

toString   [line 422]

String toString( )

Converts a BigInteger to a base-10 number.

Here's a quick 'n dirty example:

  1.  <?php
  2.     include('Math_BigInteger.php');
  3.  
  4.     $a = new Math_BigInteger('50');
  5.  
  6.     echo $a->toString()// outputs 50
  7.  ?>

  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:48:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.