Bug 6819 – BigInt ^^ fails for some big numbers (powers)

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2011-10-16T16:16:00Z
Last change time
2011-10-21T05:29:20Z
Assigned to
nobody
Creator
axel.foster-5bcwppg

Comments

Comment #0 by axel.foster-5bcwppg — 2011-10-16T16:16:40Z
With dmd 2.055 under Linux x86-64, (BigInt(10)^^p)^^2 doesn't return the correct result starting from p == 32: import std.stdio, std.bigint; void main() { for( int p = 0 ; p < 40 ; p++ ) { BigInt n = BigInt(10)^^p; BigInt a = n*n; BigInt b = n^^2; if( a != b ) { writefln( "%s %s %s %s", p, n, a, b ); } } } It also fails with BigInt(2)^^p (from p==32 too) and BigInt(20)^^p (from p==16). Values like (BigInt(2)^^32+1)^^2 are computed correctly.
Comment #1 by clugdbug — 2011-10-16T22:54:46Z
Ouch. There's a shift by 32 missing. Looks like a fencepost error. Raising to critical.
Comment #2 by clugdbug — 2011-10-20T23:55:35Z
Comment #3 by axel.foster-5bcwppg — 2011-10-21T05:29:20Z
(In reply to comment #2) I've just built and tried latest git (dmd2+druntime+libphobos2) and both the small test above and my original program that triggered the bug now work correctly. Thanks!