Portably generating infinity and NaN

Michael Hoffman cam.ac.uk at mh391.invalid
Fri Apr 13 20:18:16 EDT 2007


Michael Hoffman wrote:
> skip at pobox.com wrote:
>>     >> (Note the absence of a demonstration on Windows.)  Can't the 
>> above be
>>     >> blessed as the One True Way and wormed around in floatmodule.c for
>>     >> those platforms where float'ing "NaN" or "Inf" doesn't currently
>>     >> work?
>>
>>     Martin> How would you do the worming-around?
>>
>> I don't know.  On I was just asking.  On unixoid systems I sort of assume
>> you could add tests to the configure script to detect what worked.  If
>> converting the strings works you're done.  If not, maybe Robert Kern's 
>> numpy
>> code could be run in the configure script to generate constants for 
>> NaN and
>> Inf that could be used in floatmodule.c.  Windows would probably have 
>> to be
>> hard-coded, but except for 32-bit and 64-bit differences it should be the
>> same all over, yes?
> 
> If you're going to change CPython to do this, I think adopting PEP 754, 
> and using the fpconst module would be better than changing how float() 
> works when called on string literals. The only thing I don't like about 
> it is the camelcasing of the functions.
> 
> http://www.python.org/dev/peps/pep-0754/

I notice in the tracker, kousu suggested an alternative design, where 
the test functions become part of the float type. So you'd have 
float.isnan(), float.isfinite(), etc.

http://sourceforge.net/tracker/?func=detail&aid=1151323&group_id=5470&atid=305470

-- 
Michael Hoffman



More information about the Python-list mailing list