[ 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() param: mixed $x integer Base-10 number or base-$base number if $base set. param: int $base return: PHP |
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 param: string $str return: string |
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). param: bool $twos_compliment return: string |
addHelper(array $x_value, $x_negative, array $y_value, $y_negative) X-Ref |
Performs addition. param: array $x_value param: bool $x_negative param: array $y_value param: bool $y_negative return: array |
subtractHelper(array $x_value, $x_negative, array $y_value, $y_negative) X-Ref |
Performs subtraction. param: array $x_value param: bool $x_negative param: array $y_value param: bool $y_negative return: array |
multiplyHelper(array $x_value, $x_negative, array $y_value, $y_negative) X-Ref |
Performs multiplication. param: array $x_value param: bool $x_negative param: array $y_value param: bool $y_negative return: array |
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}. param: array $x_value param: array $y_value return: array |
regularMultiply(array $x_value, array $y_value) X-Ref |
Performs long multiplication on two BigIntegers Modeled after 'multiply' in MutableBigInteger.java. param: array $x_value param: array $y_value return: array |
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 param: array $dividend param: int $divisor return: array |
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. param: int $x param: int $y return: int |
convertToObj(array $arr) X-Ref |
Convert an array / boolean to a PHP BigInteger object param: array $arr return: static |
normalize(PHP $result) X-Ref |
Normalize Removes leading zeros and truncates (if necessary) to maintain the appropriate precision param: PHP $result return: static |
compareHelper(array $x_value, $x_negative, array $y_value, $y_negative) X-Ref |
Compares two numbers. see: static::compare() param: array $x_value param: bool $x_negative param: array $y_value param: bool $y_negative return: int |
abs() X-Ref |
Absolute value. return: PHP |
trim(array $value) X-Ref |
Trim Removes leading zeros param: list<static> $value return: list<static> |
bitwise_rightShift($shift) X-Ref |
Logical Right Shift Shifts BigInteger's by $shift bits, effectively dividing by 2**$shift. param: int $shift return: PHP |
bitwise_leftShift($shift) X-Ref |
Logical Left Shift Shifts BigInteger's by $shift bits, effectively multiplying by 2**$shift. param: int $shift return: PHP |
int2bytes($x) X-Ref |
Converts 32-bit integers to bytes. param: int $x return: string |
array_repeat($input, $multiplier) X-Ref |
Array Repeat param: int $input param: int $multiplier return: array |
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. param: PHP $e param: PHP $n return: PHP |
square(array $x) X-Ref |
Performs squaring param: list<static> $x return: list<static> |
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. param: array $value return: array |
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}. param: array $value return: array |
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() param: PHP $r return: int |
powHelper(PHP $n) X-Ref |
Performs exponentiation. param: PHP $n return: PHP |
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 param: int $split return: list<static> |
bitwise_small_split($split) X-Ref |
Bitwise Split where $split < static::BASE param: int $split return: list<int> |
testJITOnWindows() X-Ref |
return: bool |
getLength() X-Ref |
Return the size of a BigInteger in bits return: int |