[Python-Dev] Why is nan != nan? (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Thu Mar 25 12:22:12 CET 2010


Mark Dickinson wrote:

Here's an interesting recent blog post on this subject, from the creator of Eiffel:

http://bertrandmeyer.com/2010/02/06/reflexivity-and-other-pillars-of-civilization/

Interesting. So the natural tweak that would arise from that perspective is for us to restore reflexivity by declaring that any given NaN is equal to itself but not to any other NaN (even one with the same payload).

With NaN (in general) not being interned, that would actually fit the idea of a NaN implicitly carrying the operation that created the NaN as part of its definition of equivalence.

So, I'm specifically putting that proposal on the table for both float and Decimal NaNs in Python:

"Not a Number" is not a single floating point value. Instead each instance is a distinct value representing the precise conditions that created it. Thus, two "NaN" values x and y will compare equal iff they are the exact same NaN object (i.e. "if isnan(x) then x == y iff x is y".

As stated above, such a change would allow us to restore reflexivity (eliminating a bunch of weirdness) while still honouring the idea of NaN being a set of values rather than a single value.

Cheers, Nick.

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



More information about the Python-Dev mailing list