3 ms·
NaN == NaN is always false (at least in other languages I know).
by fyp 7y ago
NaN == NaN is always false (at least in other languages I know).
- kibwen 7y agoThis will be the case in any language that confirms to IEEE 754 (so, hopefully, all of them (because the only thing more confusing than properly implementing IEEE 754 is improperly implementing your own bespoke subset)). This property of NaN is required by the spec (and is, for example, why Rust's default HashMap refuses to accept floating point numbers as keys).
- umanwizard 7y agoI can confirm that this is true in C++ (or at least the common implementations), as required by IEEE. In particular, this means that sorting a container including NaNs is undefined behavior (since typical sorting algorithms rely on the property that for any x and y, exactly one of x < y, y < x, or x = y is true).