test for nan
Peter Maas
fpetermaas at netscape.net
Thu Apr 1 03:23:41 EST 2004
John Hunter wrote:
> I have a C extension module that is returning some doubles. When the
> doubles get out of range, the numbers print as 'nan'.
>
> Is there a better way to test for NaN than
>
> str(p1)=='nan'
>
> where p1 is a float?
>
> python2.3
>
> Thanks,
> John Hunter
>
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
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