This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients jmfauth, mark.dickinson
Date 2010-01-08.19:25:25
SpamBayes Score 1.6342483e-13
Marked as misclassified No
Message-id <1262978728.03.0.343268610719.issue7660@psf.upfronthosting.co.za>
In-reply-to
Content
>>> float('nan') == float('nan')
False
>>> float('nan') != float('nan')
True

This is deliberate, though perhaps surprising if you haven't seen it before.  There's a long history of nan comparisons behaving this way (that is, x == nan always returns False, x != nan always returns True, even if x is a nan);  the behaviour comes from the IEEE 754 specification for floating-point arithmetic.

>>> copysign(1, float('nan'))
-1.0
>>> copysign(1, float('-nan'))
-1.0

This is also as expected:  the sign bit of a nan result (either as a result of conversion from string, or the result of an arithmetic operation) is probably best regarded as undefined.  The new string -> float conversion algorithms that are used in Python 3.1 (and in the upcoming 2.7) make sure that 'nan' and '-nan' are converted to nans with different signs, but again that's an implementation detail that shouldn't be relied upon.
History
Date User Action Args
2010-01-08 19:25:28mark.dickinsonsetrecipients: + mark.dickinson, jmfauth
2010-01-08 19:25:28mark.dickinsonsetmessageid: <1262978728.03.0.343268610719.issue7660@psf.upfronthosting.co.za>
2010-01-08 19:25:26mark.dickinsonlinkissue7660 messages
2010-01-08 19:25:26mark.dickinsoncreate