mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-25 19:21:09 +00:00
Merge branch '2.0'
This commit is contained in:
commit
677a15c122
@ -517,7 +517,14 @@ class GMP extends Engine
|
||||
$result->bitmask = $this->bitmask;
|
||||
|
||||
if ($result->bitmask !== false) {
|
||||
$flip = $result->value < 0;
|
||||
if ($flip) {
|
||||
$result->value = -$result->value;
|
||||
}
|
||||
$result->value = $result->value & $result->bitmask->value;
|
||||
if ($flip) {
|
||||
$result->value = -$result->value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -157,6 +157,7 @@ abstract class PHP extends Engine
|
||||
}
|
||||
|
||||
$temp = clone $this;
|
||||
$temp->bitmask = false;
|
||||
$temp->is_negative = false;
|
||||
|
||||
$divisor = new static();
|
||||
|
@ -485,4 +485,21 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
||||
$temp = $this->getInstance('-0');
|
||||
$this->assertSame($temp->toString(), '0');
|
||||
}
|
||||
|
||||
public function testNegativePrecision()
|
||||
{
|
||||
$vals = [
|
||||
'-9223372036854775808', // eg. 8000 0000 0000 0000
|
||||
'-1'
|
||||
];
|
||||
foreach ($vals as $val) {
|
||||
$x = $this->getInstance($val);
|
||||
$x->setPrecision(64); // ie. 8 bytes
|
||||
$this->assertSame($val, "$x");
|
||||
$r = $x->toBytes(true);
|
||||
$this->assertSame(8, strlen($r));
|
||||
$x2 = $this->getInstance($r, -256);
|
||||
$this->assertSame(0, $x->compare($x2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user