[Python-ideas] Why is nan != nan?

Adam Olsen rhamph at gmail.com
Thu Mar 25 19:33:48 CET 2010


IMO, we should go for the simplest of all usage: a NaN singleton,
shared by float and Decimal, compares equal to itself, unsortable, no
payload.

Usage of the payload is hypothetical.  Situations where comparing
false is "more correct" than comparing true are hypothetical, and
grossly outweighed by the situations where comparing true is blatantly
correct.

IEEE 754 doesn't say NaN should compare false; it says it should
compare "unordered".  We can't do that as we're not using a 4-way
comparison (which wouldn't generalize to complex anyway), so we have
to make up our own solution.  It might as well fit our needs, rather
than nobodies.


-- 
Adam Olsen, aka Rhamphoryncus



More information about the Python-ideas mailing list