Math_BigInteger (Constructor) [line 267]
Converts base-2, base-10, base-16, and binary strings (eg. 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 2518]
add [line 780]
Adds two BigIntegers.
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
bitwise_and [line 2653]
bitwise_leftRotate [line 2887]
Logical Left Rotate
Instead of the top x bits being dropped they're appended to the shifted bit string.
Parameters:
bitwise_leftShift [line 2850]
Logical Left Shift
Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift.
Parameters:
bitwise_not [line 2773]
bitwise_or [line 2694]
bitwise_rightRotate [line 2931]
Logical Right Rotate
Instead of the bottom x bits being dropped they're prepended to the shifted bit string.
Parameters:
bitwise_rightShift [line 2812]
Logical Right Shift
Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift.
Parameters:
bitwise_xor [line 2734]
Logical Exclusive-Or
Parameters:
compare [line 2554]
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 674]
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 1333]
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 2612]
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 2375]
Calculates the greatest common divisor and Bézout's identity.
Say you have 693 and 609. The GCD is 21. Bézout'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 Bézout'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 2506]
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 3158]
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 2309]
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 1571]
Performs modular exponentiation.
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
multiply [line 1046]
Multiplies two BigIntegers
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
powMod [line 1670]
Performs modular exponentiation.
Alias for Math_BigInteger::modPow()
Parameters:
random [line 2963]
Generate a random number
Parameters:
randomPrime [line 3027]
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 2632]
Set Precision
Some bitwise operations give different results depending on the precision being used. Examples include left shift, not, and rotates.
Parameters:
setRandomGenerator [line 2950]
void setRandomGenerator(
optional
$generator)
|
|
Set random number generator function
$generator should be the name of a random generating function whose first parameter is the minimum value and whose second parameter is the maximum value. If this function needs to be seeded, it should be seeded prior to calling Math_BigInteger::random() or Math_BigInteger::randomPrime()
If the random generating function is not explicitly set, it'll be assumed to be mt_rand().
Parameters:
subtract [line 911]
Subtracts two BigIntegers.
Here's an example: <?php
include('Math/BigInteger.php');
?>
Parameters:
toBits [line 595]
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 471]
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 568]
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 623]
Converts a BigInteger to a base-10 number.
Here's an example: <?php
include('Math/BigInteger.php');
?>
__clone [line 711]
__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 724]
__sleep() magic method
Will be called, automatically, when serialize() is called on a Math_BigInteger object.
__toString [line 694]
__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 746]
__wakeup() magic method
Will be called, automatically, when unserialize() is called on a Math_BigInteger object.