4 ms·
The stupid thing about IEEE NaN is that it's not equal to itself! Why would it be? The rationale makes perfect sense. It would be unexpected to believe that 17
by nemothekid 12y ago
The stupid thing about IEEE NaN is that it's not equal to itself!
Why would it be? The rationale makes perfect sense. It would be unexpected to believe that 17/0 == 0^0. Both are NaN, and equally nonsense, but 2 very different statements.
Secondly, IIRC, NaN is supposed to break assert(x==x), because if you use NaN in your program, then your program is undefined.
- hesselink 12y agoWhile your overall point is correct, your example is wrong: 17/0 == Infinity, and 0^0 == 1. Neither is NaN :)
- kazinator 12y agoYour == expression has distinct operands which are the results of different evaluations. The problem is that a NaN is not equal to itself: double nan = /* NaN-producing expression */ if (nan == nan) { /* dead code */ }