4 ms·
There's no non-confusing option for comparisons. You have two invalid values, but they aren't necessarily the same invalid value. There are multiple operations
by nitwit005 7mo ago
There's no non-confusing option for comparisons. You have two invalid values, but they aren't necessarily the same invalid value. There are multiple operations that can produce NaN.
It's a sentinel value for an error. Once you have an error, doing math with the error code isn't sensible.
- caditinpiscinam 7mo agoThere are no non-confusing options, but some of those are still clearly worse than others. What should sorted([3, nan, 2, 4, 1]) give you in Python? A) [1, 2, 3, 4, nan] is an good option B) [nan, 1, 2, 3, 4] is an good option C) An error is an good option D) [3, nan, 1, 2, 4] is a silly, bad option. It's definitely not what you want, and it's quiet enough to slip by unnoticed. This is what you get when Nan != NaN NaN == NaN is wrong. NaN != NaN is wrong, unintuitive, and breaks the rest of your code. If you want to signal that an operation is invalid, then throw an error. The silently nonsensical semantics of NaN are the worst possible response
- paulddraper 7mo agoYes. And to boot…it’s only floating point numbers In invalid math op with integers produces an error (or undefined behavior). Definitely not some self unequal abomination.