BigInteger: add getprecision

This commit is contained in:
terrafrost 2016-01-03 10:42:44 -06:00
parent a0d21b6321
commit d86c61de78
2 changed files with 30 additions and 1 deletions

View File

@ -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
*

View File

@ -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);
}
}