[ Index ] |
PHP Cross Reference of DokuWiki |
[Source view] [Print] [Project Stats]
Pure-PHP 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: | 1357 lines (39 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
__construct($x = 0, $base = 10) X-Ref |
Default constructor see: parent::__construct() return: PHP param: mixed $x integer Base-10 number or base-$base number if $base set. param: int $base |
initialize($base) X-Ref |
Initialize a PHP BigInteger Engine instance see: parent::__construct() param: int $base |
pad($str) X-Ref |
Pads strings so that unpack may be used on them return: string param: string $str |
toString() X-Ref |
Converts a BigInteger to a base-10 number. return: string |
toBytes($twos_compliment = false) X-Ref |
Converts a BigInteger to a byte string (eg. base-256). return: string param: bool $twos_compliment |
addHelper(array $x_value, $x_negative, array $y_value, $y_negative) X-Ref |
Performs addition. return: array param: array $x_value param: bool $x_negative param: array $y_value param: bool $y_negative |
subtractHelper(array $x_value, $x_negative, array $y_value, $y_negative) X-Ref |
Performs subtraction. return: array param: array $x_value param: bool $x_negative param: array $y_value param: bool $y_negative |
multiplyHelper(array $x_value, $x_negative, array $y_value, $y_negative) X-Ref |
Performs multiplication. return: array param: array $x_value param: bool $x_negative param: array $y_value param: bool $y_negative |
karatsuba(array $x_value, array $y_value) X-Ref |
Performs Karatsuba multiplication on two BigIntegers See {@link http://en.wikipedia.org/wiki/Karatsuba_algorithm Karatsuba algorithm} and {@link http://math.libtomcrypt.com/files/tommath.pdf#page=120 MPM 5.2.3}. return: array param: array $x_value param: array $y_value |
regularMultiply(array $x_value, array $y_value) X-Ref |
Performs long multiplication on two BigIntegers Modeled after 'multiply' in MutableBigInteger.java. return: array param: array $x_value param: array $y_value |
divideHelper(PHP $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{static, static} |
divide_digit(array $dividend, $divisor) X-Ref |
Divides a BigInteger by a regular integer abc / x = a00 / x + b0 / x + c / x return: array param: array $dividend param: int $divisor |
safe_divide($x, $y) X-Ref |
Single digit division Even if int64 is being used the division operator will return a float64 value if the dividend is not evenly divisible by the divisor. Since a float64 doesn't have the precision of int64 this is a problem so, when int64 is being used, we'll guarantee that the dividend is divisible by first subtracting the remainder. return: int param: int $x param: int $y |
convertToObj(array $arr) X-Ref |
Convert an array / boolean to a PHP BigInteger object return: static param: array $arr |
normalize(PHP $result) X-Ref |
Normalize Removes leading zeros and truncates (if necessary) to maintain the appropriate precision return: static param: PHP $result |
compareHelper(array $x_value, $x_negative, array $y_value, $y_negative) X-Ref |
Compares two numbers. see: static::compare() return: int param: array $x_value param: bool $x_negative param: array $y_value param: bool $y_negative |
abs() X-Ref |
Absolute value. return: PHP |
trim(array $value) X-Ref |
Trim Removes leading zeros return: list<static> param: list<static> $value |
bitwise_rightShift($shift) X-Ref |
Logical Right Shift Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift. return: PHP param: int $shift |
bitwise_leftShift($shift) X-Ref |
Logical Left Shift Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift. return: PHP param: int $shift |
int2bytes($x) X-Ref |
Converts 32-bit integers to bytes. return: string param: int $x |
array_repeat($input, $multiplier) X-Ref |
Array Repeat return: array param: int $input param: int $multiplier |
lshift($shift) X-Ref |
Logical Left Shift Shifts BigInteger's by $shift bits. param: int $shift |
rshift($shift) X-Ref |
Logical Right Shift Shifts BigInteger's by $shift bits. param: int $shift |
powModInner(PHP $e, PHP $n) X-Ref |
Performs modular exponentiation. return: PHP param: PHP $e param: PHP $n |
square(array $x) X-Ref |
Performs squaring return: list<static> param: list<static> $x |
baseSquare(array $value) X-Ref |
Performs traditional squaring on two BigIntegers Squaring can be done faster than multiplying a number by itself can be. See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=7 HAC 14.2.4} / {@link http://math.libtomcrypt.com/files/tommath.pdf#page=141 MPM 5.3} for more information. return: array param: array $value |
karatsubaSquare(array $value) X-Ref |
Performs Karatsuba "squaring" on two BigIntegers See {@link http://en.wikipedia.org/wiki/Karatsuba_algorithm Karatsuba algorithm} and {@link http://math.libtomcrypt.com/files/tommath.pdf#page=151 MPM 5.3.4}. return: array param: array $value |
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() |
testSmallPrimes() X-Ref |
Test the number against small primes. see: self::isPrime() |
scan1divide(PHP $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)); see: self::isPrime() return: int param: PHP $r |
powHelper(PHP $n) X-Ref |
Performs exponentiation. return: PHP param: PHP $n |
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: static |
bitwise_split($split) X-Ref |
Bitwise Split Splits BigInteger's into chunks of $split bits return: list<static> param: int $split |
bitwise_small_split($split) X-Ref |
Bitwise Split where $split < static::BASE return: list<int> param: int $split |
testJITOnWindows() X-Ref |
return: bool |
getLength() X-Ref |
Return the size of a BigInteger in bits return: int |