Re: test for nan

From: Peter Maas (fpetermaas_at_netscape.net)
Date: 04/01/04


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
-------------------------------------------------------------------


Relevant Pages

  • test for nan
    ... I have a C extension module that is returning some doubles. ... the numbers print as 'nan'. ... John Hunter ...
    (comp.lang.python)
  • Re: test for nan
    ... At some point, John Hunter wrote: ... > doubles get out of range, the numbers print as 'nan'. ... If you're on something that uses IEEE floating-point representations, ...
    (comp.lang.python)
  • Re: equality and null pointers
    ... fundamental meaning of NaN? ... at least when you want to use Doubles as hash table keys. ...
    (comp.lang.java.programmer)
  • Re: Meaning of Double.Epsilon
    ... >> sort an array of doubles (at least with generics, ... > NaN is just for that purpose: If a value is NaN it stays NaN even if used ... like these have to be values that cannot be result of a calculation. ... converting it to an int will throw an ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: std::max and NAN
    ... collection of doubles of which at least one is NaN causes undefined ... as an infinite loop. ... algorithmical reasons. ...
    (microsoft.public.vc.stl)