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

Nick Coghlan ncoghlan at gmail.com
Sat Mar 27 14:21:39 CET 2010

Mark Dickinson wrote:
> On Fri, Mar 26, 2010 at 11:16 PM, 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.
> Yes;  those are the only two options I've seen that seem workable.  Of
> the two, I prefer the first (do nothing), but would be content with
> second.

I've ended up in the same place as Mark: +1 on retaining the status quo
(possibly with better warnings about the potential oddities of floating
point values being placed in equality-based containers), +0 on changing
NaN equality to check identity first in order to provide reflexivity
under == for these two types.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list