test for nan

From: John Hunter (jdhunter_at_ace.bsd.uchicago.edu)
Date: 03/30/04


Date: Tue, 30 Mar 2004 14:24:57 -0600
To: python-list@python.org


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



Relevant Pages

  • Re: test for nan
    ... John Hunter wrote: ... > I have a C extension module that is returning some doubles. ... > doubles get out of range, the numbers print as 'nan'. ... Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. ...
    (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: 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: 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)