Skip to content

Commit e05e840

Browse files
committed
Issue #5724: Fix cmath failures on Solaris 10.
1 parent 6703225 commit e05e840

File tree

7 files changed

+397
-22
lines changed

7 files changed

+397
-22
lines changed

Include/pymath.h

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ extern double copysign(double, double);
7777
#define Py_MATH_E 2.7182818284590452354
7878
#endif
7979

80+
/* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU
81+
register and into a 64-bit memory location, rounding from extended
82+
precision to double precision in the process. On other platforms it does
83+
nothing. */
84+
85+
/* we take double rounding as evidence of x87 usage */
86+
#ifndef Py_FORCE_DOUBLE
87+
# ifdef X87_DOUBLE_ROUNDING
88+
PyAPI_FUNC(double) _Py_force_double(double);
89+
# define Py_FORCE_DOUBLE(X) (_Py_force_double(X))
90+
# else
91+
# define Py_FORCE_DOUBLE(X) (X)
92+
# endif
93+
#endif
94+
8095
/* Py_IS_NAN(X)
8196
* Return 1 if float or double arg is a NaN, else 0.
8297
* Caution:
@@ -87,7 +102,7 @@ extern double copysign(double, double);
87102
* Note: PC/pyconfig.h defines Py_IS_NAN as _isnan
88103
*/
89104
#ifndef Py_IS_NAN
90-
#ifdef HAVE_ISNAN
105+
#if defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 1
91106
#define Py_IS_NAN(X) isnan(X)
92107
#else
93108
#define Py_IS_NAN(X) ((X) != (X))
@@ -101,14 +116,18 @@ extern double copysign(double, double);
101116
* This implementation may set the underflow flag if |X| is very small;
102117
* it really can't be implemented correctly (& easily) before C99.
103118
* Override in pyconfig.h if you have a better spelling on your platform.
119+
* Py_FORCE_DOUBLE is used to avoid getting false negatives from a
120+
* non-infinite value v sitting in an 80-bit x87 register such that
121+
* v becomes infinite when spilled from the register to 64-bit memory.
104122
* Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf
105123
*/
106124
#ifndef Py_IS_INFINITY
107-
#ifdef HAVE_ISINF
108-
#define Py_IS_INFINITY(X) isinf(X)
109-
#else
110-
#define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
111-
#endif
125+
# if defined HAVE_DECL_ISINF && HAVE_DECL_ISINF == 1
126+
# define Py_IS_INFINITY(X) isinf(X)
127+
# else
128+
# define Py_IS_INFINITY(X) ((X) && \
129+
(Py_FORCE_DOUBLE(X)*0.5 == Py_FORCE_DOUBLE(X)))
130+
# endif
112131
#endif
113132

114133
/* Py_IS_FINITE(X)
@@ -118,7 +137,9 @@ extern double copysign(double, double);
118137
* Note: PC/pyconfig.h defines Py_IS_FINITE as _finite
119138
*/
120139
#ifndef Py_IS_FINITE
121-
#ifdef HAVE_FINITE
140+
#if defined HAVE_DECL_ISFINITE && HAVE_DECL_ISFINITE == 1
141+
#define Py_IS_FINITE(X) isfinite(X)
142+
#elif defined HAVE_FINITE
122143
#define Py_IS_FINITE(X) finite(X)
123144
#else
124145
#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 2.6.3
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #5724: (See also issue #4575.) Fix Py_IS_INFINITY macro to
16+
work correctly on x87 FPUs: it now forces its argument to double
17+
before testing for infinity.
18+
1519
- Issue #4971: Fix titlecase for characters that are their own
1620
titlecase, but not their own uppercase.
1721

PC/pyconfig.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,11 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
405405
/* Define to 1 if you have the `copysign' function. */
406406
#define HAVE_COPYSIGN 1
407407

408-
/* Define to 1 if you have the `isinf' function. */
409-
#define HAVE_ISINF 1
408+
/* Define to 1 if you have the `isinf' macro. */
409+
#define HAVE_DECL_ISINF 1
410410

411411
/* Define to 1 if you have the `isnan' function. */
412-
#define HAVE_ISNAN 1
412+
#define HAVE_DECL_ISNAN 1
413413

414414
/* Define if on AIX 3.
415415
System headers sometimes define this.

Python/pymath.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#include "Python.h"
22

3+
#ifdef X87_DOUBLE_ROUNDING
4+
/* On x86 platforms using an x87 FPU, this function is called from the
5+
Py_FORCE_DOUBLE macro (defined in pymath.h) to force a floating-point
6+
number out of an 80-bit x87 FPU register and into a 64-bit memory location,
7+
thus rounding from extended precision to double precision. */
8+
double _Py_force_double(double x)
9+
{
10+
volatile double y;
11+
y = x;
12+
return y;
13+
}
14+
#endif
15+
316
#ifndef HAVE_HYPOT
417
double hypot(double x, double y)
518
{

0 commit comments

Comments
 (0)