float("nan") in set or as key
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun May 29 19:31:19 EDT 2011
On Sun, 29 May 2011 22:19:49 +0100, Nobody wrote:
> 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.
If so, I've never heard it, and I cannot imagine what such a good
argument would be. Please give it.
(I can think of *bad* arguments, like "NANs confuse me and I don't
understand the reason for their existence, therefore I'll give them
behaviours that make no sense and aren't useful". But you did state there
is a *good* argument.)
> Bear in mind that an exception is not necessarily an error,
> just an "exceptional" condition.
True, but what's your point? Testing two floats for equality is not an
exceptional condition.
>> The correct answer to "nan == nan" is False, they are not equal.
>
> There is no correct answer to "nan == nan".
Why on earth not?
> Defining it to be false is just the "least wrong" answer.
So you say, but I think you are incorrect.
> Arguably, "nan != nan" should also be false,
> but that would violate the invariant "(x != y) == !(x == y)".
I cannot imagine what that argument would be. Please explain.
--
Steven
More information about the Python-list
mailing list