Comparisons of incompatible types

John Nagle nagle at animats.com
Thu Dec 9 12:34:19 EST 2010


On 12/9/2010 12:36 AM, Terry Reedy wrote:
> On 12/9/2010 2:58 AM, Steven D'Aprano wrote:
>> On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote:
> I believe that is that exactly one of <,=.> are true.

Not for NaNs.

 >>> NaN = float('nan')
 >>> NaN == NaN
False
 >>> NaN > NaN
False
 >>> NaN < NaN
False

    That's IEEE 754 compliant.  NaN is not equal to NaN.
That's by design.  But it really messes up sorting.

    Python "dict" types, however, treat "NaN" as a unique value,
because they're hash based on the underlying representation.

    (The best coverage of this whole topic was the Apple Numerics Manual
for the original Mac.  Apple hired the floating point expert from
Berkeley to get this right. Then Apple went from the M68xxx series
to the IBM PowerPC, and 80-bit floats to 64-bit floats, breaking all
the engineering applications, most of which were never ported to the
PowerPC.)

				John Nagle





More information about the Python-list mailing list