summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/cmathmodule.c
diff options
context:
space:
mode:
authorAlexSm <[email protected]>2024-02-16 11:51:30 +0100
committerGitHub <[email protected]>2024-02-16 11:51:30 +0100
commit506ecaee93b52cc12c2e2f97c3d42e3ca2a7f59e (patch)
treed096fb9eb988fbb0ca1ba970041773207ce3aa70 /contrib/tools/python3/src/Modules/cmathmodule.c
parent4749b9e5d260714490997e6f5ee1ee8c1c8fc46c (diff)
parentf200f72c9d7a89c1018e3dc6b46c49fe2ecf84fb (diff)
Merge pull request #1940 from dcherednik/importlib
Library import 14
Diffstat (limited to 'contrib/tools/python3/src/Modules/cmathmodule.c')
-rw-r--r--contrib/tools/python3/src/Modules/cmathmodule.c65
1 files changed, 9 insertions, 56 deletions
diff --git a/contrib/tools/python3/src/Modules/cmathmodule.c b/contrib/tools/python3/src/Modules/cmathmodule.c
index 7fffb31cff0..25491e65584 100644
--- a/contrib/tools/python3/src/Modules/cmathmodule.c
+++ b/contrib/tools/python3/src/Modules/cmathmodule.c
@@ -8,7 +8,6 @@
#include "Python.h"
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
-#include "pycore_dtoa.h" // _Py_dg_stdnan()
/* we need DBL_MAX, DBL_MIN, DBL_EPSILON, DBL_MANT_DIG and FLT_RADIX from
float.h. We assume that FLT_RADIX is either 2 or 16. */
#include <float.h>
@@ -88,53 +87,6 @@ else {
#endif
#define CM_SCALE_DOWN (-(CM_SCALE_UP+1)/2)
-/* Constants cmath.inf, cmath.infj, cmath.nan, cmath.nanj.
- cmath.nan and cmath.nanj are defined only when either
- _PY_SHORT_FLOAT_REPR is 1 (which should be
- the most common situation on machines using an IEEE 754
- representation), or Py_NAN is defined. */
-
-static double
-m_inf(void)
-{
-#if _PY_SHORT_FLOAT_REPR == 1
- return _Py_dg_infinity(0);
-#else
- return Py_HUGE_VAL;
-#endif
-}
-
-static Py_complex
-c_infj(void)
-{
- Py_complex r;
- r.real = 0.0;
- r.imag = m_inf();
- return r;
-}
-
-#if _PY_SHORT_FLOAT_REPR == 1
-
-static double
-m_nan(void)
-{
-#if _PY_SHORT_FLOAT_REPR == 1
- return _Py_dg_stdnan(0);
-#else
- return Py_NAN;
-#endif
-}
-
-static Py_complex
-c_nanj(void)
-{
- Py_complex r;
- r.real = 0.0;
- r.imag = m_nan();
- return r;
-}
-
-#endif
/* forward declarations */
static Py_complex cmath_asinh_impl(PyObject *, Py_complex);
@@ -829,7 +781,7 @@ cmath_sqrt_impl(PyObject *module, Py_complex z)
ax = fabs(z.real);
ay = fabs(z.imag);
- if (ax < DBL_MIN && ay < DBL_MIN && (ax > 0. || ay > 0.)) {
+ if (ax < DBL_MIN && ay < DBL_MIN) {
/* here we catch cases where hypot(ax, ay) is subnormal */
ax = ldexp(ax, CM_SCALE_UP);
s = ldexp(sqrt(ax + hypot(ax, ldexp(ay, CM_SCALE_UP))),
@@ -1013,7 +965,7 @@ cmath_phase_impl(PyObject *module, Py_complex z)
double phi;
errno = 0;
- phi = c_atan2(z);
+ phi = c_atan2(z); /* should not cause any exception */
if (errno != 0)
return math_error();
else
@@ -1274,21 +1226,21 @@ cmath_exec(PyObject *mod)
if (_PyModule_Add(mod, "tau", PyFloat_FromDouble(Py_MATH_TAU)) < 0) {
return -1;
}
- if (_PyModule_Add(mod, "inf", PyFloat_FromDouble(m_inf())) < 0) {
+ if (_PyModule_Add(mod, "inf", PyFloat_FromDouble(Py_INFINITY)) < 0) {
return -1;
}
- if (_PyModule_Add(mod, "infj", PyComplex_FromCComplex(c_infj())) < 0) {
+ Py_complex infj = {0.0, Py_INFINITY};
+ if (_PyModule_Add(mod, "infj", PyComplex_FromCComplex(infj)) < 0) {
return -1;
}
-#if _PY_SHORT_FLOAT_REPR == 1
- if (_PyModule_Add(mod, "nan", PyFloat_FromDouble(m_nan())) < 0) {
+ if (_PyModule_Add(mod, "nan", PyFloat_FromDouble(fabs(Py_NAN))) < 0) {
return -1;
}
- if (_PyModule_Add(mod, "nanj", PyComplex_FromCComplex(c_nanj())) < 0) {
+ Py_complex nanj = {0.0, fabs(Py_NAN)};
+ if (_PyModule_Add(mod, "nanj", PyComplex_FromCComplex(nanj)) < 0) {
return -1;
}
-#endif
/* initialize special value tables */
@@ -1409,6 +1361,7 @@ cmath_exec(PyObject *mod)
static PyModuleDef_Slot cmath_slots[] = {
{Py_mod_exec, cmath_exec},
+ {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};