Skip to content

Commit c8946ad

Browse files
vstinnerasvetlov
authored andcommitted
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.
1 parent 919acfe commit c8946ad

File tree

9 files changed

+16
-28
lines changed

9 files changed

+16
-28
lines changed

Diff for: Doc/whatsnew/3.11.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,13 @@ Build Changes
633633
(Contributed by Victor Stinner in :issue:`45440`.)
634634

635635
* Building Python now requires a C99 ``<math.h>`` header file providing
636-
a ``NAN`` constant, or the ``__builtin_nan()`` built-in function. If a
637-
platform does not support Not-a-Number (NaN), the ``Py_NO_NAN`` macro can be
638-
defined in the ``pyconfig.h`` file.
636+
a ``NAN`` constant, or the ``__builtin_nan()`` built-in function.
639637
(Contributed by Victor Stinner in :issue:`46640`.)
640638

639+
* Building Python now requires support for floating point Not-a-Number (NaN):
640+
remove the ``Py_NO_NAN`` macro.
641+
(Contributed by Victor Stinner in :issue:`46656`.)
642+
641643
* Freelists for object structs can now be disabled. A new :program:`configure`
642644
option :option:`!--without-freelists` can be used to disable all freelists
643645
except empty tuple singleton.

Diff for: Include/floatobject.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
1616
#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
1717
#define PyFloat_CheckExact(op) Py_IS_TYPE(op, &PyFloat_Type)
1818

19-
#ifdef Py_NAN
20-
# define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
21-
#endif
19+
#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
2220

2321
#define Py_RETURN_INF(sign) \
2422
do { \

Diff for: Include/pymath.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@
5050
# define Py_HUGE_VAL HUGE_VAL
5151
#endif
5252

53-
/* Py_NAN
54-
* A value that evaluates to a quiet Not-a-Number (NaN).
55-
* Define Py_NO_NAN in pyconfig.h if your platform doesn't support NaNs.
56-
*/
57-
#if !defined(Py_NAN) && !defined(Py_NO_NAN)
53+
// Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN).
54+
#if !defined(Py_NAN)
5855
# if _Py__has_builtin(__builtin_nan)
5956
// Built-in implementation of the ISO C99 function nan(): quiet NaN.
6057
# define Py_NAN (__builtin_nan(""))
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Building Python now requires a C99 ``<math.h>`` header file providing a ``NAN``
2-
constant, or the ``__builtin_nan()`` built-in function. If a platform does not
3-
support Not-a-Number (NaN), the ``Py_NO_NAN`` macro can be defined in the
4-
``pyconfig.h`` file. Patch by Victor Stinner.
2+
constant, or the ``__builtin_nan()`` built-in function.
3+
Patch by Victor Stinner.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Building Python now requires support for floating point Not-a-Number (NaN):
2+
remove the ``Py_NO_NAN`` macro. Patch by by Victor Stinner.

Diff for: Modules/cmathmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ c_infj(void)
113113
return r;
114114
}
115115

116-
#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
116+
#if _PY_SHORT_FLOAT_REPR == 1
117117

118118
static double
119119
m_nan(void)
@@ -1282,7 +1282,7 @@ cmath_exec(PyObject *mod)
12821282
PyComplex_FromCComplex(c_infj())) < 0) {
12831283
return -1;
12841284
}
1285-
#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
1285+
#if _PY_SHORT_FLOAT_REPR == 1
12861286
if (PyModule_AddObject(mod, "nan", PyFloat_FromDouble(m_nan())) < 0) {
12871287
return -1;
12881288
}

Diff for: Modules/mathmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ m_inf(void)
283283
/* Constant nan value, generated in the same way as float('nan'). */
284284
/* We don't currently assume that Py_NAN is defined everywhere. */
285285

286-
#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
286+
#if _PY_SHORT_FLOAT_REPR == 1
287287

288288
static double
289289
m_nan(void)
@@ -3838,7 +3838,7 @@ math_exec(PyObject *module)
38383838
if (PyModule_AddObject(module, "inf", PyFloat_FromDouble(m_inf())) < 0) {
38393839
return -1;
38403840
}
3841-
#if _PY_SHORT_FLOAT_REPR == 1 || defined(Py_NAN)
3841+
#if _PY_SHORT_FLOAT_REPR == 1
38423842
if (PyModule_AddObject(module, "nan", PyFloat_FromDouble(m_nan())) < 0) {
38433843
return -1;
38443844
}

Diff for: Objects/floatobject.c

-8
Original file line numberDiff line numberDiff line change
@@ -2486,15 +2486,7 @@ _PyFloat_Unpack2(const unsigned char *p, int le)
24862486
}
24872487
else {
24882488
/* NaN */
2489-
#ifdef Py_NAN
24902489
return sign ? -Py_NAN : Py_NAN;
2491-
#else
2492-
PyErr_SetString(
2493-
PyExc_ValueError,
2494-
"can't unpack IEEE 754 NaN "
2495-
"on platform that does not support NaNs");
2496-
return -1;
2497-
#endif // !defined(Py_NAN)
24982490
}
24992491
#else // _PY_SHORT_FLOAT_REPR == 1
25002492
if (f == 0) {

Diff for: Python/pystrtod.c

-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
8282
s += 5;
8383
retval = negate ? -Py_HUGE_VAL : Py_HUGE_VAL;
8484
}
85-
#ifdef Py_NAN
8685
else if (case_insensitive_match(s, "nan")) {
8786
s += 3;
8887
retval = negate ? -Py_NAN : Py_NAN;
8988
}
90-
#endif
9189
else {
9290
s = p;
9391
retval = -1.0;

0 commit comments

Comments
 (0)