IEEE 754 NaN Behavior
Discussions center on the properties and quirks of NaN in IEEE 754 floating-point arithmetic, such as NaN != NaN, comparisons with infinities, signed zeros, and standard compliance across languages.
Activity Over Time
Top Contributors
Keywords
Sample Comments
If your language can't use signalling NaNs correctly, get a better language.
This is default IEEE 754 behavior.https://en.wikipedia.org/wiki/NaN
NaN stuff works according to the IEEE 754 spec.
You can look these things up for yourself - they're standardised in most language's implementations in something called IEEE 754. In the cases you've asked about they're false and true. Is this what you want in all cases? No. Is this what you want in some cases? Yes. It's a tradeoff. You can still observe the difference by dividing by zero (which should be another indication that these aren't real numbers as we're conventionally understand them.)
NaN is meant to represent a non-sensical mathematical operation (like divide by 0). One non-sensical mathematical operation is not the same as some other non-sensical mathematical operation (1/0 !== Infinity/Infinity)
Pretty sure that their behaviors on NaN arguments will also differ.
They'd differ for floating-point NaNs.
But NaN is also a quirk of IEEE754 floating pount math.
Not sure I like the sound of that. It sounds like the floating point wat of "NaN != NaN".
Or there's NaN which just results in NaN and doesn't equal itself. No need to crash.