Bug 5999 – Runtime treats floating NaNs to be equal

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-05-14T07:33:00Z
Last change time
2015-05-22T13:00:56Z
Keywords
CTFE, pull, wrong-code
Assigned to
verylonglogin.reg
Creator
kennytm

Comments

Comment #0 by kennytm — 2011-05-14T07:33:25Z
In CTFE, an array of NaN will not be equal to itself. However, this return 'true' in the runtime: ----------------------------------------------- bool f() { float[] h = [float.nan]; float[] i = [float.nan]; return h == i; } void main() { static assert(!f()); // ctfe is OK assert(!f()); // runtime asserts } ----------------------------------------------- The CTFE and runtime result should be consistent.
Comment #1 by paul.d.anderson — 2011-06-14T14:01:19Z
At the risk of stating the obvious, the correct result for a NaN compared to itself is false. I would assume (correct me if I'm wrong) that an array of NaN compared to itself would therefore also be false, since each element is != to itself. That is, the runtime assert is correct and the CTFE is incorrect.
Comment #2 by clugdbug — 2011-06-14T14:22:33Z
(In reply to comment #1) > At the risk of stating the obvious, the correct result for a NaN compared to > itself is false. I would assume (correct me if I'm wrong) that an array of NaN > compared to itself would therefore also be false, since each element is != to > itself. Yes. >That is, the runtime assert is correct and the CTFE is incorrect. I think you misread the code. CTFE returns not equal, runtime returns equal.
Comment #3 by bugzilla — 2012-01-20T22:05:03Z
Yes, the runtime is in error here.
Comment #4 by verylonglogin.reg — 2013-11-05T01:15:10Z
Comment #5 by verylonglogin.reg — 2013-11-07T08:47:27Z
*** Issue 7836 has been marked as a duplicate of this issue. ***