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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jul 8 12:42:14 PDT 2015


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

--- Comment #4 from thomas.bockman at gmail.com ---
I haven't tested it extensively yet, but here is a fixed version of that
section:

// Result is real only if y is an integer
// Check for a non-zero fractional part
enum real maxPrecise = ulong.max;
enum real minPrecise = -maxPrecise;
if (y >= minPrecise && y <= maxPrecise)
{
    real absY = abs(y);
    ulong w = cast(ulong)absY;
    if (w != absY)
        return sqrt(x); // Complex result -- create a NaN
    if (w & 1) sign = -1.0;
}
x = -x;

However, looking at the whole function, I think it would benefit from a major
refactoring as well. So much duplicated logic...

Is that something I should do, or would it mostly likely be rejected on the
basis of, "If it ain't broke, don't fix it"?

--


More information about the Digitalmars-d-bugs mailing list