diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2015-01-11 11:55:29 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2015-01-11 11:55:29 (GMT) |
commit | a5d0c7c2fdd638d684acdb5391e0987b1e37f56a (patch) | |
tree | 90debcd5a43e635d8a0dda8cb69533588c6c513e /Modules/mathmodule.c | |
parent | 845b14cc8ef2d95e72c97a788a1ffb31faeaa3a8 (diff) | |
download | cpython-a5d0c7c2fdd638d684acdb5391e0987b1e37f56a.zip cpython-a5d0c7c2fdd638d684acdb5391e0987b1e37f56a.tar.gz cpython-a5d0c7c2fdd638d684acdb5391e0987b1e37f56a.tar.bz2 |
Issue #23185: add math.inf and math.nan constants.
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r-- | Modules/mathmodule.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index bce3799..0c991cd 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -223,6 +223,35 @@ lanczos_sum(double x) return num/den; } +/* Constant for +infinity, generated in the same way as float('inf'). */ + +static double +m_inf(void) +{ +#ifndef PY_NO_SHORT_FLOAT_REPR + return _Py_dg_infinity(0); +#else + return Py_HUGE_VAL; +#endif +} + +/* Constant nan value, generated in the same way as float('nan'). */ +/* We don't currently assume that Py_NAN is defined everywhere. */ + +#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 +} + +#endif + static double m_tgamma(double x) { @@ -2009,7 +2038,11 @@ PyInit_math(void) PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI)); PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E)); + PyModule_AddObject(m, "inf", PyFloat_FromDouble(m_inf())); +#if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN) + PyModule_AddObject(m, "nan", PyFloat_FromDouble(m_nan())); +#endif - finally: + finally: return m; } |