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

Glenn Linderman v+python at g.nevcal.com
Fri Mar 26 02:56:00 CET 2010


On 3/25/2010 4:14 PM, Guido van Rossum wrote:
> On Thu, Mar 25, 2010 at 12:31 PM, Glenn Linderman<v+python at g.nevcal.com>  wrote:
>    
>> It is my understand that even bit-for-bit identical NaN values will compare
>> unequal according to IEEE 754 rules.
>>
>> I would have no problem with Python interning each encountered NaN value, to
>> avoid having bit-for-bit identical NaN values with different Python IDs, but
>> having them compare equal seems inappropriate.
>>      
> Let's please not intern NaNs. Interning is for performance. If you
> have enough NaNs to affect your performance I think you have bigger
> worries!
>    

I'm OK with interning NaNs, and I'm OK with not interning NaNs.  But I 
would much prefer to see Python conform to the IEEE 754 for float, and 
the Decimal standard for Decimal, where at all possible, including 
keeping NaNs not comparing equal to anything, themselves included.

And retaining a mode where Decimal is standoffish, and doesn't accept 
non-Decimal comparisons or arithmetic seems like a big win for program 
correctness to me.

Glenn


More information about the Python-Dev mailing list