Math_BigInteger (Constructor) [line 259]
Converts base-2, base-10, base-16, and binary strings (base-256) to BigIntegers.
If the second parameter - $base - is negative, then it will be assumed that the number's are encoded using two's compliment. The sole exception to this is -10, which is treated the same as 10 is.
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
abs [line 2625]
add [line 845]
Adds two BigIntegers.
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
bitwise_and [line 2759]
bitwise_leftRotate [line 2993]
Logical Left Rotate
Instead of the top x bits being dropped they're appended to the shifted bit string.
Parameters:
bitwise_leftShift [line 2956]
Logical Left Shift
Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift.
Parameters:
bitwise_not [line 2879]
bitwise_or [line 2800]
bitwise_rightRotate [line 3037]
Logical Right Rotate
Instead of the bottom x bits being dropped they're prepended to the shifted bit string.
Parameters:
bitwise_rightShift [line 2918]
Logical Right Shift
Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift.
Parameters:
bitwise_xor [line 2840]
Logical Exclusive-Or
Parameters:
compare [line 2661]
Compares two numbers.
Although one might think !$x->compare($y) means $x != $y, it, in fact, means the opposite. The reason for this is demonstrated thusly:
$x > $y: $x->compare($y) > 0 $x < $y: $x->compare($y) < 0 $x == $y: $x->compare($y) == 0
Note how the same comparison operator is used. If you want to test for equality, use $x->equals($y).
Parameters:
copy [line 739]
Copy an object
PHP5 passes objects by reference while PHP4 passes by value. As such, we need a function to guarantee that all objects are passed by value, when appropriate. More information can be found here:
http://php.net/language.oop5.basic#51624
divide [line 1398]
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 (basically, the "common residue" is the first positive modulo).
Here's an example: <?php
include('Math/BigInteger.php');
list
($quotient, $remainder) =
$a->divide($b);
echo
$quotient->toString();
// outputs 0
echo "\r\n";
echo
$remainder->toString();
// outputs 10
?>
Parameters:
equals [line 2719]
Tests the equality of two numbers.
If you need to see if one number is greater than or less than another number, use Math_BigInteger::compare()
Parameters:
extendedGCD [line 2482]
Calculates the greatest common divisor and Bezout's identity.
Say you have 693 and 609. The GCD is 21. Bezout's identity states that there exist integers x and y such that 693*x + 609*y == 21. In point of fact, there are actually an infinite number of x and y combinations and which combination is returned is dependant upon which mode is in use. See Bezout's identity - Wikipedia for more information.
Here's an example: <?php
include('Math/BigInteger.php');
echo
$gcd->toString() .
"\r\n";
// outputs 21
?>
Parameters:
gcd [line 2613]
Calculates the greatest common divisor
Say you have 693 and 609. The GCD is 21.
Here's an example: <?php
include('Math/BigInteger.php');
echo
$gcd->toString() .
"\r\n";
// outputs 21
?>
Parameters:
isPrime [line 3296]
Boolean isPrime(
[optional
$t = false])
|
|
Checks a numer to see if it's prime
Assuming the $t parameter is not set, this function has an error rate of 2**-80. The main motivation for the $t parameter is distributability. Math_BigInteger::randomPrime() can be distributed accross multiple pageloads on a website instead of just one.
Parameters:
modInverse [line 2416]
Calculates modular inverses.
Say you have (30 mod 17 * x mod 17) mod 17 == 1. x can be found using modular inverses.
Here's an example: <?php
include('Math/BigInteger.php');
echo "\r\n";
echo $d; // outputs 1 (as per the definition of modular inverse)
?>
Parameters:
modPow [line 1636]
Performs modular exponentiation.
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
multiply [line 1111]
Multiplies two BigIntegers
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
powMod [line 1776]
Performs modular exponentiation.
Alias for Math_BigInteger::modPow()
Parameters:
random [line 3093]
Generate a random number
Parameters:
randomPrime [line 3170]
Math_BigInteger randomPrime(
[optional
$min = false], [optional
$max = false], [optional
$timeout = false])
|
|
Generate a random prime number.
If there's not a prime within the given range, false will be returned. If more than $timeout seconds have elapsed, give up and return false.
Parameters:
setPrecision [line 2738]
void setPrecision(
Integer
$bits)
|
|
Set Precision
Some bitwise operations give different results depending on the precision being used. Examples include left shift, not, and rotates.
Parameters:
setRandomGenerator [line 3050]
void setRandomGenerator(
String
$generator)
|
|
Set random number generator function
This function is deprecated.
Parameters:
subtract [line 976]
Subtracts two BigIntegers.
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
toBits [line 651]
String toBits(
[Boolean
$twos_compliment = false])
|
|
Converts a BigInteger to a bit string (eg. base-2).
Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're saved as two's compliment.
Here's an example: <?php
include('Math/BigInteger.php');
echo
$a->toBits();
// outputs '1000001'
?>
Parameters:
toBytes [line 527]
String toBytes(
[Boolean
$twos_compliment = false])
|
|
Converts a BigInteger to a byte string (eg. base-256).
Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're saved as two's compliment.
Here's an example: <?php
include('Math/BigInteger.php');
echo
$a->toBytes();
// outputs chr(65)
?>
Parameters:
toHex [line 624]
String toHex(
[Boolean
$twos_compliment = false])
|
|
Converts a BigInteger to a hex string (eg. base-16)).
Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're saved as two's compliment.
Here's an example: <?php
include('Math/BigInteger.php');
echo
$a->toHex();
// outputs '41'
?>
Parameters:
toString [line 688]
Converts a BigInteger to a base-10 number.
Here's an example: <?php
include('Math/BigInteger.php');
?>
__clone [line 776]
__clone() magic method
Although you can call Math_BigInteger::__toString() directly in PHP5, you cannot call Math_BigInteger::__clone() directly in PHP5. You can in PHP4 since it's not a magic method, but in PHP5, you have to call it by using the PHP5 only syntax of $y = clone $x. As such, if you're trying to write an application that works on both PHP4 and PHP5, call Math_BigInteger::copy(), instead.
__sleep [line 789]
__sleep() magic method
Will be called, automatically, when serialize() is called on a Math_BigInteger object.
__toString [line 759]
__toString() magic method
Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call toString().
__wakeup [line 811]
__wakeup() magic method
Will be called, automatically, when unserialize() is called on a Math_BigInteger object.