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

Robert Kern robert.kern at gmail.com
Sun Mar 28 01:27:57 CET 2010

On 2010-03-27 13:36 , Adam Olsen wrote:
> On Fri, Mar 26, 2010 at 17:16, Raymond Hettinger
> <raymond.hettinger at gmail.com>  wrote:
>> Of the ideas I've seen in this thread, only two look reasonable:
>> * Do nothing.  This is attractive because it doesn't break anything.
>> * Have float.__eq__(x, y) return True whenever x and y are
>>     the same NaN object.  This is attractive because it is a
>>     minimal change that provides a little protection for
>>     simple containers.
>> I support either of those options.
> What's the flaw in using isnan()?

There are implicit comparisons being done inside list.__contains__() and other 
such methods. They do not, and should not, know about isnan().

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-Dev mailing list