D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6819 - BigInt ^^ fails for some big numbers (powers)
Summary: BigInt ^^ fails for some big numbers (powers)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 All
: P2 critical
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-16 16:16 UTC by Olivier Fabre
Modified: 2011-10-21 05:29 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Olivier Fabre 2011-10-16 16:16:40 UTC
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 Don 2011-10-16 22:54:46 UTC
Ouch. There's a shift by 32 missing. Looks like a fencepost error. Raising to critical.
Comment 3 Olivier Fabre 2011-10-21 05:29:20 UTC
(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!