test for nan

Peter Otten __peter__ at web.de
Thu Apr 1 04:56:44 EST 2004


Peter Maas wrote:

> As far as I know NaN is th only value that yields false when compared
> to itself. This leads to
> 
> def isNaN(x):
>      return (x == x) == False

That is not portable:

Python 2.3.3 (#1, Jan  3 2004, 13:57:08)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> nan = float("nan")
>>> nan != nan
False


Peter




More information about the Python-list mailing list