Index: Include/floatobject.h =================================================================== --- Include/floatobject.h (revision 67706) +++ Include/floatobject.h (working copy) @@ -32,6 +32,15 @@ return PyFloat_FromDouble(-Py_HUGE_VAL); \ } while(0) +/* Py_FORCE_DOUBLE is used to force a possibly extended precision value to + double precision; this is useful on x86 systems that make use of the x87 + FPU. See Modules/cmathmodule.c for an example of its use. On non x86 + systems it wouldn't be a problem if Py_FORCE_DOUBLE did nothing.*/ +PyAPI_FUNC(double) Py_force_double(double); +#ifndef Py_FORCE_DOUBLE +#define Py_FORCE_DOUBLE(x) Py_force_double(x) +#endif + PyAPI_FUNC(double) PyFloat_GetMax(void); PyAPI_FUNC(double) PyFloat_GetMin(void); PyAPI_FUNC(PyObject *) PyFloat_GetInfo(void); Index: Objects/floatobject.c =================================================================== --- Objects/floatobject.c (revision 67706) +++ Objects/floatobject.c (working copy) @@ -57,6 +57,18 @@ return p + N_FLOATOBJECTS - 1; } +/* This function (Py_force_double) doesn't really belong here: it's needed + in the math and cmath modules, but we put it in a different file to stop an + optimizing compiler from inlining it. */ + +/* force a (possibly extended precision) value into memory, thereby + rounding to double precision */ +double Py_force_double(double x) +{ + volatile double y = x; + return y; +} + double PyFloat_GetMax(void) { Index: Modules/cmathmodule.c =================================================================== --- Modules/cmathmodule.c (revision 67706) +++ Modules/cmathmodule.c (working copy) @@ -478,7 +478,8 @@ r.imag = l*sin(z.imag); } /* detect overflow, and set errno accordingly */ - if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag)) + if (Py_IS_INFINITY(Py_FORCE_DOUBLE(r.real)) || + Py_IS_INFINITY(Py_FORCE_DOUBLE(r.imag))) errno = ERANGE; else errno = 0;

AltStyle によって変換されたページ (->オリジナル) /