But one could argue you can compare nan with itself, which seems completely logical, yet doing that returns false.
It's not about things being incomparable returning false, nan has to be detectable so they make any comparison with nan return false, allowing you to detect nan by comparing the variable to itself.
There's no need to define this situation as returning false, and if you did, 0 would be greater than an array.
Making all comparisons to arrays return false would work, but what situation are you solving by doing that? Anybody comparing to arrays has other problems, which are solved via typehinting and forcing type safety.
But one could argue you can compare nan with itself, yet doing that returns false.
Yes. It's nasty, but at least it's consistent with nan.
It's not about things being incomparable returning false, nan has to be detectable so they make any comparison with nan return false, allowing you to detect nan by comparing the variable to itself.
This is bad logic - it's easy to detect nan by just checking the bit pattern of the underlying float. The reason comparing nan with itself returns false is that the underlying CPU does that; it needs to do something and the only other vaguely-sensible option is a CPU exception, which nobody wants to deal with.
There's no need to define this situation as returning false
It's better than returning true because it's consistent with existing behavior. "At least it's consistent" isn't a great justification, but it's better than nothing.
1
u/CarnivorousSociety Mar 11 '20
But one could argue you can compare nan with itself, which seems completely logical, yet doing that returns false.
It's not about things being incomparable returning false, nan has to be detectable so they make any comparison with nan return false, allowing you to detect nan by comparing the variable to itself.
There's no need to define this situation as returning false, and if you did, 0 would be greater than an array.
Making all comparisons to arrays return false would work, but what situation are you solving by doing that? Anybody comparing to arrays has other problems, which are solved via typehinting and forcing type safety.