Bug 20542 – std.math.nextafter(NaN, y) and nextafter(x, NaN) should return NaN

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-01-28T15:57:32Z
Last change time
2020-01-31T03:25:08Z
Keywords
pull
Assigned to
No Owner
Creator
e10s

Comments

Comment #0 by electrolysis.jp — 2020-01-28T15:57:32Z
Currently the result of nextafter(x, y) against NaN is undefined at least in the document. Actually, although nextafter(NaN, y) returns NaN as a result of nextDown(NaN), nextafter(x, NaN) returns nextDown(x), as below: void main() { import std; auto a = 4.0; writefln("%a", a); // 0x1p+2 writefln("%a", nextafter(a.nan, a)); // nan, it's fine. writefln("%a", nextafter(a, a.nan)); // 0x1.fffffffffffffp+1, but should be nan. } On POSIX, the man page of nextafter(3) describes ambiguously: > If x or y is NaN, a NaN shall be returned. http://man7.org/linux/man-pages/man3/nextafter.3p.html On the other hand, the Linux version says: > If x or y is a NaN, a NaN is returned. http://man7.org/linux/man-pages/man3/nextafter.3.html Similarly, Microsoft says: > If either x or y is a NAN, then the return value is one of the input NANs. https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/nextafter-functions?view=vs-2019
Comment #1 by dlang-bot — 2020-01-28T16:20:53Z
@e10s created dlang/phobos pull request #7380 "Fix Issue 20542 - std.math.nextafter(NaN, y) and nextafter(x, NaN) sh…" fixing this issue: - Fix Issue 20542 - std.math.nextafter(NaN, y) and nextafter(x, NaN) should return NaN https://github.com/dlang/phobos/pull/7380
Comment #2 by dlang-bot — 2020-01-31T03:25:08Z
dlang/phobos pull request #7380 "Fix Issue 20542 - std.math.nextafter(NaN, y) and nextafter(x, NaN) sh…" was merged into master: - 2d726d2dc3217c98f0cec7088a04ccb19e6f6346 by Kazuya Takahashi: Fix Issue 20542 - std.math.nextafter(NaN, y) and nextafter(x, NaN) should return NaN https://github.com/dlang/phobos/pull/7380