From 5b7bc648e899007e03b29d59e123e07b06a30b76 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 4 Jun 2024 13:23:47 +0300 Subject: [PATCH 1/5] gh-120026: deprecate (soft) Py_HUGE_VAL macro --- Doc/c-api/conversion.rst | 2 +- Doc/whatsnew/3.14.rst | 4 ++++ Include/floatobject.h | 4 ++-- Include/internal/pycore_pymath.h | 6 +++--- Include/pymath.h | 2 +- .../2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst | 1 + Modules/cmathmodule.c | 2 +- Modules/mathmodule.c | 14 +++++++------- Objects/floatobject.c | 2 +- Python/pystrtod.c | 4 ++-- 10 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst diff --git a/Doc/c-api/conversion.rst b/Doc/c-api/conversion.rst index 4aaf3905e81c8a..c92ef4c653a675 100644 --- a/Doc/c-api/conversion.rst +++ b/Doc/c-api/conversion.rst @@ -105,7 +105,7 @@ The following functions provide locale-independent string to number conversions. If ``s`` represents a value that is too large to store in a float (for example, ``"1e500"`` is such a string on many platforms) then - if ``overflow_exception`` is ``NULL`` return ``Py_HUGE_VAL`` (with + if ``overflow_exception`` is ``NULL`` return ``Py_INFINITY`` (with an appropriate sign) and don't set any exception. Otherwise, ``overflow_exception`` must point to a Python exception object; raise that exception and return ``-1.0``. In both cases, set diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index b2dd80b64a691a..15aad5de41df4d 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -270,6 +270,10 @@ Deprecated :c:macro:`!isfinite` available from :file:`math.h` since C99. (Contributed by Sergey B Kirpichev in :gh:`119613`.) +* Macro :c:macro:`!Py_HUGE_VAL` is :term:`soft deprecated`, use instead + :c:macro:`!Py_INFINITY`. (Contributed by Sergey B Kirpichev in + :gh:`120026`.) + Removed ------- diff --git a/Include/floatobject.h b/Include/floatobject.h index 999441ac536e1d..45a54608412261 100644 --- a/Include/floatobject.h +++ b/Include/floatobject.h @@ -21,10 +21,10 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type; #define Py_RETURN_INF(sign) \ do { \ if (copysign(1., sign) == 1.) { \ - return PyFloat_FromDouble(Py_HUGE_VAL); \ + return PyFloat_FromDouble(Py_INFINITY); \ } \ else { \ - return PyFloat_FromDouble(-Py_HUGE_VAL); \ + return PyFloat_FromDouble(-Py_INFINITY); \ } \ } while(0) diff --git a/Include/internal/pycore_pymath.h b/Include/internal/pycore_pymath.h index 7a4e1c1eb714f7..eea8996ba68ca0 100644 --- a/Include/internal/pycore_pymath.h +++ b/Include/internal/pycore_pymath.h @@ -33,7 +33,7 @@ extern "C" { static inline void _Py_ADJUST_ERANGE1(double x) { if (errno == 0) { - if (x == Py_HUGE_VAL || x == -Py_HUGE_VAL) { + if (x == Py_INFINITY || x == -Py_INFINITY) { errno = ERANGE; } } @@ -44,8 +44,8 @@ static inline void _Py_ADJUST_ERANGE1(double x) static inline void _Py_ADJUST_ERANGE2(double x, double y) { - if (x == Py_HUGE_VAL || x == -Py_HUGE_VAL || - y == Py_HUGE_VAL || y == -Py_HUGE_VAL) + if (x == Py_INFINITY || x == -Py_INFINITY || + y == Py_INFINITY || y == -Py_INFINITY) { if (errno == 0) { errno = ERANGE; diff --git a/Include/pymath.h b/Include/pymath.h index d8f763f808d662..9db1b5e878dbd1 100644 --- a/Include/pymath.h +++ b/Include/pymath.h @@ -49,7 +49,7 @@ /* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically * this was not reliable and Python did not require IEEE floats and C99 - * conformity. Prefer Py_INFINITY for new code. + * conformity. Soft deprecated since Python 3.14, use Py_INFINITY instead. */ #ifndef Py_HUGE_VAL # define Py_HUGE_VAL HUGE_VAL diff --git a/Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst b/Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst new file mode 100644 index 00000000000000..b6a6dd6fc0cd75 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst @@ -0,0 +1 @@ +Macro :c:macro:`!Py_HUGE_VAL` is :term:`soft deprecated`. diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c index bf86a211bcb188..91a41d5783be8d 100644 --- a/Modules/cmathmodule.c +++ b/Modules/cmathmodule.c @@ -150,7 +150,7 @@ special_type(double d) #define P14 0.25*Py_MATH_PI #define P12 0.5*Py_MATH_PI #define P34 0.75*Py_MATH_PI -#define INF Py_HUGE_VAL +#define INF Py_INFINITY #define N Py_NAN #define U -9.5426319407711027e33 /* unlikely value, used as placeholder */ diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 6defa973da0952..29cdde2c47416b 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -438,7 +438,7 @@ m_tgamma(double x) } else { errno = ERANGE; - return Py_HUGE_VAL; + return Py_INFINITY; } } @@ -502,14 +502,14 @@ m_lgamma(double x) if (isnan(x)) return x; /* lgamma(nan) = nan */ else - return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */ + return Py_INFINITY; /* lgamma(+-inf) = +inf */ } /* integer arguments */ if (x == floor(x) && x <= 2.0) { if (x <= 0.0) { errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */ - return Py_HUGE_VAL; /* integers n <= 0 */ + return Py_INFINITY; /* integers n <= 0 */ } else { return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */ @@ -682,7 +682,7 @@ m_log(double x) return log(x); errno = EDOM; if (x == 0.0) - return -Py_HUGE_VAL; /* log(0) = -inf */ + return -Py_INFINITY; /* log(0) = -inf */ else return Py_NAN; /* log(-ve) = nan */ } @@ -725,7 +725,7 @@ m_log2(double x) } else if (x == 0.0) { errno = EDOM; - return -Py_HUGE_VAL; /* log2(0) = -inf, divide-by-zero */ + return -Py_INFINITY; /* log2(0) = -inf, divide-by-zero */ } else { errno = EDOM; @@ -741,7 +741,7 @@ m_log10(double x) return log10(x); errno = EDOM; if (x == 0.0) - return -Py_HUGE_VAL; /* log10(0) = -inf */ + return -Py_INFINITY; /* log10(0) = -inf */ else return Py_NAN; /* log10(-ve) = nan */ } @@ -2159,7 +2159,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i) errno = 0; } else if (exp > INT_MAX) { /* overflow */ - r = copysign(Py_HUGE_VAL, x); + r = copysign(Py_INFINITY, x); errno = ERANGE; } else if (exp < INT_MIN) { /* underflow to +-0 */ diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 2627ba80eed8ca..0d8c5032cf177f 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -2414,7 +2414,7 @@ PyFloat_Unpack2(const char *data, int le) if (e == 0x1f) { if (f == 0) { /* Infinity */ - return sign ? -Py_HUGE_VAL : Py_HUGE_VAL; + return sign ? -Py_INFINITY : Py_INFINITY; } else { /* NaN */ diff --git a/Python/pystrtod.c b/Python/pystrtod.c index 5c8be0447ace4b..911e508cab97a1 100644 --- a/Python/pystrtod.c +++ b/Python/pystrtod.c @@ -43,7 +43,7 @@ _Py_parse_inf_or_nan(const char *p, char **endptr) s += 3; if (case_insensitive_match(s, "inity")) s += 5; - retval = negate ? -Py_HUGE_VAL : Py_HUGE_VAL; + retval = negate ? -Py_INFINITY : Py_INFINITY; } else if (case_insensitive_match(s, "nan")) { s += 3; @@ -286,7 +286,7 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr) string, -1.0 is returned and again ValueError is raised. On overflow (e.g., when trying to convert '1e500' on an IEEE 754 machine), - if overflow_exception is NULL then +-Py_HUGE_VAL is returned, and no Python + if overflow_exception is NULL then +-Py_INFINITY is returned, and no Python exception is raised. Otherwise, overflow_exception should point to a Python exception, this exception will be raised, -1.0 will be returned, and *endptr will point just past the end of the converted value. From 9ad8416f37ea3e1fa8bb4448f1dd23c990025d7d Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 20 Aug 2024 07:10:39 +0300 Subject: [PATCH 2/5] + damn web editor --- Doc/whatsnew/3.14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 3b4d17e858b59e..9fded982769610 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -449,7 +449,7 @@ Deprecated * Macro :c:macro:`!Py_HUGE_VAL` is :term:`soft deprecated`, use instead :c:macro:`!Py_INFINITY`. (Contributed by Sergey B Kirpichev in :gh:`120026`.) - + * :func:`!asyncio.iscoroutinefunction` is deprecated and will be removed in Python 3.16, use :func:`inspect.iscoroutinefunction` instead. From 9abcb580729ab8306035db7d850b17e35f322f7e Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 20 Aug 2024 12:46:42 +0300 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Doc/whatsnew/3.14.rst | 6 +++--- Include/pymath.h | 2 +- .../C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 9fded982769610..c3508504472f0b 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -446,9 +446,9 @@ Deprecated :c:macro:`!isfinite` available from :file:`math.h` since C99. (Contributed by Sergey B Kirpichev in :gh:`119613`.) -* Macro :c:macro:`!Py_HUGE_VAL` is :term:`soft deprecated`, use instead - :c:macro:`!Py_INFINITY`. (Contributed by Sergey B Kirpichev in - :gh:`120026`.) +* The :c:macro:`!Py_HUGE_VAL` macro is :term:`soft deprecated`, + use :c:macro:`!Py_INFINITY` instead. + (Contributed by Sergey B Kirpichev in :gh:`120026`.) * :func:`!asyncio.iscoroutinefunction` is deprecated and will be removed in Python 3.16, diff --git a/Include/pymath.h b/Include/pymath.h index 9db1b5e878dbd1..0ead1f95670fde 100644 --- a/Include/pymath.h +++ b/Include/pymath.h @@ -49,7 +49,7 @@ /* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically * this was not reliable and Python did not require IEEE floats and C99 - * conformity. Soft deprecated since Python 3.14, use Py_INFINITY instead. + * conformity. The macro was soft deprecated in Python 3.14, use Py_INFINITY instead. */ #ifndef Py_HUGE_VAL # define Py_HUGE_VAL HUGE_VAL diff --git a/Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst b/Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst index b6a6dd6fc0cd75..d43a138724ad33 100644 --- a/Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst +++ b/Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst @@ -1 +1 @@ -Macro :c:macro:`!Py_HUGE_VAL` is :term:`soft deprecated`. +The :c:macro:`!Py_HUGE_VAL` macro is :term:`soft deprecated`. From d221527a26badc3fbce1c67f1d66b7f06aa1de1c Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 1 Nov 2024 19:17:57 +0300 Subject: [PATCH 4/5] address review: 3.14.rst --- Doc/whatsnew/3.14.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index de3e5f195848c7..205495a82a80b5 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -710,11 +710,6 @@ Deprecated :c:macro:`!isfinite` available from :file:`math.h` since C99. (Contributed by Sergey B Kirpichev in :gh:`119613`.) -* :func:`!asyncio.iscoroutinefunction` is deprecated - and will be removed in Python 3.16, - use :func:`inspect.iscoroutinefunction` instead. - (Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.) - .. Add C API deprecations above alphabetically, not here at the end. .. include:: ../deprecations/c-api-pending-removal-in-3.15.rst From 881bddf6baa3187c134010e915bffc62cda957b9 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 1 Nov 2024 19:22:13 +0300 Subject: [PATCH 5/5] move news --- .../2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/{C API => C_API}/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst (100%) diff --git a/Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst b/Misc/NEWS.d/next/C_API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst similarity index 100% rename from Misc/NEWS.d/next/C API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst rename to Misc/NEWS.d/next/C_API/2024-06-04-13-38-44.gh-issue-120026.uhEvJ9.rst