[Issue 17324] New: Floating point 1/(1/x) > 0 if x > 0 not generally true
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Apr 13 15:15:14 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17324
Issue ID: 17324
Summary: Floating point 1/(1/x) > 0 if x > 0 not generally true
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: qs.il.paperinik at gmail.com
In https://dlang.org/d-floating-point.html it is claimed:
"[...] in order to preserve identities such as: if x>0, then 1/(1/x) > 0."
But this is wrong, the identity doesn't hold anyway! Compile the following with
DMD v2.074.0.
void main()
{
import std.math : nextafter;
double x = nextafter(0.0, 1.0); // produce smallest denormal number > 0.
assert(x > 0);
double y = 1/x;
assert(y > 0);
assert(1/y > 0); // fails
assert(1/(1/x) > 0); // passes due to wrong optimuzation
}
--
More information about the Digitalmars-d-bugs
mailing list