[Python-Dev] Rich comparisons
Edward Loper
edloper at gradient.cis.upenn.edu
Fri Mar 19 10:29:40 EST 2004
Michael Hudson wrote:
> >>> float('nan')
> nan
> >>> _ == _
> False
This means that 'nan' is no longer a well-behaved dictionary key:
>>> x = {float('nan'):0}
>>> x[float('nan')] = 1
>>> print x
{nan: 0, nan: 1}
Even worse, we get different behavior if we use the "same copy" of nan:
>>> nan = float('nan')
>>> x = {nan:0}
>>> x[nan] = 1
>>> print x
{nan: 1}
If we *really* want nan==nan to be false, then it seems like we have to
say that nan is unhashable. I'm also disturbed by the fact that cmp()
has something different to say about their equality:
>>> cmp(float('nan'), float('nan'))
0
-Edward
More information about the Python-Dev
mailing list