mirror of
https://github.com/python/cpython.git
synced 2024-11-24 17:47:13 +01:00
gh-120026: soft deprecate Py_HUGE_VAL macro (#120027)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
parent
28b148fb32
commit
8477951a1c
@ -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
|
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
|
(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,
|
an appropriate sign) and don't set any exception. Otherwise,
|
||||||
``overflow_exception`` must point to a Python exception object;
|
``overflow_exception`` must point to a Python exception object;
|
||||||
raise that exception and return ``-1.0``. In both cases, set
|
raise that exception and return ``-1.0``. In both cases, set
|
||||||
|
@ -812,6 +812,10 @@ Porting to Python 3.14
|
|||||||
Deprecated
|
Deprecated
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* 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`.)
|
||||||
|
|
||||||
* Macros :c:macro:`!Py_IS_NAN`, :c:macro:`!Py_IS_INFINITY`
|
* Macros :c:macro:`!Py_IS_NAN`, :c:macro:`!Py_IS_INFINITY`
|
||||||
and :c:macro:`!Py_IS_FINITE` are :term:`soft deprecated`,
|
and :c:macro:`!Py_IS_FINITE` are :term:`soft deprecated`,
|
||||||
use instead :c:macro:`!isnan`, :c:macro:`!isinf` and
|
use instead :c:macro:`!isnan`, :c:macro:`!isinf` and
|
||||||
|
@ -21,10 +21,10 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
|
|||||||
#define Py_RETURN_INF(sign) \
|
#define Py_RETURN_INF(sign) \
|
||||||
do { \
|
do { \
|
||||||
if (copysign(1., sign) == 1.) { \
|
if (copysign(1., sign) == 1.) { \
|
||||||
return PyFloat_FromDouble(Py_HUGE_VAL); \
|
return PyFloat_FromDouble(Py_INFINITY); \
|
||||||
} \
|
} \
|
||||||
else { \
|
else { \
|
||||||
return PyFloat_FromDouble(-Py_HUGE_VAL); \
|
return PyFloat_FromDouble(-Py_INFINITY); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ extern "C" {
|
|||||||
static inline void _Py_ADJUST_ERANGE1(double x)
|
static inline void _Py_ADJUST_ERANGE1(double x)
|
||||||
{
|
{
|
||||||
if (errno == 0) {
|
if (errno == 0) {
|
||||||
if (x == Py_HUGE_VAL || x == -Py_HUGE_VAL) {
|
if (x == Py_INFINITY || x == -Py_INFINITY) {
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,8 +44,8 @@ static inline void _Py_ADJUST_ERANGE1(double x)
|
|||||||
|
|
||||||
static inline void _Py_ADJUST_ERANGE2(double x, double y)
|
static inline void _Py_ADJUST_ERANGE2(double x, double y)
|
||||||
{
|
{
|
||||||
if (x == Py_HUGE_VAL || x == -Py_HUGE_VAL ||
|
if (x == Py_INFINITY || x == -Py_INFINITY ||
|
||||||
y == Py_HUGE_VAL || y == -Py_HUGE_VAL)
|
y == Py_INFINITY || y == -Py_INFINITY)
|
||||||
{
|
{
|
||||||
if (errno == 0) {
|
if (errno == 0) {
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
/* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically
|
/* 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
|
* this was not reliable and Python did not require IEEE floats and C99
|
||||||
* conformity. Prefer Py_INFINITY for new code.
|
* conformity. The macro was soft deprecated in Python 3.14, use Py_INFINITY instead.
|
||||||
*/
|
*/
|
||||||
#ifndef Py_HUGE_VAL
|
#ifndef Py_HUGE_VAL
|
||||||
# define Py_HUGE_VAL HUGE_VAL
|
# define Py_HUGE_VAL HUGE_VAL
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
The :c:macro:`!Py_HUGE_VAL` macro is :term:`soft deprecated`.
|
@ -150,7 +150,7 @@ special_type(double d)
|
|||||||
#define P14 0.25*Py_MATH_PI
|
#define P14 0.25*Py_MATH_PI
|
||||||
#define P12 0.5*Py_MATH_PI
|
#define P12 0.5*Py_MATH_PI
|
||||||
#define P34 0.75*Py_MATH_PI
|
#define P34 0.75*Py_MATH_PI
|
||||||
#define INF Py_HUGE_VAL
|
#define INF Py_INFINITY
|
||||||
#define N Py_NAN
|
#define N Py_NAN
|
||||||
#define U -9.5426319407711027e33 /* unlikely value, used as placeholder */
|
#define U -9.5426319407711027e33 /* unlikely value, used as placeholder */
|
||||||
|
|
||||||
|
@ -438,7 +438,7 @@ m_tgamma(double x)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
return Py_HUGE_VAL;
|
return Py_INFINITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,14 +502,14 @@ m_lgamma(double x)
|
|||||||
if (isnan(x))
|
if (isnan(x))
|
||||||
return x; /* lgamma(nan) = nan */
|
return x; /* lgamma(nan) = nan */
|
||||||
else
|
else
|
||||||
return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */
|
return Py_INFINITY; /* lgamma(+-inf) = +inf */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* integer arguments */
|
/* integer arguments */
|
||||||
if (x == floor(x) && x <= 2.0) {
|
if (x == floor(x) && x <= 2.0) {
|
||||||
if (x <= 0.0) {
|
if (x <= 0.0) {
|
||||||
errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */
|
errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */
|
||||||
return Py_HUGE_VAL; /* integers n <= 0 */
|
return Py_INFINITY; /* integers n <= 0 */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */
|
return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */
|
||||||
@ -645,7 +645,7 @@ m_log(double x)
|
|||||||
return log(x);
|
return log(x);
|
||||||
errno = EDOM;
|
errno = EDOM;
|
||||||
if (x == 0.0)
|
if (x == 0.0)
|
||||||
return -Py_HUGE_VAL; /* log(0) = -inf */
|
return -Py_INFINITY; /* log(0) = -inf */
|
||||||
else
|
else
|
||||||
return Py_NAN; /* log(-ve) = nan */
|
return Py_NAN; /* log(-ve) = nan */
|
||||||
}
|
}
|
||||||
@ -688,7 +688,7 @@ m_log2(double x)
|
|||||||
}
|
}
|
||||||
else if (x == 0.0) {
|
else if (x == 0.0) {
|
||||||
errno = EDOM;
|
errno = EDOM;
|
||||||
return -Py_HUGE_VAL; /* log2(0) = -inf, divide-by-zero */
|
return -Py_INFINITY; /* log2(0) = -inf, divide-by-zero */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
errno = EDOM;
|
errno = EDOM;
|
||||||
@ -704,7 +704,7 @@ m_log10(double x)
|
|||||||
return log10(x);
|
return log10(x);
|
||||||
errno = EDOM;
|
errno = EDOM;
|
||||||
if (x == 0.0)
|
if (x == 0.0)
|
||||||
return -Py_HUGE_VAL; /* log10(0) = -inf */
|
return -Py_INFINITY; /* log10(0) = -inf */
|
||||||
else
|
else
|
||||||
return Py_NAN; /* log10(-ve) = nan */
|
return Py_NAN; /* log10(-ve) = nan */
|
||||||
}
|
}
|
||||||
@ -2126,7 +2126,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
} else if (exp > INT_MAX) {
|
} else if (exp > INT_MAX) {
|
||||||
/* overflow */
|
/* overflow */
|
||||||
r = copysign(Py_HUGE_VAL, x);
|
r = copysign(Py_INFINITY, x);
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
} else if (exp < INT_MIN) {
|
} else if (exp < INT_MIN) {
|
||||||
/* underflow to +-0 */
|
/* underflow to +-0 */
|
||||||
|
@ -2390,7 +2390,7 @@ PyFloat_Unpack2(const char *data, int le)
|
|||||||
if (e == 0x1f) {
|
if (e == 0x1f) {
|
||||||
if (f == 0) {
|
if (f == 0) {
|
||||||
/* Infinity */
|
/* Infinity */
|
||||||
return sign ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
return sign ? -Py_INFINITY : Py_INFINITY;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* NaN */
|
/* NaN */
|
||||||
|
@ -43,7 +43,7 @@ _Py_parse_inf_or_nan(const char *p, char **endptr)
|
|||||||
s += 3;
|
s += 3;
|
||||||
if (case_insensitive_match(s, "inity"))
|
if (case_insensitive_match(s, "inity"))
|
||||||
s += 5;
|
s += 5;
|
||||||
retval = negate ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
retval = negate ? -Py_INFINITY : Py_INFINITY;
|
||||||
}
|
}
|
||||||
else if (case_insensitive_match(s, "nan")) {
|
else if (case_insensitive_match(s, "nan")) {
|
||||||
s += 3;
|
s += 3;
|
||||||
@ -286,7 +286,7 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
|
|||||||
string, -1.0 is returned and again ValueError is raised.
|
string, -1.0 is returned and again ValueError is raised.
|
||||||
|
|
||||||
On overflow (e.g., when trying to convert '1e500' on an IEEE 754 machine),
|
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
|
exception is raised. Otherwise, overflow_exception should point to
|
||||||
a Python exception, this exception will be raised, -1.0 will be returned,
|
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.
|
and *endptr will point just past the end of the converted value.
|
||||||
|
Loading…
Reference in New Issue
Block a user