Bug 20508 – std.math.pow(-infinity, y) does not return NaN for imaginary or complex results
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-01-15T19:45:12Z
Last change time
2021-01-22T07:31:04Z
Keywords
pull
Assigned to
No Owner
Creator
thomas.bockman
Comments
Comment #0 by thomas.bockman — 2020-01-15T19:45:12Z
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?
Comment #1 by bugzilla — 2020-01-17T10:41:26Z
IMHO the current implementation is broken. Probably it's been implemented with integers in mind (for the exponent). Before fixing this, I'd like to completely understand -inf ^^ y for any y. I will be able to figure this out myself, but this will take a while. So if you've got a link to a page, where this is explained or could provide this information, it would be great. :-)
Comment #2 by dlang-bot — 2020-01-24T08:17:09Z
@berni44 created dlang/phobos pull request #7363 "Fix Issue 20508 - std.math.pow(-infinity, y) does not return NaN for imaginary or complex results" fixing this issue:
- Fix Issue 20508 - std.math.pow(-infinity, y) does not return NaN for
imaginary or complex results
https://github.com/dlang/phobos/pull/7363
Comment #3 by dlang-bot — 2021-01-17T18:02:54Z
@berni44 created dlang/phobos pull request #7747 "Fix Issue 20508 - std.math.pow(-infinity, y) does not return NaN for imaginary or complex results" fixing this issue:
- Fix Issue 20508 - std.math.pow(-infinity, y) does not return NaN for
imaginary or complex results
https://github.com/dlang/phobos/pull/7747
Comment #4 by dlang-bot — 2021-01-22T07:31:04Z
dlang/phobos pull request #7747 "Fix Issue 20508 - std.math.pow(-infinity, y) does not return NaN for imaginary or complex results" was merged into master:
- 7cc7d4d01a6f80aaaa1ada095f553c151f0f49bc by Bernhard Seckinger:
Fix Issue 20508 - std.math.pow(-infinity, y) does not return NaN for
imaginary or complex results
https://github.com/dlang/phobos/pull/7747