How to represent the infinite ?

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Fri Jun 21 22:20:42 EDT 2002


Tim Peters <tim.one at comcast.net> wrote:
>
>I intended that x**y act the same as math.pow(x, y).

OK, here it is:

>>> from math import *
>>> pow (1e200, 2)
inf
>>> 1e200**2
inf

Here's the new patch (without any testing for other effects).  Are there
documentations of the circumstances where the commented-out code is supposed
to be useful?  Are there unit tests for them?

Huaiyu


diff -rcN Python-2.2.1/Include/pyport.h Python-2.2.1.i/Include/pyport.h
*** Python-2.2.1/Include/pyport.h	Mon Mar 11 02:16:23 2002
--- Python-2.2.1.i/Include/pyport.h	Wed May  8 15:20:30 2002
***************
*** 301,311 ****
   */
  #define Py_ADJUST_ERANGE1(X)						\
  	do {								\
! 		if (errno == 0) {					\
  			if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL)	\
  				errno = ERANGE;				\
  		}							\
! 		else if (errno == ERANGE && (X) == 0.0)			\
  			errno = 0;					\
  	} while(0)
  
--- 301,311 ----
   */
  #define Py_ADJUST_ERANGE1(X)						\
  	do {								\
! 		/*if (errno == 0) {					\
  			if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL)	\
  				errno = ERANGE;				\
  		}							\
! 		else */ if (errno == ERANGE && (X) == 0.0)			\
  			errno = 0;					\
  	} while(0)
  
***************
*** 313,320 ****
  	do {								\
  		if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL ||	\
  		    (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) {	\
! 				if (errno == 0)				\
! 					errno = ERANGE;			\
  		}							\
  		else if (errno == ERANGE)				\
  			errno = 0;					\
--- 313,320 ----
  	do {								\
  		if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL ||	\
  		    (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) {	\
! 			/*	if (errno == 0)				\
! 				errno = ERANGE; */			\
  		}							\
  		else if (errno == ERANGE)				\
  			errno = 0;					\
diff -rcN Python-2.2.1/Modules/mathmodule.c Python-2.2.1.i/Modules/mathmodule.c
*** Python-2.2.1/Modules/mathmodule.c	Thu Sep  6 01:16:17 2001
--- Python-2.2.1.i/Modules/mathmodule.c	Fri Jun 21 19:06:48 2002
***************
*** 35,44 ****
  		 * overflow, so testing the result for zero suffices to
  		 * distinguish the cases).
  		 */
! 		if (x)
! 			PyErr_SetString(PyExc_OverflowError,
! 					"math range error");
! 		else
  			result = 0;
  	}
  	else
--- 35,44 ----
  		 * overflow, so testing the result for zero suffices to
  		 * distinguish the cases).
  		 */
! 		/* if (x)
! 		   PyErr_SetString(PyExc_OverflowError,
! 			 "math range error");
! 		else */
  			result = 0;
  	}
  	else
diff -rcN Python-2.2.1/configure.in Python-2.2.1.i/configure.in
*** Python-2.2.1/configure.in	Mon Mar 11 02:14:23 2002
--- Python-2.2.1.i/configure.in	Wed May  8 15:47:07 2002
***************
*** 1777,1786 ****
  # (none yet)
  
  # Linux requires this for correct f.p. operations
! AC_CHECK_FUNC(__fpu_control,
!   [],
!   [AC_CHECK_LIB(ieee, __fpu_control)
! ])
  
  # Check for --with-fpectl
  AC_MSG_CHECKING(for --with-fpectl)
--- 1777,1787 ----
  # (none yet)
  
  # Linux requires this for correct f.p. operations
! #AC_CHECK_FUNC(__fpu_control,
! #  [],
! #  [AC_CHECK_LIB(ieee, __fpu_control)
! #])
! AC_CHECK_LIB(ieee, __fpu_control)
  
  # Check for --with-fpectl
  AC_MSG_CHECKING(for --with-fpectl)
diff -rcN Python-2.2.1/pyconfig.h.in Python-2.2.1.i/pyconfig.h.in
*** Python-2.2.1/pyconfig.h.in	Wed Oct 24 10:10:49 2001
--- Python-2.2.1.i/pyconfig.h.in	Wed May  8 15:53:51 2002
***************
*** 748,754 ****
  #undef HAVE_LIBDLD
  
  /* Define if you have the ieee library (-lieee).  */
! #undef HAVE_LIBIEEE
  
  #ifdef __CYGWIN__
  #ifdef USE_DL_IMPORT
--- 748,754 ----
  #undef HAVE_LIBDLD
  
  /* Define if you have the ieee library (-lieee).  */
! #define HAVE_LIBIEEE
  
  #ifdef __CYGWIN__
  #ifdef USE_DL_IMPORT



More information about the Python-list mailing list