test for nan

Peter Maas fpetermaas at netscape.net
Thu Apr 1 04:41:12 EST 2004


Peter Maas wrote:
> John Hunter wrote:
>> Is there a better way to test for NaN than
>>
>>    str(p1)=='nan'
>>
>> where p1 is a float?
> [...]
> 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

Shorter:

def isNaN(x):
     return x != x

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