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

Nick Coghlan ncoghlan at gmail.com
Thu Mar 25 15:08:48 CET 2010

Jesus Cea wrote:
> But IEEE 754 was created by pretty clever guys and sure they had a
> reason for define things in the way they are. Probably we are missing
> something.

Yes, this is where their "implementable in a hardware circuit" focus
comes in. They were primarily thinking of a floating point
representation where the 32/64 bits are *it* - you can't have "multiple
NaNs" because you don't have the bits available to describe them.

We don't have that limitation - by bring id() into play for NaN equality
tests we have a lot more bits to play with (effectively adding an extra
32 or 64 bits to the floating point value just to say "which NaN is this
one?"). Doubling the size of your storage just to have multiple kinds of
NaN would be insane, but in our case the extra storage is already in use
- we would just be applying an additional interpretation to it.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list