Merge pull request #685 from donc/bigint7993div

Fix issue 7973 BigInt %= long/ulong gives wrong value
This commit is contained in:
Jonathan M Davis 2012-07-14 03:55:27 -07:00
commit 52b5058d06

View file

@ -162,7 +162,7 @@ public:
else static if (op=="%") else static if (op=="%")
{ {
assert(y!=0, "Division by zero"); assert(y!=0, "Division by zero");
static if (is(const(T) == const(long)) || is( const(T) == const(ulong) )) static if (is(immutable(T) == immutable(long)) || is( immutable(T) == immutable(ulong) ))
{ {
this %= BigInt(y); this %= BigInt(y);
} }
@ -581,11 +581,14 @@ unittest // Recursive division, bug 5568
// Bug 7973 // Bug 7973
auto a7973 = 10_000_000_000_000_000; auto a7973 = 10_000_000_000_000_000;
const c7973 = 10_000_000_000_000_000; const c7973 = 10_000_000_000_000_000;
immutable i7973 = 10_000_000_000_000_000;
BigInt v7973 = 2551700137; BigInt v7973 = 2551700137;
v7973 %= a7973; v7973 %= a7973;
assert(v7973 == 2551700137); assert(v7973 == 2551700137);
v7973 %= c7973; v7973 %= c7973;
assert(v7973 == 2551700137); assert(v7973 == 2551700137);
v7973 %= i7973;
assert(v7973 == 2551700137);
// 8165 // 8165
BigInt[2] a8165; BigInt[2] a8165;
a8165[0] = a8165[1] = 1; a8165[0] = a8165[1] = 1;