Re: test for nan
From: Peter Maas (fpetermaas_at_netscape.net)
Date: 04/01/04
- Next message: Peter Maas: "Re: ANNOUNCE: 'goto' for Python"
- Previous message: Michele Simionato: "Re: Prothon, metaclasses, Zope [Was: A 'Python like' language]"
- Next in thread: Peter Maas: "Re: test for nan"
- Reply: Peter Maas: "Re: test for nan"
- Reply: Peter Otten: "Re: test for nan"
- Reply: Michael Hudson: "Re: test for nan"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 01 Apr 2004 10:23:41 +0200
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@mplusr.de -------------------------------------------------------------------
- Next message: Peter Maas: "Re: ANNOUNCE: 'goto' for Python"
- Previous message: Michele Simionato: "Re: Prothon, metaclasses, Zope [Was: A 'Python like' language]"
- Next in thread: Peter Maas: "Re: test for nan"
- Reply: Peter Maas: "Re: test for nan"
- Reply: Peter Otten: "Re: test for nan"
- Reply: Michael Hudson: "Re: test for nan"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|