[Issue 24028] New: BigInt power operator ignores sign of exponent

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 3 14:09:10 UTC 2023


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

          Issue ID: 24028
           Summary: BigInt power operator ignores sign of exponent
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.104.0, the assertion in the following program fails:

---
import std.bigint;

void main()
{
    auto n = BigInt(100);
    auto expected = BigInt(1) / BigInt(100);
    assert(n ^^ -1 == expected);
}
---

With -checkaction=context, the error message is:

---
core.exception.AssertError at bug.d(7): BigInt(BigUint([100]), false) !=
BigInt(BigUint([0]), false)
---

Instead of raising n to the power of -1, BigInt's ^^ overload has raised it to
the power of 1.

--


More information about the Digitalmars-d-bugs mailing list