[XML-SIG] [ pyxml-Bugs-436623 ] calculation of Inf

Tim Peters tim.one@home.com
Wed, 27 Jun 2001 17:40:55 -0400


[Uche Ogbuji]
> I need help with
>
> http://sourceforge.net/tracker/?func=detail&atid=106473&aid=436623
> &group_id=6473
>
> I got the trick of hacking out Inf as follows:
>
> Inf = 1e300 ** 2
>
> From a clpy posting of Tim Peters.  Jan says it only works on his
> HPUX as
>
> Inf = 1e300 * 1e300
>
> Which I could change to easily enough, but I wonder whether this
> would screw up other platforms.

I'm afraid it's impossible to say:  the C standard doesn't define anything
about what happens in IEEE-754 endcases, and platform behavior is all over
the map.

This report is especially mysterious, since in C terms Python merely does a
C-level

double z = x * x;
return z;

in *both* cases (floatobject.c's float_pow special-cases an integer exponent
and turns the power into an efficient sequence of multiplies then).  The bug
report is too vague to say any more about it.

Hmm.  In the pow case, we actually end up doing (unrolling the loop):

double p = 1e300;
double r = 1.0;
p *= p;
r *= p;  /* i.e., 1. * +Inf */
p *= p;  /* i.e., +Inf * +Inf */

return r;

So maybe this is some uniquely stupid-ass platform that incorrectly
complains about a +Inf *input* but not a +Inf *result*.  In that case, ya, a
straight multiply is safer.  Until somebody volunteers x-platform 754
support, though, it's a crapshoot.  Don't hold your breath <wink>.

In the meantime, 1e300 * 1e300 is as safe as it gets (although I *would*
have said the same about 1e300**2!).