test for nan
David M. Cooke
cookedm+news at physics.mcmaster.ca
Wed Mar 31 14:12:13 EST 2004
At some point, Skip Montanaro <skip at pobox.com> wrote:
> John> Is there a better way to test for NaN than
>
> John> str(p1)=='nan'
>
> John> where p1 is a float?
>
> Saw this in the list archives earlier today:
>
> >>> inf = float("1e9999")
> >>> inf
> Inf
> >>> nan = inf-inf
> >>> nan
> NaN
> >>> p1 = 5.0
> >>> p1 == nan
> False
The last line doesn't work for me:
Python 2.3.3 (#2, Feb 24 2004, 09:29:20)
[GCC 3.3.3 (Debian)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> inf = float('1e9999')
>>> inf
inf
>>> nan = inf - inf
>>> nan
nan
>>> p1 = 5.0
>>> p1 == nan
True
hmmm... Have to admit that looks funny.
--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
More information about the Python-list
mailing list