|
8 | 8 |
|
9 | 9 | #include "Python.h"
|
10 | 10 | #include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
|
11 |
| -#include "pycore_dtoa.h" // _Py_dg_stdnan() |
12 | 11 | /* we need DBL_MAX, DBL_MIN, DBL_EPSILON, DBL_MANT_DIG and FLT_RADIX from
|
13 | 12 | float.h. We assume that FLT_RADIX is either 2 or 16. */
|
14 | 13 | #include <float.h>
|
@@ -88,53 +87,6 @@ else {
|
88 | 87 | #endif
|
89 | 88 | #define CM_SCALE_DOWN (-(CM_SCALE_UP+1)/2)
|
90 | 89 |
|
91 |
| -/* Constants cmath.inf, cmath.infj, cmath.nan, cmath.nanj. |
92 |
| - cmath.nan and cmath.nanj are defined only when either |
93 |
| - _PY_SHORT_FLOAT_REPR is 1 (which should be |
94 |
| - the most common situation on machines using an IEEE 754 |
95 |
| - representation), or Py_NAN is defined. */ |
96 |
| - |
97 |
| -static double |
98 |
| -m_inf(void) |
99 |
| -{ |
100 |
| -#if _PY_SHORT_FLOAT_REPR == 1 |
101 |
| - return _Py_dg_infinity(0); |
102 |
| -#else |
103 |
| - return Py_HUGE_VAL; |
104 |
| -#endif |
105 |
| -} |
106 |
| - |
107 |
| -static Py_complex |
108 |
| -c_infj(void) |
109 |
| -{ |
110 |
| - Py_complex r; |
111 |
| - r.real = 0.0; |
112 |
| - r.imag = m_inf(); |
113 |
| - return r; |
114 |
| -} |
115 |
| - |
116 |
| -#if _PY_SHORT_FLOAT_REPR == 1 |
117 |
| - |
118 |
| -static double |
119 |
| -m_nan(void) |
120 |
| -{ |
121 |
| -#if _PY_SHORT_FLOAT_REPR == 1 |
122 |
| - return _Py_dg_stdnan(0); |
123 |
| -#else |
124 |
| - return Py_NAN; |
125 |
| -#endif |
126 |
| -} |
127 |
| - |
128 |
| -static Py_complex |
129 |
| -c_nanj(void) |
130 |
| -{ |
131 |
| - Py_complex r; |
132 |
| - r.real = 0.0; |
133 |
| - r.imag = m_nan(); |
134 |
| - return r; |
135 |
| -} |
136 |
| - |
137 |
| -#endif |
138 | 90 |
|
139 | 91 | /* forward declarations */
|
140 | 92 | static Py_complex cmath_asinh_impl(PyObject *, Py_complex);
|
@@ -1274,23 +1226,22 @@ cmath_exec(PyObject *mod)
|
1274 | 1226 | if (PyModule_AddObject(mod, "tau", PyFloat_FromDouble(Py_MATH_TAU)) < 0) {
|
1275 | 1227 | return -1;
|
1276 | 1228 | }
|
1277 |
| - if (PyModule_AddObject(mod, "inf", PyFloat_FromDouble(m_inf())) < 0) { |
| 1229 | + if (PyModule_AddObject(mod, "inf", PyFloat_FromDouble(Py_INFINITY)) < 0) { |
1278 | 1230 | return -1;
|
1279 | 1231 | }
|
1280 | 1232 |
|
| 1233 | + Py_complex infj = {0.0, Py_INFINITY}; |
1281 | 1234 | if (PyModule_AddObject(mod, "infj",
|
1282 |
| - PyComplex_FromCComplex(c_infj())) < 0) { |
| 1235 | + PyComplex_FromCComplex(infj)) < 0) { |
1283 | 1236 | return -1;
|
1284 | 1237 | }
|
1285 |
| -#if _PY_SHORT_FLOAT_REPR == 1 |
1286 |
| - if (PyModule_AddObject(mod, "nan", PyFloat_FromDouble(m_nan())) < 0) { |
| 1238 | + if (PyModule_AddObject(mod, "nan", PyFloat_FromDouble(fabs(Py_NAN))) < 0) { |
1287 | 1239 | return -1;
|
1288 | 1240 | }
|
1289 |
| - if (PyModule_AddObject(mod, "nanj", |
1290 |
| - PyComplex_FromCComplex(c_nanj())) < 0) { |
| 1241 | + Py_complex nanj = {0.0, fabs(Py_NAN)}; |
| 1242 | + if (PyModule_AddObject(mod, "nanj", PyComplex_FromCComplex(nanj)) < 0) { |
1291 | 1243 | return -1;
|
1292 | 1244 | }
|
1293 |
| -#endif |
1294 | 1245 |
|
1295 | 1246 | /* initialize special value tables */
|
1296 | 1247 |
|
|
0 commit comments