float("nan") in set or as key

Nobody nobody at nowhere.com
Sun May 29 17:19:49 EDT 2011


On Sun, 29 May 2011 10:29:28 +0000, Steven D'Aprano wrote:

>>     The correct answer to "nan == nan" is to raise an exception, because
>> you have asked a question for which the answer is nether True nor False.
> 
> Wrong.

That's overstating it. There's a good argument to be made for raising an
exception. Bear in mind that an exception is not necessarily an error,
just an "exceptional" condition.

> The correct answer to "nan == nan" is False, they are not equal.

There is no correct answer to "nan == nan". Defining it to be false is
just the "least wrong" answer. Arguably, "nan != nan" should also be
false, but that would violate the invariant "(x != y) == !(x == y)".




More information about the Python-list mailing list