mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 03:27:31 +00:00
BigInteger: add getprecision
This commit is contained in:
parent
a0d21b6321
commit
d86c61de78
@ -2751,6 +2751,12 @@ class BigInteger
|
||||
*/
|
||||
function setPrecision($bits)
|
||||
{
|
||||
if ($bits < 1) {
|
||||
$this->precision = -1;
|
||||
$this->bitmask = false;
|
||||
|
||||
return;
|
||||
}
|
||||
$this->precision = $bits;
|
||||
if (MATH_BIGINTEGER_MODE != self::MODE_BCMATH) {
|
||||
$this->bitmask = new static(chr((1 << ($bits & 0x7)) - 1) . str_repeat(chr(0xFF), $bits >> 3), 256);
|
||||
@ -2762,6 +2768,18 @@ class BigInteger
|
||||
$this->value = $temp->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Precision
|
||||
*
|
||||
* @return int
|
||||
* @see self::setPrecision()
|
||||
* @access public
|
||||
*/
|
||||
function getPrecision()
|
||||
{
|
||||
return $this->precision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logical And
|
||||
*
|
||||
|
@ -348,6 +348,17 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
||||
$num = $this->getInstance(50);
|
||||
$str = print_r($num, true);
|
||||
$this->assertContains('[value] => 0x32', $str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function testPrecision()
|
||||
{
|
||||
$a = $this->getInstance(50);
|
||||
$this->assertSame($a->getPrecision(), -1);
|
||||
$b = $a;
|
||||
$c = clone $a;
|
||||
$b->setPrecision(4);
|
||||
$this->assertSame($a->getPrecision(), 4);
|
||||
$this->assertSame($b->getPrecision(), 4);
|
||||
$this->assertSame($c->getPrecision(), -1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user