D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.

Issue 4155

Summary: return of NaN to temporary fails equality test
Product: D Reporter: melvin.curran
Component: dmdAssignee: yebblies <yebblies>
Status: RESOLVED FIXED
Severity: critical CC: bugzilla, clugdbug, yebblies
Priority: P2 Keywords: pull, wrong-code
Version: D2
Hardware: x86
OS: All

Description melvin.curran 2010年05月03日 09:06:03 UTC
The problem is found in both DMD 1.059 and 2.044 and is demonstrated by the following program - every answer should be false, but that is not the case.
import std.stdio;
T getnan(T)() { return T.nan; }
void main()
{
 float f = 0.0;
 double d = 0.0;
 real r = 0.0;
 writefln("before assigning NaN, float:%s, double:%s, real:%s", f, d, r);
 f = getnan!(float)();
 d = getnan!(double)();
 r = getnan!(real)();
 writefln(" float test, literal:%s, assign:%s, temporary:%s", (float.nan == 0), (f == 0), (getnan!(float)() == 0));
 writefln("double test, literal:%s, assign:%s, temporary:%s", (double.nan == 0), (d == 0), (getnan!(double)() == 0));
 writefln(" real test, literal:%s, assign:%s, temporary:%s", (real.nan == 0), (r == 0), (getnan!(real)() == 0));
}
Comment 1 yebblies 2012年02月23日 06:42:51 UTC
https://github.com/D-Programming-Language/dmd/pull/760
When T is a float or double, and in memory, dmd loads it to gp registers, doubles it, then tests for zero. When it's in ST(0), dmd uses fucompp to test but the code that tests the flags is unaware of this and doesn't check the zero flag to see if it was a nan comparison.
Comment 2 yebblies 2012年02月26日 08:37:25 UTC
New pull
https://github.com/D-Programming-Language/dmd/pull/769 
Comment 3 github-bugzilla 2012年04月27日 18:21:45 UTC
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/ac10c87904a73311eba93143d1aa92988227be49
add yebblies fix Issue 4155 - return of NaN to temporary fails equality test
Comment 4 github-bugzilla 2012年04月27日 18:21:57 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/e1d597875183f58464ac44b8eb5d3d28f1f90170
add yebblies fix Issue 4155 - return of NaN to temporary fails equality test

AltStyle によって変換されたページ (->オリジナル) /