Sorting NaNs

Richard Damon Richard at Damon-Family.org
Sat Jun 2 20:11:30 EDT 2018


On 6/2/18 7:50 PM, Ned Batchelder wrote:
> Careful, "same input" is vague.  In Python2, object() instances are
> compared based on their id, in other words, their memory location. It
> would be easy to overlook the idea that the layout in memory is part
> of whether two inputs are "the same".
>
> I have no idea what factors determine the result of comparing NaNs.
>
> --Ned.

NaNs have VERY defined comparison results, they are just strange. If you
compare a NaN to another floating point value (even another NaN) all
comparisons except 'not equals' are false, and 'not equals' are true.
Thus all NaNs are unequal to all numbers, including themselves, but are
neither greater than or than than any of them.


-- 
Richard Damon




More information about the Python-list mailing list