[ Index ] |
PHP Cross Reference of DokuWiki |
[Source view] [Print] [Project Stats]
Pure-PHP 32-bit BigInteger Engine PHP version 5 and 7
Author: | Jim Wigginton |
Copyright: | 2017 Jim Wigginton |
License: | http://www.opensource.org/licenses/mit-license.html MIT License |
Link: | http://pear.php.net/package/Math_BigInteger |
File Size: | 371 lines (9 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
PHP32:: (22 methods):
initialize()
isValidEngine()
add()
subtract()
multiply()
divide()
modInverse()
extendedGCD()
gcd()
bitwise_and()
bitwise_or()
bitwise_xor()
compare()
equals()
modPow()
powMod()
randomRangePrime()
randomRange()
pow()
min()
max()
between()
initialize($base) X-Ref |
Initialize a PHP32 BigInteger Engine instance param: int $base see: parent::initialize() |
isValidEngine() X-Ref |
Test for engine validity return: bool see: parent::__construct() |
add(PHP32 $y) X-Ref |
Adds two BigIntegers. return: PHP32 param: PHP32 $y |
subtract(PHP32 $y) X-Ref |
Subtracts two BigIntegers. return: PHP32 param: PHP32 $y |
multiply(PHP32 $y) X-Ref |
Multiplies two BigIntegers. return: PHP32 param: PHP32 $y |
divide(PHP32 $y) X-Ref |
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). return: array{PHP32, PHP32} param: PHP32 $y |
modInverse(PHP32 $n) X-Ref |
Calculates modular inverses. Say you have (30 mod 17 * x mod 17) mod 17 == 1. x can be found using modular inverses. return: false|PHP32 param: PHP32 $n |
extendedGCD(PHP32 $n) X-Ref |
Calculates modular inverses. Say you have (30 mod 17 * x mod 17) mod 17 == 1. x can be found using modular inverses. return: PHP32[] param: PHP32 $n |
gcd(PHP32 $n) X-Ref |
Calculates the greatest common divisor Say you have 693 and 609. The GCD is 21. return: PHP32 param: PHP32 $n |
bitwise_and(PHP32 $x) X-Ref |
Logical And return: PHP32 param: PHP32 $x |
bitwise_or(PHP32 $x) X-Ref |
Logical Or return: PHP32 param: PHP32 $x |
bitwise_xor(PHP32 $x) X-Ref |
Logical Exclusive Or return: PHP32 param: PHP32 $x |
compare(PHP32 $y) X-Ref |
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). {@internal Could return $this->subtract($x), but that's not as fast as what we do do.} return: int in case < 0 if $this is less than $y; > 0 if $this is greater than $y, and 0 if they are equal. param: PHP32 $y see: self::equals() |
equals(PHP32 $x) X-Ref |
Tests the equality of two numbers. If you need to see if one number is greater than or less than another number, use BigInteger::compare() return: bool param: PHP32 $x |
modPow(PHP32 $e, PHP32 $n) X-Ref |
Performs modular exponentiation. return: PHP32 param: PHP32 $e param: PHP32 $n |
powMod(PHP32 $e, PHP32 $n) X-Ref |
Performs modular exponentiation. Alias for modPow(). return: PHP32 param: PHP32 $e param: PHP32 $n |
randomRangePrime(PHP32 $min, PHP32 $max) X-Ref |
Generate a random prime number between a range If there's not a prime within the given range, false will be returned. return: false|PHP32 param: PHP32 $min param: PHP32 $max |
randomRange(PHP32 $min, PHP32 $max) X-Ref |
Generate a random number between a range Returns a random number between $min and $max where $min and $max can be defined using one of the two methods: BigInteger::randomRange($min, $max) BigInteger::randomRange($max, $min) return: PHP32 param: PHP32 $min param: PHP32 $max |
pow(PHP32 $n) X-Ref |
Performs exponentiation. return: PHP32 param: PHP32 $n |
min(PHP32 ...$nums) X-Ref |
Return the minimum BigInteger between an arbitrary number of BigIntegers. return: PHP32 param: PHP32 ...$nums |
max(PHP32 ...$nums) X-Ref |
Return the maximum BigInteger between an arbitrary number of BigIntegers. return: PHP32 param: PHP32 ...$nums |
between(PHP32 $min, PHP32 $max) X-Ref |
Tests BigInteger to see if it is between two integers, inclusive return: bool param: PHP32 $min param: PHP32 $max |