Summary: BigInt %= long/ulong gives wrong value
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from Stewart Gordon <> 2012-04-23 04:23:34 PDT ---
import std.stdio, std.bigint;

void main() {
    const mod = 10_000_000_000_000_000;
    pragma(msg, typeof(mod));
    BigInt value = 2551700137;

    writefln("%d", value);
    writefln("%d", mod);
    value %= mod;
    writefln("%d", value);
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd bigint_mod.d


Interestingly, if I %= a long or ulong literal or non-const variable instead, I
d:\dmd2\windows\bin\..\..\src\phobos\std\bigint.d(163): Error: static assert 
(true && false) is false
bigint_mod.d(10):        instantiated from here: opOpAssign!("%",ulong)
and looking at bigint.d I see
    static assert(!is(T==long) && !is(T==ulong));

so it appears that doing %= on a long/ulong has been deliberately disabled
pending getting it working properly, but const/immutable long/ulong has been
overlooked in doing so.

Since BigInt %= BigInt seems to work correctly, how about making it construct a
BigInt from the long/ulong and using that?  It can later be replaced with an
implementation optimised to long/ulong once that has been written and tested.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to