[Python-ideas] Disallow orderring comparison to NaN

Steven D'Aprano steve at pearwood.info
Thu Apr 28 16:01:53 CEST 2011


Alexander Belopolsky wrote:
> Another spin-off from the "[Python-Dev] PyObject_RichCompareBool
> identity shortcut" thread:
> 
>> I would like to discuss another peculiarity of NaNs:
>>
>>>>> float('nan') < 0
>> False
>>>>> float('nan') > 0
>> False
>>
>> This property in my experience causes much more trouble than nan ==
>> nan being false.  The problem is that common sorting or binary search
>> algorithms may degenerate into infinite loops in the presence of nans.

I think I would like to see a demonstration of this rather than just 
take your word for it.

 >>> sorted([4, 5, 1, float('nan'), 3, 2])
[1, 2, 3, 4, 5, nan]




-- 
Steven




More information about the Python-ideas mailing list