[ 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 see: parent::__construct() return: bool |
__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. param: bool $twos_compliment return: string |
toBytes($twos_compliment = false) X-Ref |
Converts a BigInteger to a byte string (eg. base-256). param: bool $twos_compliment return: string |
add(GMP $y) X-Ref |
Adds two BigIntegers. param: GMP $y return: GMP |
subtract(GMP $y) X-Ref |
Subtracts two BigIntegers. param: GMP $y return: GMP |
multiply(GMP $x) X-Ref |
Multiplies two BigIntegers. param: GMP $x return: GMP |
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). param: GMP $y return: array{GMP, GMP} |
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.} param: GMP $y see: self::equals() return: int in case < 0 if $this is less than $y; > 0 if $this is greater than $y, and 0 if they are equal. |
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() param: GMP $x return: bool |
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. param: GMP $n return: false|GMP |
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. param: GMP $n return: GMP[] |
gcd(GMP $n) X-Ref |
Calculates the greatest common divisor Say you have 693 and 609. The GCD is 21. param: GMP $n return: GMP |
abs() X-Ref |
Absolute value. return: GMP |
bitwise_and(GMP $x) X-Ref |
Logical And param: GMP $x return: GMP |
bitwise_or(GMP $x) X-Ref |
Logical Or param: GMP $x return: GMP |
bitwise_xor(GMP $x) X-Ref |
Logical Exclusive Or param: GMP $x return: GMP |
bitwise_rightShift($shift) X-Ref |
Logical Right Shift Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift. param: int $shift return: GMP |
bitwise_leftShift($shift) X-Ref |
Logical Left Shift Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift. param: int $shift return: GMP |
modPow(GMP $e, GMP $n) X-Ref |
Performs modular exponentiation. param: GMP $e param: GMP $n return: GMP |
powMod(GMP $e, GMP $n) X-Ref |
Performs modular exponentiation. Alias for modPow(). param: GMP $e param: GMP $n return: GMP |
powModInner(GMP $e, GMP $n) X-Ref |
Performs modular exponentiation. param: GMP $e param: GMP $n return: GMP |
normalize(GMP $result) X-Ref |
Normalize Removes leading zeros and truncates (if necessary) to maintain the appropriate precision param: GMP $result return: GMP |
randomRangePrimeInner(Engine $x, Engine $min, Engine $max) X-Ref |
Performs some post-processing for randomRangePrime param: Engine $x param: Engine $min param: Engine $max return: GMP |
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. param: GMP $min param: GMP $max return: false|GMP |
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) param: GMP $min param: GMP $max return: GMP |
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 param: int $t return: bool |
rootInner($n) X-Ref |
Calculates the nth root of a biginteger. Returns the nth root of a positive biginteger, where n defaults to 2 param: int $n return: GMP |
pow(GMP $n) X-Ref |
Performs exponentiation. param: GMP $n return: GMP |
min(GMP ...$nums) X-Ref |
Return the minimum BigInteger between an arbitrary number of BigIntegers. param: GMP ...$nums return: GMP |
max(GMP ...$nums) X-Ref |
Return the maximum BigInteger between an arbitrary number of BigIntegers. param: GMP ...$nums return: GMP |
between(GMP $min, GMP $max) X-Ref |
Tests BigInteger to see if it is between two integers, inclusive param: GMP $min param: GMP $max return: bool |
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)); param: GMP $r return: int |
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 |