BigInteger: update comments and add test case

This commit is contained in:
terrafrost 2014-04-23 23:13:27 -05:00 committed by Andreas Fischer
parent e4ff01f054
commit 9eb6e1ed67
2 changed files with 12 additions and 9 deletions

View File

@ -19,10 +19,6 @@
* which only supports integers. Although this fact will slow this library down, the fact that such a high * which only supports integers. Although this fact will slow this library down, the fact that such a high
* base is being used should more than compensate. * base is being used should more than compensate.
* *
* When PHP version 6 is officially released, we'll be able to use 64-bit integers. This should, once again,
* allow bitwise operators, and will increase the maximum possible base to 2**31 (or 2**62 for addition /
* subtraction).
*
* Numbers are stored in {@link http://en.wikipedia.org/wiki/Endianness little endian} format. ie. * Numbers are stored in {@link http://en.wikipedia.org/wiki/Endianness little endian} format. ie.
* (new Math_BigInteger(pow(2, 26)))->value = array(0, 1) * (new Math_BigInteger(pow(2, 26)))->value = array(0, 1)
* *
@ -3715,12 +3711,12 @@ class Math_BigInteger
/** /**
* Calculate the carry * Calculate the carry
* *
* when PHP uses int32 phpseclib uses float64 / base-26. at that point the largest intermediary * when PHP uses int32, phpseclib uses float64 / base-26. at that point the largest intermediary
* value numbers can have is 2**52. you can't left shift to get the top 26 bits because left * value numbers can have is 2**52. you can't left shift to get the top (most significant) 26 bits
* shift takes in ints, which have 31-bits of usuable precision, since PHP does signed int32. * because left shift takes in ints, which have 31-bits of usable precision, since PHP does
* so we divide. * signed int32. as a consequence of the above, division takes place
* *
* when PHP uses int64 phpseclib uses int64 / base-31. at that point the largest intermediary * when PHP uses int64, phpseclib uses int64 / base-31. at that point the largest intermediary
* value numbers can have is 2**62. you can't divide because PHP's division operator returns * value numbers can have is 2**62. you can't divide because PHP's division operator returns
* a float64 (which doesn't have sufficient precision) unless the two operands are evenly * a float64 (which doesn't have sufficient precision) unless the two operands are evenly
* divisible. but we can left shift. * divisible. but we can left shift.

View File

@ -14,4 +14,11 @@ class Math_BigInteger_InternalTest extends Math_BigInteger_TestCase
self::ensureConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL); self::ensureConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL);
self::ensureConstant('MATH_BIGINTEGER_OPENSSL_DISABLE', true); self::ensureConstant('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
} }
public function testInternalRepresentation()
{
$x = new Math_BigInteger('FFFFFFFFFFFFFFFFC90FDA', 16);
$y = new Math_BigInteger("$x");
$this->assertSame($x->value, $y->value);
}
} }