test for nan

Michael Hudson mwh at python.net
Wed Mar 31 13:20:02 CEST 2004


John Hunter <jdhunter at ace.bsd.uchicago.edu> writes:

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

I'd hope so: that's exceeding unportable.  Of course, all things to do
with nans are unportable, so you're going to have to tell us more of
your requirements...

Cheers,
mwh

-- 
  I have *both* hands clapping, but I'm still not sure it's a sound.
  When I tried deciding if it were a sound while clapping only one
  hand, I fell off my chair.
                         -- Peter Hansen, Zen master, comp.lang.python



More information about the Python-list mailing list