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

@ -79,7 +79,7 @@ append_repr(_PyUnicodeWriter *writer, PyObject *obj)
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))
{
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,
and don't let adding the compensation convert
an infinite or overflowed sum to a NaN. */
if (c && Py_IS_FINITE(c)) {
if (c && isfinite(c)) {
f_result += c;
}
return PyFloat_FromDouble(f_result);
@ -2672,7 +2672,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
continue;
}
}
if (c && Py_IS_FINITE(c)) {
if (c && isfinite(c)) {
f_result += c;
}
result = PyFloat_FromDouble(f_result);

View file

@ -90,8 +90,8 @@ _Py_HashDouble(PyObject *inst, double v)
double m;
Py_uhash_t x, y;
if (!Py_IS_FINITE(v)) {
if (Py_IS_INFINITY(v))
if (!isfinite(v)) {
if (isinf(v))
return v > 0 ? _PyHASH_INF : -_PyHASH_INF;
else
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' */
bufsize = 5;
else {
@ -860,10 +860,10 @@ char * PyOS_double_to_string(double val,
}
/* Handle nan and inf. */
if (Py_IS_NAN(val)) {
if (isnan(val)) {
strcpy(buf, "nan");
t = Py_DTST_NAN;
} else if (Py_IS_INFINITY(val)) {
} else if (isinf(val)) {
if (copysign(1., val) == 1.)
strcpy(buf, "inf");
else

View file

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