www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20508] New: std.math.pow(-infinity, y) does not return NaN

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

          Issue ID: 20508
           Summary: std.math.pow(-infinity, y) does not return NaN for
                    imaginary or complex results
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: thomas.bockman gmail.com

void main() {
    import std.stdio, std.math;
    writefln("%s", pow(-double.infinity, 0.5)); // wrongly prints "inf"
    writefln("%s", sqrt(-double.infinity));     // correctly prints "-nan"
}

I realize that pow() is following the spec given in the documentation here, and
that at least some implementations of the C standard library apparently do the
same thing.

But, the behaviour of pow() is mathematically incorrect here, and sabotages the
ability of floating-point algorithms to detect and handle the generation of
imaginary and complex results properly.

Is there an actual good reason it works this way, or was this just copied from
some broken C implementation?

--
Jan 15 2020