[ Index ] |
PHP Cross Reference of DokuWiki |
[Source view] [Print] [Project Stats]
GMP 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: | 694 lines (17 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
GMP:: (41 methods):
isValidEngine()
__construct()
initialize()
toString()
toBits()
toBytes()
add()
subtract()
multiply()
divide()
compare()
equals()
modInverse()
extendedGCD()
gcd()
abs()
bitwise_and()
bitwise_or()
bitwise_xor()
bitwise_rightShift()
bitwise_leftShift()
modPow()
powMod()
powModInner()
normalize()
randomRangePrimeInner()
randomRangePrime()
randomRange()
make_odd()
testPrimality()
rootInner()
pow()
min()
max()
between()
createRecurringModuloFunction()
scan1divide()
isOdd()
testBit()
isNegative()
negate()
isValidEngine() X-Ref |
Test for engine validity return: bool see: parent::__construct() |
__construct($x = 0, $base = 10) X-Ref |
Default constructor param: mixed $x integer Base-10 number or base-$base number if $base set. param: int $base see: parent::__construct() |
initialize($base) X-Ref |
Initialize a GMP BigInteger Engine instance param: int $base see: parent::__construct() |
toString() X-Ref |
Converts a BigInteger to a base-10 number. return: string |
toBits($twos_compliment = false) X-Ref |
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. return: string param: bool $twos_compliment |
toBytes($twos_compliment = false) X-Ref |
Converts a BigInteger to a byte string (eg. base-256). return: string param: bool $twos_compliment |
add(GMP $y) X-Ref |
Adds two BigIntegers. return: GMP param: GMP $y |
subtract(GMP $y) X-Ref |
Subtracts two BigIntegers. return: GMP param: GMP $y |
multiply(GMP $x) X-Ref |
Multiplies two BigIntegers. return: GMP param: GMP $x |
divide(GMP $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{GMP, GMP} param: GMP $y |
compare(GMP $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: GMP $y see: self::equals() |
equals(GMP $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: GMP $x |
modInverse(GMP $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|GMP param: GMP $n |
extendedGCD(GMP $n) X-Ref |
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 dependent upon which mode is in use. See {@link http://en.wikipedia.org/wiki/B%C3%A9zout%27s_identity Bezout's identity - Wikipedia} for more information. return: GMP[] param: GMP $n |
gcd(GMP $n) X-Ref |
Calculates the greatest common divisor Say you have 693 and 609. The GCD is 21. return: GMP param: GMP $n |
abs() X-Ref |
Absolute value. return: GMP |
bitwise_and(GMP $x) X-Ref |
Logical And return: GMP param: GMP $x |
bitwise_or(GMP $x) X-Ref |
Logical Or return: GMP param: GMP $x |
bitwise_xor(GMP $x) X-Ref |
Logical Exclusive Or return: GMP param: GMP $x |
bitwise_rightShift($shift) X-Ref |
Logical Right Shift Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift. return: GMP param: int $shift |
bitwise_leftShift($shift) X-Ref |
Logical Left Shift Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift. return: GMP param: int $shift |
modPow(GMP $e, GMP $n) X-Ref |
Performs modular exponentiation. return: GMP param: GMP $e param: GMP $n |
powMod(GMP $e, GMP $n) X-Ref |
Performs modular exponentiation. Alias for modPow(). return: GMP param: GMP $e param: GMP $n |
powModInner(GMP $e, GMP $n) X-Ref |
Performs modular exponentiation. return: GMP param: GMP $e param: GMP $n |
normalize(GMP $result) X-Ref |
Normalize Removes leading zeros and truncates (if necessary) to maintain the appropriate precision return: GMP param: GMP $result |
randomRangePrimeInner(Engine $x, Engine $min, Engine $max) X-Ref |
Performs some post-processing for randomRangePrime return: GMP param: Engine $x param: Engine $min param: Engine $max |
randomRangePrime(GMP $min, GMP $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|GMP param: GMP $min param: GMP $max |
randomRange(GMP $min, GMP $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: GMP param: GMP $min param: GMP $max |
make_odd() X-Ref |
Make the current number odd If the current number is odd it'll be unchanged. If it's even, one will be added to it. see: self::randomPrime() |
testPrimality($t) X-Ref |
Tests Primality return: bool param: int $t |
rootInner($n) X-Ref |
Calculates the nth root of a biginteger. Returns the nth root of a positive biginteger, where n defaults to 2 return: GMP param: int $n |
pow(GMP $n) X-Ref |
Performs exponentiation. return: GMP param: GMP $n |
min(GMP ...$nums) X-Ref |
Return the minimum BigInteger between an arbitrary number of BigIntegers. return: GMP param: GMP ...$nums |
max(GMP ...$nums) X-Ref |
Return the maximum BigInteger between an arbitrary number of BigIntegers. return: GMP param: GMP ...$nums |
between(GMP $min, GMP $max) X-Ref |
Tests BigInteger to see if it is between two integers, inclusive return: bool param: GMP $min param: GMP $max |
createRecurringModuloFunction() X-Ref |
Create Recurring Modulo Function Sometimes it may be desirable to do repeated modulos with the same number outside of modular exponentiation return: callable |
scan1divide(GMP $r) X-Ref |
Scan for 1 and right shift by that amount ie. $s = gmp_scan1($n, 0) and $r = gmp_div_q($n, gmp_pow(gmp_init('2'), $s)); return: int param: GMP $r |
isOdd() X-Ref |
Is Odd? return: bool |
testBit($x) X-Ref |
Tests if a bit is set return: bool |
isNegative() X-Ref |
Is Negative? return: bool |
negate() X-Ref |
Negate Given $k, returns -$k return: GMP |