Skip to content

Commit 8477951

Browse files
pythongh-120026: soft deprecate Py_HUGE_VAL macro (python#120027)
Co-authored-by: Adam Turner <[email protected]>
1 parent 28b148f commit 8477951

File tree

10 files changed

+23
-18
lines changed

10 files changed

+23
-18
lines changed

Doc/c-api/conversion.rst

+1-1
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_HUGE_VAL`` (with
108+
if ``overflow_exception`` is ``NULL`` return ``Py_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

+4
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,10 @@ Porting to Python 3.14
812812
Deprecated
813813
----------
814814

815+
* The :c:macro:`!Py_HUGE_VAL` macro is :term:`soft deprecated`,
816+
use :c:macro:`!Py_INFINITY` instead.
817+
(Contributed by Sergey B Kirpichev in :gh:`120026`.)
818+
815819
* Macros :c:macro:`!Py_IS_NAN`, :c:macro:`!Py_IS_INFINITY`
816820
and :c:macro:`!Py_IS_FINITE` are :term:`soft deprecated`,
817821
use instead :c:macro:`!isnan`, :c:macro:`!isinf` and

Include/floatobject.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
2121
#define Py_RETURN_INF(sign) \
2222
do { \
2323
if (copysign(1., sign) == 1.) { \
24-
return PyFloat_FromDouble(Py_HUGE_VAL); \
24+
return PyFloat_FromDouble(Py_INFINITY); \
2525
} \
2626
else { \
27-
return PyFloat_FromDouble(-Py_HUGE_VAL); \
27+
return PyFloat_FromDouble(-Py_INFINITY); \
2828
} \
2929
} while(0)
3030

Include/internal/pycore_pymath.h

+3-3
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_HUGE_VAL || x == -Py_HUGE_VAL) {
36+
if (x == Py_INFINITY || x == -Py_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_HUGE_VAL || x == -Py_HUGE_VAL ||
48-
y == Py_HUGE_VAL || y == -Py_HUGE_VAL)
47+
if (x == Py_INFINITY || x == -Py_INFINITY ||
48+
y == Py_INFINITY || y == -Py_INFINITY)
4949
{
5050
if (errno == 0) {
5151
errno = ERANGE;

Include/pymath.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
/* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically
5151
* this was not reliable and Python did not require IEEE floats and C99
52-
* conformity. Prefer Py_INFINITY for new code.
52+
* conformity. The macro was soft deprecated in Python 3.14, use Py_INFINITY instead.
5353
*/
5454
#ifndef Py_HUGE_VAL
5555
# define Py_HUGE_VAL HUGE_VAL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :c:macro:`!Py_HUGE_VAL` macro is :term:`soft deprecated`.

Modules/cmathmodule.c

+1-1
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_HUGE_VAL
153+
#define INF Py_INFINITY
154154
#define N Py_NAN
155155
#define U -9.5426319407711027e33 /* unlikely value, used as placeholder */
156156

Modules/mathmodule.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ m_tgamma(double x)
438438
}
439439
else {
440440
errno = ERANGE;
441-
return Py_HUGE_VAL;
441+
return Py_INFINITY;
442442
}
443443
}
444444

@@ -502,14 +502,14 @@ m_lgamma(double x)
502502
if (isnan(x))
503503
return x; /* lgamma(nan) = nan */
504504
else
505-
return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */
505+
return Py_INFINITY; /* lgamma(+-inf) = +inf */
506506
}
507507

508508
/* integer arguments */
509509
if (x == floor(x) && x <= 2.0) {
510510
if (x <= 0.0) {
511511
errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */
512-
return Py_HUGE_VAL; /* integers n <= 0 */
512+
return Py_INFINITY; /* integers n <= 0 */
513513
}
514514
else {
515515
return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */
@@ -645,7 +645,7 @@ m_log(double x)
645645
return log(x);
646646
errno = EDOM;
647647
if (x == 0.0)
648-
return -Py_HUGE_VAL; /* log(0) = -inf */
648+
return -Py_INFINITY; /* log(0) = -inf */
649649
else
650650
return Py_NAN; /* log(-ve) = nan */
651651
}
@@ -688,7 +688,7 @@ m_log2(double x)
688688
}
689689
else if (x == 0.0) {
690690
errno = EDOM;
691-
return -Py_HUGE_VAL; /* log2(0) = -inf, divide-by-zero */
691+
return -Py_INFINITY; /* log2(0) = -inf, divide-by-zero */
692692
}
693693
else {
694694
errno = EDOM;
@@ -704,7 +704,7 @@ m_log10(double x)
704704
return log10(x);
705705
errno = EDOM;
706706
if (x == 0.0)
707-
return -Py_HUGE_VAL; /* log10(0) = -inf */
707+
return -Py_INFINITY; /* log10(0) = -inf */
708708
else
709709
return Py_NAN; /* log10(-ve) = nan */
710710
}
@@ -2126,7 +2126,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
21262126
errno = 0;
21272127
} else if (exp > INT_MAX) {
21282128
/* overflow */
2129-
r = copysign(Py_HUGE_VAL, x);
2129+
r = copysign(Py_INFINITY, x);
21302130
errno = ERANGE;
21312131
} else if (exp < INT_MIN) {
21322132
/* underflow to +-0 */

Objects/floatobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ PyFloat_Unpack2(const char *data, int le)
23902390
if (e == 0x1f) {
23912391
if (f == 0) {
23922392
/* Infinity */
2393-
return sign ? -Py_HUGE_VAL : Py_HUGE_VAL;
2393+
return sign ? -Py_INFINITY : Py_INFINITY;
23942394
}
23952395
else {
23962396
/* NaN */

Python/pystrtod.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
4343
s += 3;
4444
if (case_insensitive_match(s, "inity"))
4545
s += 5;
46-
retval = negate ? -Py_HUGE_VAL : Py_HUGE_VAL;
46+
retval = negate ? -Py_INFINITY : Py_INFINITY;
4747
}
4848
else if (case_insensitive_match(s, "nan")) {
4949
s += 3;
@@ -286,7 +286,7 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
286286
string, -1.0 is returned and again ValueError is raised.
287287
288288
On overflow (e.g., when trying to convert '1e500' on an IEEE 754 machine),
289-
if overflow_exception is NULL then +-Py_HUGE_VAL is returned, and no Python
289+
if overflow_exception is NULL then +-Py_INFINITY is returned, and no Python
290290
exception is raised. Otherwise, overflow_exception should point to
291291
a Python exception, this exception will be raised, -1.0 will be returned,
292292
and *endptr will point just past the end of the converted value.

0 commit comments

Comments
 (0)