[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 14:27:31 PDT 2015


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

--- Comment #5 from Iain Buclaw <ibuclaw at gdcproject.org> ---
(In reply to thomas.bockman from comment #4)
> 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...
> 

There is no duplicated logic. ;)

--


More information about the Digitalmars-d-bugs mailing list