[issue21873] Tuple comparisons with NaNs are broken

akira report at bugs.python.org
Thu Jun 26 16:42:04 CEST 2014


akira added the comment:

Is the issue that:

  >>> (1, float('nan')) == (1, float('nan'))
  False

but

  >>> nan = float('nan')
  >>> (1, nan) == (1, nan)
  True

?

`nan != nan` therefore it might be expected that `(a, nan) != (a, nan)` [1]:

> The values float('NaN') and Decimal('NaN') are special. The are identical to themselves, x is x but are not equal to themselves, x != x. 

> Tuples and lists are compared lexicographically using comparison of corresponding elements. This means that to compare equal, each element must compare equal and the two sequences must be of the same type and have the same length.
> If not equal, the sequences are ordered the same as their first differing elements.

[1]: https://docs.python.org/3.4/reference/expressions.html#comparisons

----------
nosy: +akira

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21873>
_______________________________________


More information about the Python-bugs-list mailing list