[Issue 14786] New: The built-in exponentiation operator ^^ sometimes returns a value with the wrong sign.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 7 16:18:25 PDT 2015


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

          Issue ID: 14786
           Summary: The built-in exponentiation operator ^^ sometimes
                    returns a value with the wrong sign.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: thomas.bockman at gmail.com

Negative one raised to any odd power should yield negative one.

However, when using 80-bit real arithmetic, -1 raised to a power greater than
2^^63 and less than 2^^64 yields +1.

This is despite the fact that integers in this range can still (just barely) be
represented without loss of precision by an 80-bit real; even and odd can still
be distinguished.

** Test case that currently fails **
void main(string[] args)
{
    real b = -1;
    real e = long.max;
    e += 2;
    assert(e % 2 == 1);
    real r = b ^^ e;
    assert(r == 1);  // Passes, but shouldn't
    assert(r == -1); // Fails, but shouldn't

    e = ulong.max;
    assert(e % 2 == 1);
    r = b ^^ e;
    assert(r == 1);  // Passes, but shouldn't
    assert(r == -1); // Fails, but shouldn't
}

I have marked this as a D runtime issue since it fails with all of DMD, GDC,
and LDC. However, I couldn't actually find where the ^^ is defined in my quick
search, so I don't know what the fix should look like. I suppose it might even
be a hardware errata in my FPU (Xeon E3-1225 v3)...

--


More information about the Digitalmars-d-bugs mailing list