Why float('Nan') == float('Nan') is False
On 2/13/19 12:32 PM, Marko Rauhamaa wrote:
> "Avi Gross" <avigross at verizon.net>:
>> A NaN is a bit like a black hole. Anything thrown in disappears and
>> that is about all we know about it. No two black holes are the same
>> even if they seem to have the same mass, spin and charge. All they
>> share is that we don't know what is in them.
> Then, how do you explain:
> >>> float("nan") != float("nan")
> Why's that not False?
Because IEEE-754 decided that it was non-optional that (x != y) was
equal to not (x == y). Which is not the case for the ordering
operators, since ordering is inherently undefined.
In part, these decisions were made to make it possible to detect a NaN
in C in the absence of an isnan() function. If (x != x), then x must be
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.