D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2987 - D2 phobos BigInt opMul doesn't work correctly
Summary: D2 phobos BigInt opMul doesn't work correctly
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2009-05-15 19:11 UTC by ZY Zhou
Modified: 2015-06-09 01:27 UTC (History)
3 users (show)

See Also:


Attachments
patch to fix bug 2987 (977 bytes, patch)
2009-05-17 19:25 UTC, ZY Zhou
Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description ZY Zhou 2009-05-15 19:11:42 UTC
It won't pass this test

 BigInt a = 10;
 BigInt b = a * a;
 foreach (i; 0..100)
 {
    assert(a * a == b);
    a *= i;
    b *= i * i;
 }

To fix this bug.
Find this around BigInt.d line 907

    c = updateShr(c);

replace it with

    c = updateUShr(c);
Comment 1 ZY Zhou 2009-05-15 19:15:31 UTC
The test code should be.
  BigInt a = 10;
  BigInt b = a * a;
  foreach (i; 2..100)
  {
     assert(a * a == b);
     a *= i;
     b *= i * i;
  }

sorry for the typo

(In reply to comment #0)
> It won't pass this test
> 
>  BigInt a = 10;
>  BigInt b = a * a;
>  foreach (i; 0..100)
>  {
>     assert(a * a == b);
>     a *= i;
>     b *= i * i;
>  }
> 
> To fix this bug.
> Find this around BigInt.d line 907
> 
>     c = updateShr(c);
> 
> replace it with
> 
>     c = updateUShr(c);
Comment 2 ZY Zhou 2009-05-17 19:25:38 UTC
Created attachment 375 [details]
patch to fix bug 2987

fix the bug (line 907)

add a testcase
Comment 3 Don 2009-08-28 05:47:53 UTC
Thanks!
Actually both cases of updateShr should probably be updateUShr, although AFAICT the result of the second one is never actually used, so it's a bit irrelevant.
Fixed in svn 1251.