summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2016-08-29 12:56:58 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2016-08-29 12:56:58 (GMT)
commit84e6311dee71bb104e1779c89cf22ff703799086 (patch)
tree24edd9ad6b2909704f43a402f65ea31e6095be90 /Modules
parent8631da64bb1f163026b7be82884f8e5b506e0e66 (diff)
downloadcpython-84e6311dee71bb104e1779c89cf22ff703799086.zip
cpython-84e6311dee71bb104e1779c89cf22ff703799086.tar.gz
cpython-84e6311dee71bb104e1779c89cf22ff703799086.tar.bz2
Issue 23229: add cmath.inf, cmath.nan, cmath.infj and cmath.nanj.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/cmathmodule.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c
index 0e7d4db..8319767 100644
--- a/Modules/cmathmodule.c
+++ b/Modules/cmathmodule.c
@@ -81,6 +81,54 @@ 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_NO_SHORT_FLOAT_REPR is *not* defined (which should be
+ the most common situation on machines using an IEEE 754
+ representation), or Py_NAN is defined. */
+
+static double
+m_inf(void)
+{
+#ifndef PY_NO_SHORT_FLOAT_REPR
+ 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 !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
+
+static double
+m_nan(void)
+{
+#ifndef PY_NO_SHORT_FLOAT_REPR
+ 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);
static Py_complex cmath_atanh_impl(PyObject *, Py_complex);
@@ -1240,6 +1288,12 @@ PyInit_cmath(void)
PyFloat_FromDouble(Py_MATH_PI));
PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
PyModule_AddObject(m, "tau", PyFloat_FromDouble(Py_MATH_TAU)); /* 2pi */
+ PyModule_AddObject(m, "inf", PyFloat_FromDouble(m_inf()));
+ PyModule_AddObject(m, "infj", PyComplex_FromCComplex(c_infj()));
+#if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
+ PyModule_AddObject(m, "nan", PyFloat_FromDouble(m_nan()));
+ PyModule_AddObject(m, "nanj", PyComplex_FromCComplex(c_nanj()));
+#endif
/* initialize special value tables */