test for nan
Peter Maas
fpetermaas at netscape.net
Thu Apr 1 05:27:17 EST 2004
Peter Otten wrote:
>>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
Thanks for correction. I firmly believed that NaN != NaN -> True
was a property of IEEE 754 and of all software using this standard.
For gcc/Linux you could use
def isNaN(x):
return (x == 0) and (x == 1)
and utilize sys.platform. :)
Mit freundlichen Gruessen,
Peter Maas
--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------
More information about the Python-list
mailing list