D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4452 - Incorrect result of BigInt ^^ long
Summary: Incorrect result of BigInt ^^ long
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-13 04:50 UTC by yebblies
Modified: 2010-07-14 00:07 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 yebblies 2010-07-13 04:50:21 UTC
BigInt give incorrect results for a^^b for a select set of numbers:

12 ^^ 16
48 ^^ 8
48 ^^ 16
80 ^^ 8
112 ^^ 8
144 ^^ 8
176 ^^ 8
192 ^^ 16
208 ^^ 8
etc

Test case:

void main()
{
  BigInt bpow(long a, long b)
  {
    auto r = BigInt(1);
    while(b--)
      r *= a;
    return r
  }

  foreach(a; 0..1000)
  {
    foreach(b; 0..1000)
    {
    	auto r1 = bpow(a, b);
    	auto r2 = BigInt(a) ^^ b;
    	assert(r1 == r2);
    }
  }
}

Version of std.bigint packaged with dmd2.047
Have not checked on other hardware/os
Comment 1 Don 2010-07-14 00:07:45 UTC
Fixed in Phobos svn 1757.