gh-119613: Use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE (#119619)

This commit is contained in:
Sergey B Kirpichev 2024-05-29 10:51:19 +03:00 committed by GitHub
parent 86d1a1aa88
commit cd11ff12ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 140 additions and 142 deletions

View File

@ -2425,12 +2425,12 @@ PyDecType_FromFloatExact(PyTypeObject *type, PyObject *v,
} }
sign = (copysign(1.0, x) == 1.0) ? 0 : 1; sign = (copysign(1.0, x) == 1.0) ? 0 : 1;
if (Py_IS_NAN(x) || Py_IS_INFINITY(x)) { if (isnan(x) || isinf(x)) {
dec = PyDecType_New(type); dec = PyDecType_New(type);
if (dec == NULL) { if (dec == NULL) {
return NULL; return NULL;
} }
if (Py_IS_NAN(x)) { if (isnan(x)) {
/* decimal.py calls repr(float(+-nan)), /* decimal.py calls repr(float(+-nan)),
* which always gives a positive result. */ * which always gives a positive result. */
mpd_setspecial(MPD(dec), MPD_POS, MPD_NAN); mpd_setspecial(MPD(dec), MPD_POS, MPD_NAN);

View File

@ -1326,7 +1326,7 @@ encoder_encode_float(PyEncoderObject *s, PyObject *obj)
{ {
/* Return the JSON representation of a PyFloat. */ /* Return the JSON representation of a PyFloat. */
double i = PyFloat_AS_DOUBLE(obj); double i = PyFloat_AS_DOUBLE(obj);
if (!Py_IS_FINITE(i)) { if (!isfinite(i)) {
if (!s->allow_nan) { if (!s->allow_nan) {
PyErr_Format( PyErr_Format(
PyExc_ValueError, PyExc_ValueError,

View File

@ -117,7 +117,7 @@ enum special_types {
static enum special_types static enum special_types
special_type(double d) special_type(double d)
{ {
if (Py_IS_FINITE(d)) { if (isfinite(d)) {
if (d != 0) { if (d != 0) {
if (copysign(1., d) == 1.) if (copysign(1., d) == 1.)
return ST_POS; return ST_POS;
@ -131,7 +131,7 @@ special_type(double d)
return ST_NZERO; return ST_NZERO;
} }
} }
if (Py_IS_NAN(d)) if (isnan(d))
return ST_NAN; return ST_NAN;
if (copysign(1., d) == 1.) if (copysign(1., d) == 1.)
return ST_PINF; return ST_PINF;
@ -139,11 +139,11 @@ special_type(double d)
return ST_NINF; return ST_NINF;
} }
#define SPECIAL_VALUE(z, table) \ #define SPECIAL_VALUE(z, table) \
if (!Py_IS_FINITE((z).real) || !Py_IS_FINITE((z).imag)) { \ if (!isfinite((z).real) || !isfinite((z).imag)) { \
errno = 0; \ errno = 0; \
return table[special_type((z).real)] \ return table[special_type((z).real)] \
[special_type((z).imag)]; \ [special_type((z).imag)]; \
} }
#define P Py_MATH_PI #define P Py_MATH_PI
@ -329,10 +329,10 @@ cmath_atan_impl(PyObject *module, Py_complex z)
static double static double
c_atan2(Py_complex z) c_atan2(Py_complex z)
{ {
if (Py_IS_NAN(z.real) || Py_IS_NAN(z.imag)) if (isnan(z.real) || isnan(z.imag))
return Py_NAN; return Py_NAN;
if (Py_IS_INFINITY(z.imag)) { if (isinf(z.imag)) {
if (Py_IS_INFINITY(z.real)) { if (isinf(z.real)) {
if (copysign(1., z.real) == 1.) if (copysign(1., z.real) == 1.)
/* atan2(+-inf, +inf) == +-pi/4 */ /* atan2(+-inf, +inf) == +-pi/4 */
return copysign(0.25*Py_MATH_PI, z.imag); return copysign(0.25*Py_MATH_PI, z.imag);
@ -343,7 +343,7 @@ c_atan2(Py_complex z)
/* atan2(+-inf, x) == +-pi/2 for finite x */ /* atan2(+-inf, x) == +-pi/2 for finite x */
return copysign(0.5*Py_MATH_PI, z.imag); return copysign(0.5*Py_MATH_PI, z.imag);
} }
if (Py_IS_INFINITY(z.real) || z.imag == 0.) { if (isinf(z.real) || z.imag == 0.) {
if (copysign(1., z.real) == 1.) if (copysign(1., z.real) == 1.)
/* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */ /* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
return copysign(0., z.imag); return copysign(0., z.imag);
@ -448,8 +448,8 @@ cmath_cosh_impl(PyObject *module, Py_complex z)
double x_minus_one; double x_minus_one;
/* special treatment for cosh(+/-inf + iy) if y is not a NaN */ /* special treatment for cosh(+/-inf + iy) if y is not a NaN */
if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) { if (!isfinite(z.real) || !isfinite(z.imag)) {
if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag) && if (isinf(z.real) && isfinite(z.imag) &&
(z.imag != 0.)) { (z.imag != 0.)) {
if (z.real > 0) { if (z.real > 0) {
r.real = copysign(INF, cos(z.imag)); r.real = copysign(INF, cos(z.imag));
@ -466,7 +466,7 @@ cmath_cosh_impl(PyObject *module, Py_complex z)
} }
/* need to set errno = EDOM if y is +/- infinity and x is not /* need to set errno = EDOM if y is +/- infinity and x is not
a NaN */ a NaN */
if (Py_IS_INFINITY(z.imag) && !Py_IS_NAN(z.real)) if (isinf(z.imag) && !isnan(z.real))
errno = EDOM; errno = EDOM;
else else
errno = 0; errno = 0;
@ -484,7 +484,7 @@ cmath_cosh_impl(PyObject *module, Py_complex z)
r.imag = sin(z.imag) * sinh(z.real); r.imag = sin(z.imag) * sinh(z.real);
} }
/* detect overflow, and set errno accordingly */ /* detect overflow, and set errno accordingly */
if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag)) if (isinf(r.real) || isinf(r.imag))
errno = ERANGE; errno = ERANGE;
else else
errno = 0; errno = 0;
@ -509,8 +509,8 @@ cmath_exp_impl(PyObject *module, Py_complex z)
Py_complex r; Py_complex r;
double l; double l;
if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) { if (!isfinite(z.real) || !isfinite(z.imag)) {
if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag) if (isinf(z.real) && isfinite(z.imag)
&& (z.imag != 0.)) { && (z.imag != 0.)) {
if (z.real > 0) { if (z.real > 0) {
r.real = copysign(INF, cos(z.imag)); r.real = copysign(INF, cos(z.imag));
@ -527,9 +527,9 @@ cmath_exp_impl(PyObject *module, Py_complex z)
} }
/* need to set errno = EDOM if y is +/- infinity and x is not /* need to set errno = EDOM if y is +/- infinity and x is not
a NaN and not -infinity */ a NaN and not -infinity */
if (Py_IS_INFINITY(z.imag) && if (isinf(z.imag) &&
(Py_IS_FINITE(z.real) || (isfinite(z.real) ||
(Py_IS_INFINITY(z.real) && z.real > 0))) (isinf(z.real) && z.real > 0)))
errno = EDOM; errno = EDOM;
else else
errno = 0; errno = 0;
@ -546,7 +546,7 @@ cmath_exp_impl(PyObject *module, Py_complex z)
r.imag = l*sin(z.imag); r.imag = l*sin(z.imag);
} }
/* detect overflow, and set errno accordingly */ /* detect overflow, and set errno accordingly */
if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag)) if (isinf(r.real) || isinf(r.imag))
errno = ERANGE; errno = ERANGE;
else else
errno = 0; errno = 0;
@ -686,8 +686,8 @@ cmath_sinh_impl(PyObject *module, Py_complex z)
/* special treatment for sinh(+/-inf + iy) if y is finite and /* special treatment for sinh(+/-inf + iy) if y is finite and
nonzero */ nonzero */
if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) { if (!isfinite(z.real) || !isfinite(z.imag)) {
if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag) if (isinf(z.real) && isfinite(z.imag)
&& (z.imag != 0.)) { && (z.imag != 0.)) {
if (z.real > 0) { if (z.real > 0) {
r.real = copysign(INF, cos(z.imag)); r.real = copysign(INF, cos(z.imag));
@ -704,7 +704,7 @@ cmath_sinh_impl(PyObject *module, Py_complex z)
} }
/* need to set errno = EDOM if y is +/- infinity and x is not /* need to set errno = EDOM if y is +/- infinity and x is not
a NaN */ a NaN */
if (Py_IS_INFINITY(z.imag) && !Py_IS_NAN(z.real)) if (isinf(z.imag) && !isnan(z.real))
errno = EDOM; errno = EDOM;
else else
errno = 0; errno = 0;
@ -720,7 +720,7 @@ cmath_sinh_impl(PyObject *module, Py_complex z)
r.imag = sin(z.imag) * cosh(z.real); r.imag = sin(z.imag) * cosh(z.real);
} }
/* detect overflow, and set errno accordingly */ /* detect overflow, and set errno accordingly */
if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag)) if (isinf(r.real) || isinf(r.imag))
errno = ERANGE; errno = ERANGE;
else else
errno = 0; errno = 0;
@ -856,8 +856,8 @@ cmath_tanh_impl(PyObject *module, Py_complex z)
/* special treatment for tanh(+/-inf + iy) if y is finite and /* special treatment for tanh(+/-inf + iy) if y is finite and
nonzero */ nonzero */
if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) { if (!isfinite(z.real) || !isfinite(z.imag)) {
if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag) if (isinf(z.real) && isfinite(z.imag)
&& (z.imag != 0.)) { && (z.imag != 0.)) {
if (z.real > 0) { if (z.real > 0) {
r.real = 1.0; r.real = 1.0;
@ -876,7 +876,7 @@ cmath_tanh_impl(PyObject *module, Py_complex z)
} }
/* need to set errno = EDOM if z.imag is +/-infinity and /* need to set errno = EDOM if z.imag is +/-infinity and
z.real is finite */ z.real is finite */
if (Py_IS_INFINITY(z.imag) && Py_IS_FINITE(z.real)) if (isinf(z.imag) && isfinite(z.real))
errno = EDOM; errno = EDOM;
else else
errno = 0; errno = 0;
@ -1030,11 +1030,11 @@ cmath_rect_impl(PyObject *module, double r, double phi)
errno = 0; errno = 0;
/* deal with special values */ /* deal with special values */
if (!Py_IS_FINITE(r) || !Py_IS_FINITE(phi)) { if (!isfinite(r) || !isfinite(phi)) {
/* if r is +/-infinity and phi is finite but nonzero then /* if r is +/-infinity and phi is finite but nonzero then
result is (+-INF +-INF i), but we need to compute cos(phi) result is (+-INF +-INF i), but we need to compute cos(phi)
and sin(phi) to figure out the signs. */ and sin(phi) to figure out the signs. */
if (Py_IS_INFINITY(r) && (Py_IS_FINITE(phi) if (isinf(r) && (isfinite(phi)
&& (phi != 0.))) { && (phi != 0.))) {
if (r > 0) { if (r > 0) {
z.real = copysign(INF, cos(phi)); z.real = copysign(INF, cos(phi));
@ -1051,7 +1051,7 @@ cmath_rect_impl(PyObject *module, double r, double phi)
} }
/* need to set errno = EDOM if r is a nonzero number and phi /* need to set errno = EDOM if r is a nonzero number and phi
is infinite */ is infinite */
if (r != 0. && !Py_IS_NAN(r) && Py_IS_INFINITY(phi)) if (r != 0. && !isnan(r) && isinf(phi))
errno = EDOM; errno = EDOM;
else else
errno = 0; errno = 0;
@ -1085,7 +1085,7 @@ static PyObject *
cmath_isfinite_impl(PyObject *module, Py_complex z) cmath_isfinite_impl(PyObject *module, Py_complex z)
/*[clinic end generated code: output=ac76611e2c774a36 input=848e7ee701895815]*/ /*[clinic end generated code: output=ac76611e2c774a36 input=848e7ee701895815]*/
{ {
return PyBool_FromLong(Py_IS_FINITE(z.real) && Py_IS_FINITE(z.imag)); return PyBool_FromLong(isfinite(z.real) && isfinite(z.imag));
} }
/*[clinic input] /*[clinic input]
@ -1098,7 +1098,7 @@ static PyObject *
cmath_isnan_impl(PyObject *module, Py_complex z) cmath_isnan_impl(PyObject *module, Py_complex z)
/*[clinic end generated code: output=e7abf6e0b28beab7 input=71799f5d284c9baf]*/ /*[clinic end generated code: output=e7abf6e0b28beab7 input=71799f5d284c9baf]*/
{ {
return PyBool_FromLong(Py_IS_NAN(z.real) || Py_IS_NAN(z.imag)); return PyBool_FromLong(isnan(z.real) || isnan(z.imag));
} }
/*[clinic input] /*[clinic input]
@ -1111,8 +1111,7 @@ static PyObject *
cmath_isinf_impl(PyObject *module, Py_complex z) cmath_isinf_impl(PyObject *module, Py_complex z)
/*[clinic end generated code: output=502a75a79c773469 input=363df155c7181329]*/ /*[clinic end generated code: output=502a75a79c773469 input=363df155c7181329]*/
{ {
return PyBool_FromLong(Py_IS_INFINITY(z.real) || return PyBool_FromLong(isinf(z.real) || isinf(z.imag));
Py_IS_INFINITY(z.imag));
} }
/*[clinic input] /*[clinic input]
@ -1167,8 +1166,7 @@ cmath_isclose_impl(PyObject *module, Py_complex a, Py_complex b,
above. above.
*/ */
if (Py_IS_INFINITY(a.real) || Py_IS_INFINITY(a.imag) || if (isinf(a.real) || isinf(a.imag) || isinf(b.real) || isinf(b.imag)) {
Py_IS_INFINITY(b.real) || Py_IS_INFINITY(b.imag)) {
return 0; return 0;
} }

View File

@ -237,7 +237,7 @@ m_sinpi(double x)
double y, r; double y, r;
int n; int n;
/* this function should only ever be called for finite arguments */ /* this function should only ever be called for finite arguments */
assert(Py_IS_FINITE(x)); assert(isfinite(x));
y = fmod(fabs(x), 2.0); y = fmod(fabs(x), 2.0);
n = (int)round(2.0*y); n = (int)round(2.0*y);
assert(0 <= n && n <= 4); assert(0 <= n && n <= 4);
@ -396,8 +396,8 @@ m_tgamma(double x)
double absx, r, y, z, sqrtpow; double absx, r, y, z, sqrtpow;
/* special cases */ /* special cases */
if (!Py_IS_FINITE(x)) { if (!isfinite(x)) {
if (Py_IS_NAN(x) || x > 0.0) if (isnan(x) || x > 0.0)
return x; /* tgamma(nan) = nan, tgamma(inf) = inf */ return x; /* tgamma(nan) = nan, tgamma(inf) = inf */
else { else {
errno = EDOM; errno = EDOM;
@ -424,7 +424,7 @@ m_tgamma(double x)
/* tiny arguments: tgamma(x) ~ 1/x for x near 0 */ /* tiny arguments: tgamma(x) ~ 1/x for x near 0 */
if (absx < 1e-20) { if (absx < 1e-20) {
r = 1.0/x; r = 1.0/x;
if (Py_IS_INFINITY(r)) if (isinf(r))
errno = ERANGE; errno = ERANGE;
return r; return r;
} }
@ -481,7 +481,7 @@ m_tgamma(double x)
r *= sqrtpow; r *= sqrtpow;
} }
} }
if (Py_IS_INFINITY(r)) if (isinf(r))
errno = ERANGE; errno = ERANGE;
return r; return r;
} }
@ -498,8 +498,8 @@ m_lgamma(double x)
double absx; double absx;
/* special cases */ /* special cases */
if (!Py_IS_FINITE(x)) { if (!isfinite(x)) {
if (Py_IS_NAN(x)) if (isnan(x))
return x; /* lgamma(nan) = nan */ return x; /* lgamma(nan) = nan */
else else
return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */ return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */
@ -530,7 +530,7 @@ m_lgamma(double x)
if (x < 0.0) if (x < 0.0)
/* Use reflection formula to get value for negative x. */ /* Use reflection formula to get value for negative x. */
r = logpi - log(fabs(m_sinpi(absx))) - log(absx) - r; r = logpi - log(fabs(m_sinpi(absx))) - log(absx) - r;
if (Py_IS_INFINITY(r)) if (isinf(r))
errno = ERANGE; errno = ERANGE;
return r; return r;
} }
@ -546,10 +546,10 @@ m_lgamma(double x)
static double static double
m_atan2(double y, double x) m_atan2(double y, double x)
{ {
if (Py_IS_NAN(x) || Py_IS_NAN(y)) if (isnan(x) || isnan(y))
return Py_NAN; return Py_NAN;
if (Py_IS_INFINITY(y)) { if (isinf(y)) {
if (Py_IS_INFINITY(x)) { if (isinf(x)) {
if (copysign(1., x) == 1.) if (copysign(1., x) == 1.)
/* atan2(+-inf, +inf) == +-pi/4 */ /* atan2(+-inf, +inf) == +-pi/4 */
return copysign(0.25*Py_MATH_PI, y); return copysign(0.25*Py_MATH_PI, y);
@ -560,7 +560,7 @@ m_atan2(double y, double x)
/* atan2(+-inf, x) == +-pi/2 for finite x */ /* atan2(+-inf, x) == +-pi/2 for finite x */
return copysign(0.5*Py_MATH_PI, y); return copysign(0.5*Py_MATH_PI, y);
} }
if (Py_IS_INFINITY(x) || y == 0.) { if (isinf(x) || y == 0.) {
if (copysign(1., x) == 1.) if (copysign(1., x) == 1.)
/* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */ /* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
return copysign(0., y); return copysign(0., y);
@ -580,7 +580,7 @@ static double
m_remainder(double x, double y) m_remainder(double x, double y)
{ {
/* Deal with most common case first. */ /* Deal with most common case first. */
if (Py_IS_FINITE(x) && Py_IS_FINITE(y)) { if (isfinite(x) && isfinite(y)) {
double absx, absy, c, m, r; double absx, absy, c, m, r;
if (y == 0.0) { if (y == 0.0) {
@ -653,16 +653,16 @@ m_remainder(double x, double y)
} }
/* Special values. */ /* Special values. */
if (Py_IS_NAN(x)) { if (isnan(x)) {
return x; return x;
} }
if (Py_IS_NAN(y)) { if (isnan(y)) {
return y; return y;
} }
if (Py_IS_INFINITY(x)) { if (isinf(x)) {
return Py_NAN; return Py_NAN;
} }
assert(Py_IS_INFINITY(y)); assert(isinf(y));
return x; return x;
} }
@ -677,7 +677,7 @@ m_remainder(double x, double y)
static double static double
m_log(double x) m_log(double x)
{ {
if (Py_IS_FINITE(x)) { if (isfinite(x)) {
if (x > 0.0) if (x > 0.0)
return log(x); return log(x);
errno = EDOM; errno = EDOM;
@ -686,7 +686,7 @@ m_log(double x)
else else
return Py_NAN; /* log(-ve) = nan */ return Py_NAN; /* log(-ve) = nan */
} }
else if (Py_IS_NAN(x)) else if (isnan(x))
return x; /* log(nan) = nan */ return x; /* log(nan) = nan */
else if (x > 0.0) else if (x > 0.0)
return x; /* log(inf) = inf */ return x; /* log(inf) = inf */
@ -709,8 +709,8 @@ m_log(double x)
static double static double
m_log2(double x) m_log2(double x)
{ {
if (!Py_IS_FINITE(x)) { if (!isfinite(x)) {
if (Py_IS_NAN(x)) if (isnan(x))
return x; /* log2(nan) = nan */ return x; /* log2(nan) = nan */
else if (x > 0.0) else if (x > 0.0)
return x; /* log2(+inf) = +inf */ return x; /* log2(+inf) = +inf */
@ -736,7 +736,7 @@ m_log2(double x)
static double static double
m_log10(double x) m_log10(double x)
{ {
if (Py_IS_FINITE(x)) { if (isfinite(x)) {
if (x > 0.0) if (x > 0.0)
return log10(x); return log10(x);
errno = EDOM; errno = EDOM;
@ -745,7 +745,7 @@ m_log10(double x)
else else
return Py_NAN; /* log10(-ve) = nan */ return Py_NAN; /* log10(-ve) = nan */
} }
else if (Py_IS_NAN(x)) else if (isnan(x))
return x; /* log10(nan) = nan */ return x; /* log10(nan) = nan */
else if (x > 0.0) else if (x > 0.0)
return x; /* log10(inf) = inf */ return x; /* log10(inf) = inf */
@ -966,12 +966,12 @@ math_1(PyObject *arg, double (*func) (double), int can_overflow)
return NULL; return NULL;
errno = 0; errno = 0;
r = (*func)(x); r = (*func)(x);
if (Py_IS_NAN(r) && !Py_IS_NAN(x)) { if (isnan(r) && !isnan(x)) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"math domain error"); /* invalid arg */ "math domain error"); /* invalid arg */
return NULL; return NULL;
} }
if (Py_IS_INFINITY(r) && Py_IS_FINITE(x)) { if (isinf(r) && isfinite(x)) {
if (can_overflow) if (can_overflow)
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"math range error"); /* overflow */ "math range error"); /* overflow */
@ -980,7 +980,7 @@ math_1(PyObject *arg, double (*func) (double), int can_overflow)
"math domain error"); /* singularity */ "math domain error"); /* singularity */
return NULL; return NULL;
} }
if (Py_IS_FINITE(r) && errno && is_error(r)) if (isfinite(r) && errno && is_error(r))
/* this branch unnecessary on most platforms */ /* this branch unnecessary on most platforms */
return NULL; return NULL;
@ -1049,14 +1049,14 @@ math_2(PyObject *const *args, Py_ssize_t nargs,
} }
errno = 0; errno = 0;
r = (*func)(x, y); r = (*func)(x, y);
if (Py_IS_NAN(r)) { if (isnan(r)) {
if (!Py_IS_NAN(x) && !Py_IS_NAN(y)) if (!isnan(x) && !isnan(y))
errno = EDOM; errno = EDOM;
else else
errno = 0; errno = 0;
} }
else if (Py_IS_INFINITY(r)) { else if (isinf(r)) {
if (Py_IS_FINITE(x) && Py_IS_FINITE(y)) if (isfinite(x) && isfinite(y))
errno = ERANGE; errno = ERANGE;
else else
errno = 0; errno = 0;
@ -1403,17 +1403,17 @@ math_fsum(PyObject *module, PyObject *seq)
n = i; /* ps[i:] = [x] */ n = i; /* ps[i:] = [x] */
if (x != 0.0) { if (x != 0.0) {
if (! Py_IS_FINITE(x)) { if (! isfinite(x)) {
/* a nonfinite x could arise either as /* a nonfinite x could arise either as
a result of intermediate overflow, or a result of intermediate overflow, or
as a result of a nan or inf in the as a result of a nan or inf in the
summands */ summands */
if (Py_IS_FINITE(xsave)) { if (isfinite(xsave)) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"intermediate overflow in fsum"); "intermediate overflow in fsum");
goto _fsum_error; goto _fsum_error;
} }
if (Py_IS_INFINITY(xsave)) if (isinf(xsave))
inf_sum += xsave; inf_sum += xsave;
special_sum += xsave; special_sum += xsave;
/* reset partials */ /* reset partials */
@ -1427,7 +1427,7 @@ math_fsum(PyObject *module, PyObject *seq)
} }
if (special_sum != 0.0) { if (special_sum != 0.0) {
if (Py_IS_NAN(inf_sum)) if (isnan(inf_sum))
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"-inf + inf in fsum"); "-inf + inf in fsum");
else else
@ -2108,7 +2108,7 @@ math_frexp_impl(PyObject *module, double x)
int i; int i;
/* deal with special cases directly, to sidestep platform /* deal with special cases directly, to sidestep platform
differences */ differences */
if (Py_IS_NAN(x) || Py_IS_INFINITY(x) || !x) { if (isnan(x) || isinf(x) || !x) {
i = 0; i = 0;
} }
else { else {
@ -2153,7 +2153,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
return NULL; return NULL;
} }
if (x == 0. || !Py_IS_FINITE(x)) { if (x == 0. || !isfinite(x)) {
/* NaNs, zeros and infinities are returned unchanged */ /* NaNs, zeros and infinities are returned unchanged */
r = x; r = x;
errno = 0; errno = 0;
@ -2168,7 +2168,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
} else { } else {
errno = 0; errno = 0;
r = ldexp(x, (int)exp); r = ldexp(x, (int)exp);
if (Py_IS_INFINITY(r)) if (isinf(r))
errno = ERANGE; errno = ERANGE;
} }
@ -2196,9 +2196,9 @@ math_modf_impl(PyObject *module, double x)
double y; double y;
/* some platforms don't do the right thing for NaNs and /* some platforms don't do the right thing for NaNs and
infinities, so we take care of special cases directly. */ infinities, so we take care of special cases directly. */
if (Py_IS_INFINITY(x)) if (isinf(x))
return Py_BuildValue("(dd)", copysign(0., x), x); return Py_BuildValue("(dd)", copysign(0., x), x);
else if (Py_IS_NAN(x)) else if (isnan(x))
return Py_BuildValue("(dd)", x, x); return Py_BuildValue("(dd)", x, x);
errno = 0; errno = 0;
@ -2341,19 +2341,19 @@ math_fma_impl(PyObject *module, double x, double y, double z)
double r = fma(x, y, z); double r = fma(x, y, z);
/* Fast path: if we got a finite result, we're done. */ /* Fast path: if we got a finite result, we're done. */
if (Py_IS_FINITE(r)) { if (isfinite(r)) {
return PyFloat_FromDouble(r); return PyFloat_FromDouble(r);
} }
/* Non-finite result. Raise an exception if appropriate, else return r. */ /* Non-finite result. Raise an exception if appropriate, else return r. */
if (Py_IS_NAN(r)) { if (isnan(r)) {
if (!Py_IS_NAN(x) && !Py_IS_NAN(y) && !Py_IS_NAN(z)) { if (!isnan(x) && !isnan(y) && !isnan(z)) {
/* NaN result from non-NaN inputs. */ /* NaN result from non-NaN inputs. */
PyErr_SetString(PyExc_ValueError, "invalid operation in fma"); PyErr_SetString(PyExc_ValueError, "invalid operation in fma");
return NULL; return NULL;
} }
} }
else if (Py_IS_FINITE(x) && Py_IS_FINITE(y) && Py_IS_FINITE(z)) { else if (isfinite(x) && isfinite(y) && isfinite(z)) {
/* Infinite result from finite inputs. */ /* Infinite result from finite inputs. */
PyErr_SetString(PyExc_OverflowError, "overflow in fma"); PyErr_SetString(PyExc_OverflowError, "overflow in fma");
return NULL; return NULL;
@ -2381,12 +2381,12 @@ math_fmod_impl(PyObject *module, double x, double y)
{ {
double r; double r;
/* fmod(x, +/-Inf) returns x for finite x. */ /* fmod(x, +/-Inf) returns x for finite x. */
if (Py_IS_INFINITY(y) && Py_IS_FINITE(x)) if (isinf(y) && isfinite(x))
return PyFloat_FromDouble(x); return PyFloat_FromDouble(x);
errno = 0; errno = 0;
r = fmod(x, y); r = fmod(x, y);
if (Py_IS_NAN(r)) { if (isnan(r)) {
if (!Py_IS_NAN(x) && !Py_IS_NAN(y)) if (!isnan(x) && !isnan(y))
errno = EDOM; errno = EDOM;
else else
errno = 0; errno = 0;
@ -2508,7 +2508,7 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
int max_e; int max_e;
Py_ssize_t i; Py_ssize_t i;
if (Py_IS_INFINITY(max)) { if (isinf(max)) {
return max; return max;
} }
if (found_nan) { if (found_nan) {
@ -2530,7 +2530,7 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
assert(max * scale < 1.0); assert(max * scale < 1.0);
for (i=0 ; i < n ; i++) { for (i=0 ; i < n ; i++) {
x = vec[i]; x = vec[i];
assert(Py_IS_FINITE(x) && fabs(x) <= max); assert(isfinite(x) && fabs(x) <= max);
x *= scale; // lossless scaling x *= scale; // lossless scaling
assert(fabs(x) < 1.0); assert(fabs(x) < 1.0);
pr = dl_mul(x, x); // lossless squaring pr = dl_mul(x, x); // lossless squaring
@ -2620,7 +2620,7 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
ASSIGN_DOUBLE(qx, item, error_exit); ASSIGN_DOUBLE(qx, item, error_exit);
x = fabs(px - qx); x = fabs(px - qx);
diffs[i] = x; diffs[i] = x;
found_nan |= Py_IS_NAN(x); found_nan |= isnan(x);
if (x > max) { if (x > max) {
max = x; max = x;
} }
@ -2673,7 +2673,7 @@ math_hypot(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
ASSIGN_DOUBLE(x, item, error_exit); ASSIGN_DOUBLE(x, item, error_exit);
x = fabs(x); x = fabs(x);
coordinates[i] = x; coordinates[i] = x;
found_nan |= Py_IS_NAN(x); found_nan |= isnan(x);
if (x > max) { if (x > max) {
max = x; max = x;
} }
@ -2976,14 +2976,14 @@ math_pow_impl(PyObject *module, double x, double y)
/* deal directly with IEEE specials, to cope with problems on various /* deal directly with IEEE specials, to cope with problems on various
platforms whose semantics don't exactly match C99 */ platforms whose semantics don't exactly match C99 */
r = 0.; /* silence compiler warning */ r = 0.; /* silence compiler warning */
if (!Py_IS_FINITE(x) || !Py_IS_FINITE(y)) { if (!isfinite(x) || !isfinite(y)) {
errno = 0; errno = 0;
if (Py_IS_NAN(x)) if (isnan(x))
r = y == 0. ? 1. : x; /* NaN**0 = 1 */ r = y == 0. ? 1. : x; /* NaN**0 = 1 */
else if (Py_IS_NAN(y)) else if (isnan(y))
r = x == 1. ? 1. : y; /* 1**NaN = 1 */ r = x == 1. ? 1. : y; /* 1**NaN = 1 */
else if (Py_IS_INFINITY(x)) { else if (isinf(x)) {
odd_y = Py_IS_FINITE(y) && fmod(fabs(y), 2.0) == 1.0; odd_y = isfinite(y) && fmod(fabs(y), 2.0) == 1.0;
if (y > 0.) if (y > 0.)
r = odd_y ? x : fabs(x); r = odd_y ? x : fabs(x);
else if (y == 0.) else if (y == 0.)
@ -2992,7 +2992,7 @@ math_pow_impl(PyObject *module, double x, double y)
r = odd_y ? copysign(0., x) : 0.; r = odd_y ? copysign(0., x) : 0.;
} }
else { else {
assert(Py_IS_INFINITY(y)); assert(isinf(y));
if (fabs(x) == 1.0) if (fabs(x) == 1.0)
r = 1.; r = 1.;
else if (y > 0. && fabs(x) > 1.0) else if (y > 0. && fabs(x) > 1.0)
@ -3010,8 +3010,8 @@ math_pow_impl(PyObject *module, double x, double y)
r = pow(x, y); r = pow(x, y);
/* a NaN result should arise only from (-ve)**(finite /* a NaN result should arise only from (-ve)**(finite
non-integer); in this case we want to raise ValueError. */ non-integer); in this case we want to raise ValueError. */
if (!Py_IS_FINITE(r)) { if (!isfinite(r)) {
if (Py_IS_NAN(r)) { if (isnan(r)) {
errno = EDOM; errno = EDOM;
} }
/* /*
@ -3019,7 +3019,7 @@ math_pow_impl(PyObject *module, double x, double y)
(A) (+/-0.)**negative (-> divide-by-zero) (A) (+/-0.)**negative (-> divide-by-zero)
(B) overflow of x**y with x and y finite (B) overflow of x**y with x and y finite
*/ */
else if (Py_IS_INFINITY(r)) { else if (isinf(r)) {
if (x == 0.) if (x == 0.)
errno = EDOM; errno = EDOM;
else else
@ -3085,7 +3085,7 @@ static PyObject *
math_isfinite_impl(PyObject *module, double x) math_isfinite_impl(PyObject *module, double x)
/*[clinic end generated code: output=8ba1f396440c9901 input=46967d254812e54a]*/ /*[clinic end generated code: output=8ba1f396440c9901 input=46967d254812e54a]*/
{ {
return PyBool_FromLong((long)Py_IS_FINITE(x)); return PyBool_FromLong((long)isfinite(x));
} }
@ -3102,7 +3102,7 @@ static PyObject *
math_isnan_impl(PyObject *module, double x) math_isnan_impl(PyObject *module, double x)
/*[clinic end generated code: output=f537b4d6df878c3e input=935891e66083f46a]*/ /*[clinic end generated code: output=f537b4d6df878c3e input=935891e66083f46a]*/
{ {
return PyBool_FromLong((long)Py_IS_NAN(x)); return PyBool_FromLong((long)isnan(x));
} }
@ -3119,7 +3119,7 @@ static PyObject *
math_isinf_impl(PyObject *module, double x) math_isinf_impl(PyObject *module, double x)
/*[clinic end generated code: output=9f00cbec4de7b06b input=32630e4212cf961f]*/ /*[clinic end generated code: output=9f00cbec4de7b06b input=32630e4212cf961f]*/
{ {
return PyBool_FromLong((long)Py_IS_INFINITY(x)); return PyBool_FromLong((long)isinf(x));
} }
@ -3176,7 +3176,7 @@ math_isclose_impl(PyObject *module, double a, double b, double rel_tol,
above. above.
*/ */
if (Py_IS_INFINITY(a) || Py_IS_INFINITY(b)) { if (isinf(a) || isinf(b)) {
return 0; return 0;
} }
@ -3926,10 +3926,10 @@ math_nextafter_impl(PyObject *module, double x, double y, PyObject *steps)
Bug fixed in bos.adt.libm 7.2.2.0 by APAR IV95512. */ Bug fixed in bos.adt.libm 7.2.2.0 by APAR IV95512. */
return PyFloat_FromDouble(y); return PyFloat_FromDouble(y);
} }
if (Py_IS_NAN(x)) { if (isnan(x)) {
return PyFloat_FromDouble(x); return PyFloat_FromDouble(x);
} }
if (Py_IS_NAN(y)) { if (isnan(y)) {
return PyFloat_FromDouble(y); return PyFloat_FromDouble(y);
} }
#endif #endif
@ -3975,10 +3975,10 @@ math_nextafter_impl(PyObject *module, double x, double y, PyObject *steps)
if (usteps == 0) { if (usteps == 0) {
return PyFloat_FromDouble(x); return PyFloat_FromDouble(x);
} }
if (Py_IS_NAN(x)) { if (isnan(x)) {
return PyFloat_FromDouble(x); return PyFloat_FromDouble(x);
} }
if (Py_IS_NAN(y)) { if (isnan(y)) {
return PyFloat_FromDouble(y); return PyFloat_FromDouble(y);
} }
@ -4044,16 +4044,16 @@ static double
math_ulp_impl(PyObject *module, double x) math_ulp_impl(PyObject *module, double x)
/*[clinic end generated code: output=f5207867a9384dd4 input=31f9bfbbe373fcaa]*/ /*[clinic end generated code: output=f5207867a9384dd4 input=31f9bfbbe373fcaa]*/
{ {
if (Py_IS_NAN(x)) { if (isnan(x)) {
return x; return x;
} }
x = fabs(x); x = fabs(x);
if (Py_IS_INFINITY(x)) { if (isinf(x)) {
return x; return x;
} }
double inf = Py_INFINITY; double inf = Py_INFINITY;
double x2 = nextafter(x, inf); double x2 = nextafter(x, inf);
if (Py_IS_INFINITY(x2)) { if (isinf(x2)) {
/* special case: x is the largest positive representable float */ /* special case: x is the largest positive representable float */
x2 = nextafter(x, -inf); x2 = nextafter(x, -inf);
return x - x2; return x - x2;

View File

@ -188,16 +188,16 @@ _Py_c_abs(Py_complex z)
/* sets errno = ERANGE on overflow; otherwise errno = 0 */ /* sets errno = ERANGE on overflow; otherwise errno = 0 */
double result; double result;
if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) { if (!isfinite(z.real) || !isfinite(z.imag)) {
/* C99 rules: if either the real or the imaginary part is an /* C99 rules: if either the real or the imaginary part is an
infinity, return infinity, even if the other part is a infinity, return infinity, even if the other part is a
NaN. */ NaN. */
if (Py_IS_INFINITY(z.real)) { if (isinf(z.real)) {
result = fabs(z.real); result = fabs(z.real);
errno = 0; errno = 0;
return result; return result;
} }
if (Py_IS_INFINITY(z.imag)) { if (isinf(z.imag)) {
result = fabs(z.imag); result = fabs(z.imag);
errno = 0; errno = 0;
return result; return result;
@ -207,7 +207,7 @@ _Py_c_abs(Py_complex z)
return Py_NAN; return Py_NAN;
} }
result = hypot(z.real, z.imag); result = hypot(z.real, z.imag);
if (!Py_IS_FINITE(result)) if (!isfinite(result))
errno = ERANGE; errno = ERANGE;
else else
errno = 0; errno = 0;

View File

@ -418,7 +418,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
if (PyFloat_Check(w)) if (PyFloat_Check(w))
j = PyFloat_AS_DOUBLE(w); j = PyFloat_AS_DOUBLE(w);
else if (!Py_IS_FINITE(i)) { else if (!isfinite(i)) {
if (PyLong_Check(w)) if (PyLong_Check(w))
/* If i is an infinity, its magnitude exceeds any /* If i is an infinity, its magnitude exceeds any
* finite integer, so it doesn't matter which int we * finite integer, so it doesn't matter which int we
@ -749,13 +749,13 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
if (iw == 0) { /* v**0 is 1, even 0**0 */ if (iw == 0) { /* v**0 is 1, even 0**0 */
return PyFloat_FromDouble(1.0); return PyFloat_FromDouble(1.0);
} }
if (Py_IS_NAN(iv)) { /* nan**w = nan, unless w == 0 */ if (isnan(iv)) { /* nan**w = nan, unless w == 0 */
return PyFloat_FromDouble(iv); return PyFloat_FromDouble(iv);
} }
if (Py_IS_NAN(iw)) { /* v**nan = nan, unless v == 1; 1**nan = 1 */ if (isnan(iw)) { /* v**nan = nan, unless v == 1; 1**nan = 1 */
return PyFloat_FromDouble(iv == 1.0 ? 1.0 : iw); return PyFloat_FromDouble(iv == 1.0 ? 1.0 : iw);
} }
if (Py_IS_INFINITY(iw)) { if (isinf(iw)) {
/* v**inf is: 0.0 if abs(v) < 1; 1.0 if abs(v) == 1; inf if /* v**inf is: 0.0 if abs(v) < 1; 1.0 if abs(v) == 1; inf if
* abs(v) > 1 (including case where v infinite) * abs(v) > 1 (including case where v infinite)
* *
@ -770,7 +770,7 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
else else
return PyFloat_FromDouble(0.0); return PyFloat_FromDouble(0.0);
} }
if (Py_IS_INFINITY(iv)) { if (isinf(iv)) {
/* (+-inf)**w is: inf for w positive, 0 for w negative; in /* (+-inf)**w is: inf for w positive, 0 for w negative; in
* both cases, we need to add the appropriate sign if w is * both cases, we need to add the appropriate sign if w is
* an odd integer. * an odd integer.
@ -885,7 +885,7 @@ float_is_integer_impl(PyObject *self)
if (x == -1.0 && PyErr_Occurred()) if (x == -1.0 && PyErr_Occurred())
return NULL; return NULL;
if (!Py_IS_FINITE(x)) if (!isfinite(x))
Py_RETURN_FALSE; Py_RETURN_FALSE;
errno = 0; errno = 0;
o = (floor(x) == x) ? Py_True : Py_False; o = (floor(x) == x) ? Py_True : Py_False;
@ -1021,7 +1021,7 @@ double_round(double x, int ndigits) {
} }
y = (x*pow1)*pow2; y = (x*pow1)*pow2;
/* if y overflows, then rounded value is exactly x */ /* if y overflows, then rounded value is exactly x */
if (!Py_IS_FINITE(y)) if (!isfinite(y))
return PyFloat_FromDouble(x); return PyFloat_FromDouble(x);
} }
else { else {
@ -1041,7 +1041,7 @@ double_round(double x, int ndigits) {
z *= pow1; z *= pow1;
/* if computation resulted in overflow, raise OverflowError */ /* if computation resulted in overflow, raise OverflowError */
if (!Py_IS_FINITE(z)) { if (!isfinite(z)) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"overflow occurred during round"); "overflow occurred during round");
return NULL; return NULL;
@ -1089,7 +1089,7 @@ float___round___impl(PyObject *self, PyObject *o_ndigits)
return NULL; return NULL;
/* nans and infinities round to themselves */ /* nans and infinities round to themselves */
if (!Py_IS_FINITE(x)) if (!isfinite(x))
return PyFloat_FromDouble(x); return PyFloat_FromDouble(x);
/* Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x /* Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x
@ -1237,7 +1237,7 @@ float_hex_impl(PyObject *self)
CONVERT_TO_DOUBLE(self, x); CONVERT_TO_DOUBLE(self, x);
if (Py_IS_NAN(x) || Py_IS_INFINITY(x)) if (isnan(x) || isinf(x))
return float_repr((PyFloatObject *)self); return float_repr((PyFloatObject *)self);
if (x == 0.0) { if (x == 0.0) {
@ -1570,12 +1570,12 @@ float_as_integer_ratio_impl(PyObject *self)
CONVERT_TO_DOUBLE(self, self_double); CONVERT_TO_DOUBLE(self, self_double);
if (Py_IS_INFINITY(self_double)) { if (isinf(self_double)) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"cannot convert Infinity to integer ratio"); "cannot convert Infinity to integer ratio");
return NULL; return NULL;
} }
if (Py_IS_NAN(self_double)) { if (isnan(self_double)) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"cannot convert NaN to integer ratio"); "cannot convert NaN to integer ratio");
return NULL; return NULL;
@ -2060,12 +2060,12 @@ PyFloat_Pack2(double x, char *data, int le)
e = 0; e = 0;
bits = 0; bits = 0;
} }
else if (Py_IS_INFINITY(x)) { else if (isinf(x)) {
sign = (x < 0.0); sign = (x < 0.0);
e = 0x1f; e = 0x1f;
bits = 0; bits = 0;
} }
else if (Py_IS_NAN(x)) { else if (isnan(x)) {
/* There are 2046 distinct half-precision NaNs (1022 signaling and /* There are 2046 distinct half-precision NaNs (1022 signaling and
1024 quiet), but there are only two quiet NaNs that don't arise by 1024 quiet), but there are only two quiet NaNs that don't arise by
quieting a signaling NaN; we get those by setting the topmost bit quieting a signaling NaN; we get those by setting the topmost bit
@ -2234,7 +2234,7 @@ PyFloat_Pack4(double x, char *data, int le)
float y = (float)x; float y = (float)x;
int i, incr = 1; int i, incr = 1;
if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x)) if (isinf(y) && !isinf(x))
goto Overflow; goto Overflow;
unsigned char s[sizeof(float)]; unsigned char s[sizeof(float)];

View File

@ -401,12 +401,12 @@ PyLong_FromDouble(double dval)
double frac; double frac;
int i, ndig, expo, neg; int i, ndig, expo, neg;
neg = 0; neg = 0;
if (Py_IS_INFINITY(dval)) { if (isinf(dval)) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"cannot convert float infinity to integer"); "cannot convert float infinity to integer");
return NULL; return NULL;
} }
if (Py_IS_NAN(dval)) { if (isnan(dval)) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"cannot convert float NaN to integer"); "cannot convert float NaN to integer");
return NULL; return NULL;

View File

@ -79,7 +79,7 @@ append_repr(_PyUnicodeWriter *writer, PyObject *obj)
return -1; return -1;
} }
if ((PyFloat_CheckExact(obj) && Py_IS_INFINITY(PyFloat_AS_DOUBLE(obj))) || if ((PyFloat_CheckExact(obj) && isinf(PyFloat_AS_DOUBLE(obj))) ||
PyComplex_CheckExact(obj)) PyComplex_CheckExact(obj))
{ {
PyInterpreterState *interp = _PyInterpreterState_GET(); PyInterpreterState *interp = _PyInterpreterState_GET();

View File

@ -2640,7 +2640,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
/* Avoid losing the sign on a negative result, /* Avoid losing the sign on a negative result,
and don't let adding the compensation convert and don't let adding the compensation convert
an infinite or overflowed sum to a NaN. */ an infinite or overflowed sum to a NaN. */
if (c && Py_IS_FINITE(c)) { if (c && isfinite(c)) {
f_result += c; f_result += c;
} }
return PyFloat_FromDouble(f_result); return PyFloat_FromDouble(f_result);
@ -2672,7 +2672,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
continue; continue;
} }
} }
if (c && Py_IS_FINITE(c)) { if (c && isfinite(c)) {
f_result += c; f_result += c;
} }
result = PyFloat_FromDouble(f_result); result = PyFloat_FromDouble(f_result);

View File

@ -90,8 +90,8 @@ _Py_HashDouble(PyObject *inst, double v)
double m; double m;
Py_uhash_t x, y; Py_uhash_t x, y;
if (!Py_IS_FINITE(v)) { if (!isfinite(v)) {
if (Py_IS_INFINITY(v)) if (isinf(v))
return v > 0 ? _PyHASH_INF : -_PyHASH_INF; return v > 0 ? _PyHASH_INF : -_PyHASH_INF;
else else
return PyObject_GenericHash(inst); return PyObject_GenericHash(inst);

View File

@ -842,7 +842,7 @@ char * PyOS_double_to_string(double val,
*/ */
if (Py_IS_NAN(val) || Py_IS_INFINITY(val)) if (isnan(val) || isinf(val))
/* 3 for 'inf'/'nan', 1 for sign, 1 for '\0' */ /* 3 for 'inf'/'nan', 1 for sign, 1 for '\0' */
bufsize = 5; bufsize = 5;
else { else {
@ -860,10 +860,10 @@ char * PyOS_double_to_string(double val,
} }
/* Handle nan and inf. */ /* Handle nan and inf. */
if (Py_IS_NAN(val)) { if (isnan(val)) {
strcpy(buf, "nan"); strcpy(buf, "nan");
t = Py_DTST_NAN; t = Py_DTST_NAN;
} else if (Py_IS_INFINITY(val)) { } else if (isinf(val)) {
if (copysign(1., val) == 1.) if (copysign(1., val) == 1.)
strcpy(buf, "inf"); strcpy(buf, "inf");
else else

View File

@ -375,7 +375,7 @@ pytime_object_to_denominator(PyObject *obj, time_t *sec, long *numerator,
if (PyFloat_Check(obj)) { if (PyFloat_Check(obj)) {
double d = PyFloat_AsDouble(obj); double d = PyFloat_AsDouble(obj);
if (Py_IS_NAN(d)) { if (isnan(d)) {
*numerator = 0; *numerator = 0;
PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)"); PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)");
return -1; return -1;
@ -403,7 +403,7 @@ _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t round)
volatile double d; volatile double d;
d = PyFloat_AsDouble(obj); d = PyFloat_AsDouble(obj);
if (Py_IS_NAN(d)) { if (isnan(d)) {
PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)"); PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)");
return -1; return -1;
} }
@ -590,7 +590,7 @@ pytime_from_object(PyTime_t *tp, PyObject *obj, _PyTime_round_t round,
if (PyFloat_Check(obj)) { if (PyFloat_Check(obj)) {
double d; double d;
d = PyFloat_AsDouble(obj); d = PyFloat_AsDouble(obj);
if (Py_IS_NAN(d)) { if (isnan(d)) {
PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)"); PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)");
return -1; return -1;
} }