mirror of https://github.com/python/cpython
bpo-46656: Remove Py_NO_NAN macro (GH-31160)
Building Python now requires support for floating point Not-a-Number (NaN): remove the Py_NO_NAN macro.
This commit is contained in:
parent
5f8b5e2f21
commit
1b2611eb02
|
@ -633,11 +633,13 @@ Build Changes
|
||||||
(Contributed by Victor Stinner in :issue:`45440`.)
|
(Contributed by Victor Stinner in :issue:`45440`.)
|
||||||
|
|
||||||
* Building Python now requires a C99 ``<math.h>`` header file providing
|
* Building Python now requires a C99 ``<math.h>`` header file providing
|
||||||
a ``NAN`` constant, or the ``__builtin_nan()`` built-in function. If a
|
a ``NAN`` constant, or the ``__builtin_nan()`` built-in function.
|
||||||
platform does not support Not-a-Number (NaN), the ``Py_NO_NAN`` macro can be
|
|
||||||
defined in the ``pyconfig.h`` file.
|
|
||||||
(Contributed by Victor Stinner in :issue:`46640`.)
|
(Contributed by Victor Stinner in :issue:`46640`.)
|
||||||
|
|
||||||
|
* Building Python now requires support for floating point Not-a-Number (NaN):
|
||||||
|
remove the ``Py_NO_NAN`` macro.
|
||||||
|
(Contributed by Victor Stinner in :issue:`46656`.)
|
||||||
|
|
||||||
* Freelists for object structs can now be disabled. A new :program:`configure`
|
* Freelists for object structs can now be disabled. A new :program:`configure`
|
||||||
option :option:`!--without-freelists` can be used to disable all freelists
|
option :option:`!--without-freelists` can be used to disable all freelists
|
||||||
except empty tuple singleton.
|
except empty tuple singleton.
|
||||||
|
|
|
@ -16,9 +16,7 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
|
||||||
#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
|
#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
|
||||||
#define PyFloat_CheckExact(op) Py_IS_TYPE(op, &PyFloat_Type)
|
#define PyFloat_CheckExact(op) Py_IS_TYPE(op, &PyFloat_Type)
|
||||||
|
|
||||||
#ifdef Py_NAN
|
#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
|
||||||
# define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define Py_RETURN_INF(sign) \
|
#define Py_RETURN_INF(sign) \
|
||||||
do { \
|
do { \
|
||||||
|
|
|
@ -50,11 +50,8 @@
|
||||||
# define Py_HUGE_VAL HUGE_VAL
|
# define Py_HUGE_VAL HUGE_VAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Py_NAN
|
// Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN).
|
||||||
* A value that evaluates to a quiet Not-a-Number (NaN).
|
#if !defined(Py_NAN)
|
||||||
* Define Py_NO_NAN in pyconfig.h if your platform doesn't support NaNs.
|
|
||||||
*/
|
|
||||||
#if !defined(Py_NAN) && !defined(Py_NO_NAN)
|
|
||||||
# if _Py__has_builtin(__builtin_nan)
|
# if _Py__has_builtin(__builtin_nan)
|
||||||
// Built-in implementation of the ISO C99 function nan(): quiet NaN.
|
// Built-in implementation of the ISO C99 function nan(): quiet NaN.
|
||||||
# define Py_NAN (__builtin_nan(""))
|
# define Py_NAN (__builtin_nan(""))
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
Building Python now requires a C99 ``<math.h>`` header file providing a ``NAN``
|
Building Python now requires a C99 ``<math.h>`` header file providing a ``NAN``
|
||||||
constant, or the ``__builtin_nan()`` built-in function. If a platform does not
|
constant, or the ``__builtin_nan()`` built-in function.
|
||||||
support Not-a-Number (NaN), the ``Py_NO_NAN`` macro can be defined in the
|
Patch by Victor Stinner.
|
||||||
``pyconfig.h`` file. Patch by Victor Stinner.
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Building Python now requires support for floating point Not-a-Number (NaN):
|
||||||
|
remove the ``Py_NO_NAN`` macro. Patch by by Victor Stinner.
|
|
@ -113,7 +113,7 @@ c_infj(void)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
|
#if _PY_SHORT_FLOAT_REPR == 1
|
||||||
|
|
||||||
static double
|
static double
|
||||||
m_nan(void)
|
m_nan(void)
|
||||||
|
@ -1282,7 +1282,7 @@ cmath_exec(PyObject *mod)
|
||||||
PyComplex_FromCComplex(c_infj())) < 0) {
|
PyComplex_FromCComplex(c_infj())) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
|
#if _PY_SHORT_FLOAT_REPR == 1
|
||||||
if (PyModule_AddObject(mod, "nan", PyFloat_FromDouble(m_nan())) < 0) {
|
if (PyModule_AddObject(mod, "nan", PyFloat_FromDouble(m_nan())) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,7 @@ m_inf(void)
|
||||||
/* Constant nan value, generated in the same way as float('nan'). */
|
/* Constant nan value, generated in the same way as float('nan'). */
|
||||||
/* We don't currently assume that Py_NAN is defined everywhere. */
|
/* We don't currently assume that Py_NAN is defined everywhere. */
|
||||||
|
|
||||||
#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
|
#if _PY_SHORT_FLOAT_REPR == 1
|
||||||
|
|
||||||
static double
|
static double
|
||||||
m_nan(void)
|
m_nan(void)
|
||||||
|
@ -3838,7 +3838,7 @@ math_exec(PyObject *module)
|
||||||
if (PyModule_AddObject(module, "inf", PyFloat_FromDouble(m_inf())) < 0) {
|
if (PyModule_AddObject(module, "inf", PyFloat_FromDouble(m_inf())) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
|
#if _PY_SHORT_FLOAT_REPR == 1
|
||||||
if (PyModule_AddObject(module, "nan", PyFloat_FromDouble(m_nan())) < 0) {
|
if (PyModule_AddObject(module, "nan", PyFloat_FromDouble(m_nan())) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2486,15 +2486,7 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* NaN */
|
/* NaN */
|
||||||
#ifdef Py_NAN
|
|
||||||
return sign ? -Py_NAN : Py_NAN;
|
return sign ? -Py_NAN : Py_NAN;
|
||||||
#else
|
|
||||||
PyErr_SetString(
|
|
||||||
PyExc_ValueError,
|
|
||||||
"can't unpack IEEE 754 NaN "
|
|
||||||
"on platform that does not support NaNs");
|
|
||||||
return -1;
|
|
||||||
#endif // !defined(Py_NAN)
|
|
||||||
}
|
}
|
||||||
#else // _PY_SHORT_FLOAT_REPR == 1
|
#else // _PY_SHORT_FLOAT_REPR == 1
|
||||||
if (f == 0) {
|
if (f == 0) {
|
||||||
|
|
|
@ -82,12 +82,10 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
|
||||||
s += 5;
|
s += 5;
|
||||||
retval = negate ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
retval = negate ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
||||||
}
|
}
|
||||||
#ifdef Py_NAN
|
|
||||||
else if (case_insensitive_match(s, "nan")) {
|
else if (case_insensitive_match(s, "nan")) {
|
||||||
s += 3;
|
s += 3;
|
||||||
retval = negate ? -Py_NAN : Py_NAN;
|
retval = negate ? -Py_NAN : Py_NAN;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
else {
|
else {
|
||||||
s = p;
|
s = p;
|
||||||
retval = -1.0;
|
retval = -1.0;
|
||||||
|
|
Loading…
Reference in New Issue