Skip to content

Commit

Permalink
Merge branch 'bigint5568' of https://github.com/donc/phobos into donc…
Browse files Browse the repository at this point in the history
…-bigint5568
  • Loading branch information
WalterBright committed Feb 23, 2011
2 parents 44b60db + 9ecf947 commit 9fa7393
Show file tree
Hide file tree
Showing 2 changed files with 611 additions and 253 deletions.
26 changes: 24 additions & 2 deletions std/bigint.d
Expand Up @@ -408,8 +408,8 @@ public:
sink("-");
if (formatString.length>0 && formatString[$-1]=='x' || formatString[$-1]=='X')
{
char[] buff = data.toHexString(1, '_');
sink(data.toHexString(0, '_'));
char[] buff = data.toHexString(0, '_');
sink(buff);
}
else
{
Expand Down Expand Up @@ -492,4 +492,26 @@ unittest {
assert( b == -long.max % (ulong.max - 5));
b = long.max / a;
assert( b == long.max /(ulong.max - 5));
assert(BigInt(1) - 1 == 0);
}

unittest // Recursive division, bug 5568
{
enum Z = 4843;
BigInt m = (BigInt(1) << (Z*8) ) - 1;
m -= (BigInt(1) << (Z*6)) - 1;
BigInt oldm = m;

BigInt a = (BigInt(1) << (Z*4) )-1;
BigInt b = m % a;
m /= a;
m *= a;
assert( m + b == oldm);

m = (BigInt(1) << (4846 + 4843) ) - 1;
a = (BigInt(1) << 4846 ) - 1;
b = (BigInt(1) << (4846*2 + 4843)) - 1;
BigInt c = (BigInt(1) << (4846*2 + 4843*2)) - 1;
BigInt w = c - b + a;
assert(w % m == 0);
}

0 comments on commit 9fa7393

Please sign in to comment.