Skip to content

Commit 5b7bc64

Browse files
committed
gh-120026: deprecate (soft) Py_HUGE_VAL macro
1 parent 9e05261 commit 5b7bc64

File tree

10 files changed

+23
-18
lines changed

10 files changed

+23
-18
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_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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ Deprecated
270270
:c:macro:`!isfinite` available from :file:`math.h`
271271
since C99. (Contributed by Sergey B Kirpichev in :gh:`119613`.)
272272

273+
* Macro :c:macro:`!Py_HUGE_VAL` is :term:`soft deprecated`, use instead
274+
:c:macro:`!Py_INFINITY`. (Contributed by Sergey B Kirpichev in
275+
:gh:`120026`.)
276+
273277
Removed
274278
-------
275279

Include/floatobject.h

Lines changed: 2 additions & 2 deletions
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

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_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

Lines changed: 1 addition & 1 deletion
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. Soft deprecated since Python 3.14, use Py_INFINITY instead.
5353
*/
5454
#ifndef Py_HUGE_VAL
5555
# define Py_HUGE_VAL HUGE_VAL
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Macro :c:macro:`!Py_HUGE_VAL` is :term:`soft deprecated`.

Modules/cmathmodule.c

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 7 deletions
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 */
@@ -682,7 +682,7 @@ m_log(double x)
682682
return log(x);
683683
errno = EDOM;
684684
if (x == 0.0)
685-
return -Py_HUGE_VAL; /* log(0) = -inf */
685+
return -Py_INFINITY; /* log(0) = -inf */
686686
else
687687
return Py_NAN; /* log(-ve) = nan */
688688
}
@@ -725,7 +725,7 @@ m_log2(double x)
725725
}
726726
else if (x == 0.0) {
727727
errno = EDOM;
728-
return -Py_HUGE_VAL; /* log2(0) = -inf, divide-by-zero */
728+
return -Py_INFINITY; /* log2(0) = -inf, divide-by-zero */
729729
}
730730
else {
731731
errno = EDOM;
@@ -741,7 +741,7 @@ m_log10(double x)
741741
return log10(x);
742742
errno = EDOM;
743743
if (x == 0.0)
744-
return -Py_HUGE_VAL; /* log10(0) = -inf */
744+
return -Py_INFINITY; /* log10(0) = -inf */
745745
else
746746
return Py_NAN; /* log10(-ve) = nan */
747747
}
@@ -2159,7 +2159,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
21592159
errno = 0;
21602160
} else if (exp > INT_MAX) {
21612161
/* overflow */
2162-
r = copysign(Py_HUGE_VAL, x);
2162+
r = copysign(Py_INFINITY, x);
21632163
errno = ERANGE;
21642164
} else if (exp < INT_MIN) {
21652165
/* underflow to +-0 */

Objects/floatobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ PyFloat_Unpack2(const char *data, int le)
24142414
if (e == 0x1f) {
24152415
if (f == 0) {
24162416
/* Infinity */
2417-
return sign ? -Py_HUGE_VAL : Py_HUGE_VAL;
2417+
return sign ? -Py_INFINITY : Py_INFINITY;
24182418
}
24192419
else {
24202420
/* NaN */

Python/pystrtod.c

Lines changed: 2 additions & 2 deletions
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)