Skip to content

Commit 31e779b

Browse files
committed
gh-141004: soft-deprecate Py_INFINITY macro
1 parent 947bb46 commit 31e779b

File tree

12 files changed

+40
-34
lines changed

12 files changed

+40
-34
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/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
@@ -1068,6 +1068,10 @@ Deprecated C APIs
10681068
since 3.15 and will be removed in 3.17.
10691069
(Contributed by Nikita Sobolev in :gh:`136355`.)
10701070

1071+
* The :c:macro:`!Py_INFINITY` macro is :term:`soft deprecated`,
1072+
use the C standard :c:macro:`!INFINITY` instead.
1073+
(Contributed by Sergey B Kirpichev in :gh:`141004`.)
1074+
10711075

10721076
.. Add C API deprecations above alphabetically, not here at the end.
10731077

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
@@ -43,13 +43,14 @@
4343
#define Py_IS_FINITE(X) isfinite(X)
4444

4545
// Py_INFINITY: Value that evaluates to a positive double infinity.
46+
// Soft deprecated since Python 3.15, use INFINITY instead.
4647
#ifndef Py_INFINITY
4748
# define Py_INFINITY ((double)INFINITY)
4849
#endif
4950

5051
/* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically
5152
* this was not reliable and Python did not require IEEE floats and C99
52-
* conformity. The macro was soft deprecated in Python 3.14, use Py_INFINITY instead.
53+
* conformity. The macro was soft deprecated in Python 3.14, use INFINITY instead.
5354
*/
5455
#ifndef Py_HUGE_VAL
5556
# 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
@@ -394,7 +394,7 @@ m_tgamma(double x)
394394
if (x == 0.0) {
395395
errno = EDOM;
396396
/* tgamma(+-0.0) = +-inf, divide-by-zero */
397-
return copysign(Py_INFINITY, x);
397+
return copysign(INFINITY, x);
398398
}
399399

400400
/* integer arguments */
@@ -425,7 +425,7 @@ m_tgamma(double x)
425425
}
426426
else {
427427
errno = ERANGE;
428-
return Py_INFINITY;
428+
return INFINITY;
429429
}
430430
}
431431

@@ -489,14 +489,14 @@ m_lgamma(double x)
489489
if (isnan(x))
490490
return x; /* lgamma(nan) = nan */
491491
else
492-
return Py_INFINITY; /* lgamma(+-inf) = +inf */
492+
return INFINITY; /* lgamma(+-inf) = +inf */
493493
}
494494

495495
/* integer arguments */
496496
if (x == floor(x) && x <= 2.0) {
497497
if (x <= 0.0) {
498498
errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */
499-
return Py_INFINITY; /* integers n <= 0 */
499+
return INFINITY; /* integers n <= 0 */
500500
}
501501
else {
502502
return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */
@@ -632,7 +632,7 @@ m_log(double x)
632632
return log(x);
633633
errno = EDOM;
634634
if (x == 0.0)
635-
return -Py_INFINITY; /* log(0) = -inf */
635+
return -INFINITY; /* log(0) = -inf */
636636
else
637637
return Py_NAN; /* log(-ve) = nan */
638638
}
@@ -675,7 +675,7 @@ m_log2(double x)
675675
}
676676
else if (x == 0.0) {
677677
errno = EDOM;
678-
return -Py_INFINITY; /* log2(0) = -inf, divide-by-zero */
678+
return -INFINITY; /* log2(0) = -inf, divide-by-zero */
679679
}
680680
else {
681681
errno = EDOM;
@@ -691,7 +691,7 @@ m_log10(double x)
691691
return log10(x);
692692
errno = EDOM;
693693
if (x == 0.0)
694-
return -Py_INFINITY; /* log10(0) = -inf */
694+
return -INFINITY; /* log10(0) = -inf */
695695
else
696696
return Py_NAN; /* log10(-ve) = nan */
697697
}
@@ -1499,7 +1499,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
14991499
errno = 0;
15001500
} else if (exp > INT_MAX) {
15011501
/* overflow */
1502-
r = copysign(Py_INFINITY, x);
1502+
r = copysign(INFINITY, x);
15031503
errno = ERANGE;
15041504
} else if (exp < INT_MIN) {
15051505
/* underflow to +-0 */
@@ -2963,7 +2963,7 @@ math_ulp_impl(PyObject *module, double x)
29632963
if (isinf(x)) {
29642964
return x;
29652965
}
2966-
double inf = Py_INFINITY;
2966+
double inf = INFINITY;
29672967
double x2 = nextafter(x, inf);
29682968
if (isinf(x2)) {
29692969
/* special case: x is the largest positive representable float */
@@ -2987,7 +2987,7 @@ math_exec(PyObject *module)
29872987
if (PyModule_Add(module, "tau", PyFloat_FromDouble(Py_MATH_TAU)) < 0) {
29882988
return -1;
29892989
}
2990-
if (PyModule_Add(module, "inf", PyFloat_FromDouble(Py_INFINITY)) < 0) {
2990+
if (PyModule_Add(module, "inf", PyFloat_FromDouble(INFINITY)) < 0) {
29912991
return -1;
29922992
}
29932993
if (PyModule_Add(module, "nan", PyFloat_FromDouble(fabs(Py_NAN))) < 0) {

Objects/complexobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ _Py_c_prod(Py_complex z, Py_complex w)
139139
recalc = 1;
140140
}
141141
if (recalc) {
142-
r.real = Py_INFINITY*(a*c - b*d);
143-
r.imag = Py_INFINITY*(a*d + b*c);
142+
r.real = INFINITY*(a*c - b*d);
143+
r.imag = INFINITY*(a*d + b*c);
144144
}
145145
}
146146

@@ -229,8 +229,8 @@ _Py_c_quot(Py_complex a, Py_complex b)
229229
{
230230
const double x = copysign(isinf(a.real) ? 1.0 : 0.0, a.real);
231231
const double y = copysign(isinf(a.imag) ? 1.0 : 0.0, a.imag);
232-
r.real = Py_INFINITY * (x*b.real + y*b.imag);
233-
r.imag = Py_INFINITY * (y*b.real - x*b.imag);
232+
r.real = INFINITY * (x*b.real + y*b.imag);
233+
r.imag = INFINITY * (y*b.real - x*b.imag);
234234
}
235235
else if ((isinf(abs_breal) || isinf(abs_bimag))
236236
&& isfinite(a.real) && isfinite(a.imag))

0 commit comments

Comments
 (0)