[Numpy-discussion] RE: Python 2.2 seriously crippled for numerical computation?

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Mon Mar 4 17:17:43 EST 2002


On Sat, 2 Mar 2002 12:04:44 -0600, Skip Montanaro <skip at pobox.com> wrote:
>According to the pow man page on my Mandrake 8.1 system it suggests that
>ERANGE should be set if its first arg is zero.  This appears to happen when
>x is around 1.5717e-162.  I suspect a bug in glibc (I have version 2.2.4).
>
>In the region where the problem occurs, Python's float_pow() looks like
>
>        PyFPE_START_PROTECT("pow", return NULL)
>        ix = pow(iv, iw);
>        PyFPE_END_PROTECT(ix)
>        Py_SET_ERANGE_IF_OVERFLOW(ix);
>
>Setting a break immediately after the pow() call shows that ERANGE is set
>even though it appears to have correctly returned 0.  Perhaps if iv < 1, ix
>== 0, and errno is ERANGE, errno should be cleared, at least for certain
>versions of glibc?
>

I can't quite follow you analysis here.  Can you put this into a stand-alone
C test prog?  The following C program produces exactly the same result on two
machines, yet on one machine P2.2 raises while on the other it does not.
What else need to be tested?

#include <math.h>
#include <stdlib.h>
#include <errno.h>
extern int errno;

main() {
  double x, y;
  x = 1e200;
  y = pow(x, 2);
  printf("%g %5g %d %s %d\n", x, y, errno, strerror(errno), ERANGE);
  x = 1e-200;
  y = pow(x, 2);
  printf("%g %5g %d %s %d\n", x, y, errno, strerror(errno), ERANGE);
}

Produces
1e+200   inf 34 Numerical result out of range 34
1e-200     0 34 Numerical result out of range 34

Huaiyu




More information about the Python-list mailing list