Skip to content

Commit e202673

Browse files
skirpichevvstinner
andauthored
pythongh-141004: soft-deprecate Py_INFINITY macro (python#141033)
Co-authored-by: Victor Stinner <[email protected]>
1 parent c6f3dd6 commit e202673

File tree

13 files changed

+45
-36
lines changed

13 files changed

+45
-36
lines changed

Doc/c-api/conversion.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ The following functions provide locale-independent string to number conversions.
105105
106106
If ``s`` represents a value that is too large to store in a float
107107
(for example, ``"1e500"`` is such a string on many platforms) then
108-
if ``overflow_exception`` is ``NULL`` return ``Py_INFINITY`` (with
108+
if ``overflow_exception`` is ``NULL`` return :c:macro:`!INFINITY` (with
109109
an appropriate sign) and don't set any exception. Otherwise,
110110
``overflow_exception`` must point to a Python exception object;
111111
raise that exception and return ``-1.0``. In both cases, set

Doc/c-api/float.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ Floating-Point Objects
8383
This macro expands a to constant expression of type :c:expr:`double`, that
8484
represents the positive infinity.
8585
86-
On most platforms, this is equivalent to the :c:macro:`!INFINITY` macro from
87-
the C11 standard ``<math.h>`` header.
86+
It is equivalent to the :c:macro:`!INFINITY` macro from the C11 standard
87+
``<math.h>`` header.
88+
89+
.. deprecated:: 3.15
90+
The macro is soft deprecated.
8891
8992
9093
.. c:macro:: Py_NAN

Doc/whatsnew/3.14.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,7 @@ Deprecated C APIs
30453045
-----------------
30463046

30473047
* The :c:macro:`!Py_HUGE_VAL` macro is now :term:`soft deprecated`.
3048-
Use :c:macro:`!Py_INFINITY` instead.
3048+
Use :c:macro:`!INFINITY` instead.
30493049
(Contributed by Sergey B Kirpichev in :gh:`120026`.)
30503050

30513051
* The :c:macro:`!Py_IS_NAN`, :c:macro:`!Py_IS_INFINITY`,

Doc/whatsnew/3.15.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,10 @@ Deprecated C APIs
10951095
since 3.15 and will be removed in 3.17.
10961096
(Contributed by Nikita Sobolev in :gh:`136355`.)
10971097

1098+
* :c:macro:`!Py_INFINITY` macro is :term:`soft deprecated`,
1099+
use the C11 standard ``<math.h>`` :c:macro:`!INFINITY` instead.
1100+
(Contributed by Sergey B Kirpichev in :gh:`141004`.)
1101+
10981102
* :c:macro:`!Py_MATH_El` and :c:macro:`!Py_MATH_PIl` are deprecated
10991103
since 3.15 and will be removed in 3.20.
11001104
(Contributed by Sergey B Kirpichev in :gh:`141004`.)

Include/floatobject.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
1818

1919
#define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN)
2020

21-
#define Py_RETURN_INF(sign) \
22-
do { \
23-
if (copysign(1., sign) == 1.) { \
24-
return PyFloat_FromDouble(Py_INFINITY); \
25-
} \
26-
else { \
27-
return PyFloat_FromDouble(-Py_INFINITY); \
28-
} \
21+
#define Py_RETURN_INF(sign) \
22+
do { \
23+
if (copysign(1., sign) == 1.) { \
24+
return PyFloat_FromDouble(INFINITY); \
25+
} \
26+
else { \
27+
return PyFloat_FromDouble(-INFINITY); \
28+
} \
2929
} while(0)
3030

3131
PyAPI_FUNC(double) PyFloat_GetMax(void);

Include/internal/pycore_pymath.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333
static inline void _Py_ADJUST_ERANGE1(double x)
3434
{
3535
if (errno == 0) {
36-
if (x == Py_INFINITY || x == -Py_INFINITY) {
36+
if (x == INFINITY || x == -INFINITY) {
3737
errno = ERANGE;
3838
}
3939
}
@@ -44,8 +44,8 @@ static inline void _Py_ADJUST_ERANGE1(double x)
4444

4545
static inline void _Py_ADJUST_ERANGE2(double x, double y)
4646
{
47-
if (x == Py_INFINITY || x == -Py_INFINITY ||
48-
y == Py_INFINITY || y == -Py_INFINITY)
47+
if (x == INFINITY || x == -INFINITY ||
48+
y == INFINITY || y == -INFINITY)
4949
{
5050
if (errno == 0) {
5151
errno = ERANGE;

Include/pymath.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@
4545
#define Py_IS_FINITE(X) isfinite(X)
4646

4747
// Py_INFINITY: Value that evaluates to a positive double infinity.
48+
// Soft deprecated since Python 3.15, use INFINITY instead.
4849
#ifndef Py_INFINITY
4950
# define Py_INFINITY ((double)INFINITY)
5051
#endif
5152

5253
/* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically
5354
* this was not reliable and Python did not require IEEE floats and C99
54-
* conformity. The macro was soft deprecated in Python 3.14, use Py_INFINITY instead.
55+
* conformity. The macro was soft deprecated in Python 3.14, use INFINITY instead.
5556
*/
5657
#ifndef Py_HUGE_VAL
5758
# define Py_HUGE_VAL HUGE_VAL
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :c:macro:`!Py_INFINITY` macro is :term:`soft deprecated`.

Modules/cmathmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ special_type(double d)
150150
#define P14 0.25*Py_MATH_PI
151151
#define P12 0.5*Py_MATH_PI
152152
#define P34 0.75*Py_MATH_PI
153-
#define INF Py_INFINITY
153+
#define INF INFINITY
154154
#define N Py_NAN
155155
#define U -9.5426319407711027e33 /* unlikely value, used as placeholder */
156156

@@ -1186,11 +1186,11 @@ cmath_exec(PyObject *mod)
11861186
if (PyModule_Add(mod, "tau", PyFloat_FromDouble(Py_MATH_TAU)) < 0) {
11871187
return -1;
11881188
}
1189-
if (PyModule_Add(mod, "inf", PyFloat_FromDouble(Py_INFINITY)) < 0) {
1189+
if (PyModule_Add(mod, "inf", PyFloat_FromDouble(INFINITY)) < 0) {
11901190
return -1;
11911191
}
11921192

1193-
Py_complex infj = {0.0, Py_INFINITY};
1193+
Py_complex infj = {0.0, INFINITY};
11941194
if (PyModule_Add(mod, "infj", PyComplex_FromCComplex(infj)) < 0) {
11951195
return -1;
11961196
}

Modules/mathmodule.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ m_tgamma(double x)
395395
if (x == 0.0) {
396396
errno = EDOM;
397397
/* tgamma(+-0.0) = +-inf, divide-by-zero */
398-
return copysign(Py_INFINITY, x);
398+
return copysign(INFINITY, x);
399399
}
400400

401401
/* integer arguments */
@@ -426,7 +426,7 @@ m_tgamma(double x)
426426
}
427427
else {
428428
errno = ERANGE;
429-
return Py_INFINITY;
429+
return INFINITY;
430430
}
431431
}
432432

@@ -490,14 +490,14 @@ m_lgamma(double x)
490490
if (isnan(x))
491491
return x; /* lgamma(nan) = nan */
492492
else
493-
return Py_INFINITY; /* lgamma(+-inf) = +inf */
493+
return INFINITY; /* lgamma(+-inf) = +inf */
494494
}
495495

496496
/* integer arguments */
497497
if (x == floor(x) && x <= 2.0) {
498498
if (x <= 0.0) {
499499
errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */
500-
return Py_INFINITY; /* integers n <= 0 */
500+
return INFINITY; /* integers n <= 0 */
501501
}
502502
else {
503503
return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */
@@ -633,7 +633,7 @@ m_log(double x)
633633
return log(x);
634634
errno = EDOM;
635635
if (x == 0.0)
636-
return -Py_INFINITY; /* log(0) = -inf */
636+
return -INFINITY; /* log(0) = -inf */
637637
else
638638
return Py_NAN; /* log(-ve) = nan */
639639
}
@@ -676,7 +676,7 @@ m_log2(double x)
676676
}
677677
else if (x == 0.0) {
678678
errno = EDOM;
679-
return -Py_INFINITY; /* log2(0) = -inf, divide-by-zero */
679+
return -INFINITY; /* log2(0) = -inf, divide-by-zero */
680680
}
681681
else {
682682
errno = EDOM;
@@ -692,7 +692,7 @@ m_log10(double x)
692692
return log10(x);
693693
errno = EDOM;
694694
if (x == 0.0)
695-
return -Py_INFINITY; /* log10(0) = -inf */
695+
return -INFINITY; /* log10(0) = -inf */
696696
else
697697
return Py_NAN; /* log10(-ve) = nan */
698698
}
@@ -1500,7 +1500,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
15001500
errno = 0;
15011501
} else if (exp > INT_MAX) {
15021502
/* overflow */
1503-
r = copysign(Py_INFINITY, x);
1503+
r = copysign(INFINITY, x);
15041504
errno = ERANGE;
15051505
} else if (exp < INT_MIN) {
15061506
/* underflow to +-0 */
@@ -2983,7 +2983,7 @@ math_ulp_impl(PyObject *module, double x)
29832983
if (isinf(x)) {
29842984
return x;
29852985
}
2986-
double inf = Py_INFINITY;
2986+
double inf = INFINITY;
29872987
double x2 = nextafter(x, inf);
29882988
if (isinf(x2)) {
29892989
/* special case: x is the largest positive representable float */
@@ -3007,7 +3007,7 @@ math_exec(PyObject *module)
30073007
if (PyModule_Add(module, "tau", PyFloat_FromDouble(Py_MATH_TAU)) < 0) {
30083008
return -1;
30093009
}
3010-
if (PyModule_Add(module, "inf", PyFloat_FromDouble(Py_INFINITY)) < 0) {
3010+
if (PyModule_Add(module, "inf", PyFloat_FromDouble(INFINITY)) < 0) {
30113011
return -1;
30123012
}
30133013
if (PyModule_Add(module, "nan", PyFloat_FromDouble(fabs(Py_NAN))) < 0) {

0 commit comments

Comments
 (0)