Portably generating infinity and NaN

"Martin v. Löwis" martin at v.loewis.de
Sat Apr 14 01:49:03 EDT 2007


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

I cannot imagine what the constants would look like. For +/-inf, it
might be possible to write down an expression that causes an overflow.
For NaN, I cannot think of such an expression (also, there are many
possible values that are all not-a-number - which of them should be
denoted by float("NaN")?).

Even if you determine at configure time whether or not the C library
already supports strtod("inf") and even if you then special-case
Windows - what do you do with platforms where neither approach works?

In short, I cannot think of a way to do that portably on all platforms
in C. If there was such a way, it probably would have been implemented
long ago.

Regards,
Martin



More information about the Python-list mailing list