bpo-46656: Remove Py_NO_NAN macro by vstinner · Pull Request #31160 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpo-46656: Remove Py_NO_NAN macro
Building Python now requires support for floating point Not-a-Number
(NaN): remove the Py_NO_NAN macro.
  • Loading branch information
vstinner committed Feb 24, 2022
commit d18ddffbea80f7cfeb35f871ec7fbc344925dd38
8 changes: 5 additions & 3 deletions Doc/whatsnew/3.11.rst
4 changes: 1 addition & 3 deletions Include/floatobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
#define PyFloat_Check(op) PyObject_TypeCheck(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)
#endif
#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)

#define Py_RETURN_INF(sign) \
do { \
Expand Down
7 changes: 2 additions & 5 deletions Include/pymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@
# define Py_HUGE_VAL HUGE_VAL
#endif

/* Py_NAN
* A value that evaluates to a quiet Not-a-Number (NaN).
* Define Py_NO_NAN in pyconfig.h if your platform doesn't support NaNs.
*/
#if !defined(Py_NAN) && !defined(Py_NO_NAN)
// Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN).
#if !defined(Py_NAN)
# if _Py__has_builtin(__builtin_nan)
// Built-in implementation of the ISO C99 function nan(): quiet NaN.
# define Py_NAN (__builtin_nan(""))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
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
support Not-a-Number (NaN), the ``Py_NO_NAN`` macro can be defined in the
``pyconfig.h`` file. Patch by Victor Stinner.
constant, or the ``__builtin_nan()`` built-in function.
Patch by Victor Stinner.
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions Modules/cmathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ c_infj(void)
return r;
}

#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
#if _PY_SHORT_FLOAT_REPR == 1

static double
m_nan(void)
Expand Down Expand Up @@ -1282,7 +1282,7 @@ cmath_exec(PyObject *mod)
PyComplex_FromCComplex(c_infj())) < 0) {
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) {
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ m_inf(void)
/* Constant nan value, generated in the same way as float('nan'). */
/* 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
m_nan(void)
Expand Down Expand Up @@ -3838,7 +3838,7 @@ math_exec(PyObject *module)
if (PyModule_AddObject(module, "inf", PyFloat_FromDouble(m_inf())) < 0) {
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) {
return -1;
}
Expand Down
8 changes: 0 additions & 8 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2486,15 +2486,7 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
}
else {
/* NaN */
#ifdef 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
if (f == 0) {
Expand Down
2 changes: 0 additions & 2 deletions Python/pystrtod.c