[Issue 14124] New: BigInt %= int can return "-0"

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Feb 4 04:52:08 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14124

          Issue ID: 14124
           Summary: BigInt %= int can return "-0"
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: electrolysis.jp+d at gmail.com

Separated from issue 13963.

Not only int, but any integral types smaller than (u)long.

---

import std.bigint;

void main()
{
    auto x = BigInt(-3);  // Negative BigInt
    x %= 3;  // int
    assert(x == BigInt(0), toDecimalString(x));  // Bad, x is invalid "-0"

    x = BigInt(-3);
    x %= 3L;  // long
    assert(x == BigInt(0));  // Good, different implementation
}

--


More information about the Digitalmars-d-bugs mailing list