[Python-ideas] checking for identity before comparing built-in objects

Chris Angelico rosuav at gmail.com
Thu Oct 4 16:30:50 CEST 2012


On Fri, Oct 5, 2012 at 12:19 AM, MRAB <python at mrabarnett.plus.com> wrote:
> On 2012-10-04 15:07, Mike Graham wrote:
>>
>> On Thu, Oct 4, 2012 at 10:02 AM, Mathias Panzenböck
>> <grosser.meister.morti at gmx.net> wrote:
>>>
>>> On 10/04/2012 03:53 PM, Steven D'Aprano wrote:
>>>>
>>>>
>>>> py> NAN == NAN
>>>> False
>>>
>>>
>>>
>>> Why isn't this True anyway? Is there a PEP that explains this (IMHO odd)
>>> behavior?
>>
>>
>> IEEE 754 specifies this.
>>
> Think of it this way:
>
> Calculation A returns NaN for some reason
>
> Calculation B also returns NaN for some reason
>
> Have they really returned the same result? Just because they're both
> NaN doesn't mean that they're the _same_ NaN...

The only other viable option would be to declare that (NaN==NaN) is
NaN - kinda like SQL's NULL and its weird semantics. And that would be
*highly* confusing to many situations.

ChrisA



More information about the Python-ideas mailing list