diff options
Diffstat (limited to 'Modules/cmathmodule.c')
-rw-r--r-- | Modules/cmathmodule.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c index 0dc6bdb3968..3021cf0466a 100644 --- a/Modules/cmathmodule.c +++ b/Modules/cmathmodule.c @@ -1024,6 +1024,19 @@ PyDoc_STRVAR(cmath_rect_doc, Convert from polar coordinates to rectangular coordinates."); static PyObject * +cmath_isfinite(PyObject *self, PyObject *args) +{ + Py_complex z; + if (!PyArg_ParseTuple(args, "D:isfinite", &z)) + return NULL; + return PyBool_FromLong(Py_IS_FINITE(z.real) && Py_IS_FINITE(z.imag)); +} + +PyDoc_STRVAR(cmath_isfinite_doc, +"isfinite(z) -> bool\n\ +Return True if both the real and imaginary parts of z are finite, else False."); + +static PyObject * cmath_isnan(PyObject *self, PyObject *args) { Py_complex z; @@ -1065,6 +1078,7 @@ static PyMethodDef cmath_methods[] = { {"cos", cmath_cos, METH_VARARGS, c_cos_doc}, {"cosh", cmath_cosh, METH_VARARGS, c_cosh_doc}, {"exp", cmath_exp, METH_VARARGS, c_exp_doc}, + {"isfinite", cmath_isfinite, METH_VARARGS, cmath_isfinite_doc}, {"isinf", cmath_isinf, METH_VARARGS, cmath_isinf_doc}, {"isnan", cmath_isnan, METH_VARARGS, cmath_isnan_doc}, {"log", cmath_log, METH_VARARGS, cmath_log_doc}, @@ -1080,14 +1094,27 @@ static PyMethodDef cmath_methods[] = { {NULL, NULL} /* sentinel */ }; + +static struct PyModuleDef cmathmodule = { + PyModuleDef_HEAD_INIT, + "cmath", + module_doc, + -1, + cmath_methods, + NULL, + NULL, + NULL, + NULL +}; + PyMODINIT_FUNC -initcmath(void) +PyInit_cmath(void) { PyObject *m; - m = Py_InitModule3("cmath", cmath_methods, module_doc); + m = PyModule_Create(&cmathmodule); if (m == NULL) - return; + return NULL; PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI)); @@ -1207,4 +1234,5 @@ initcmath(void) C(INF,N) C(U,U) C(INF,-0.) C(INF,0.) C(U,U) C(INF,N) C(INF,N) C(N,N) C(N,N) C(N,0.) C(N,0.) C(N,N) C(N,N) C(N,N) }) + return m; } |