[Python-Dev] decimal.py: == and != comparisons involving NaNs (original) (raw)

Mark Dickinson dickinsm at gmail.com
Mon Nov 9 14:25:42 CET 2009


On Mon, Nov 9, 2009 at 1:21 PM, Stefan Krah <stefan-usenet at bytereef.org> wrote:

Antoine Pitrou <solipsis at pitrou.net> wrote:

(NB: interestingly, float("nan") does hash)

I wonder if it should:

d = {float('nan'): 10, 0: 20} 0 in d True float('nan') in d False d[float('nan')] Traceback (most recent call last):  File "", line 1, in KeyError: nan

That's because you're creating two different float nans. Compare with:

Python 3.2a0 (py3k:76132M, Nov 6 2009, 14:47:39) [GCC 4.2.1 (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

nan = float('nan') d = {nan: 10, 0: 20} nan in d True d[nan] 10

Mark



More information about the Python-Dev mailing list