diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-07-11 17:38:24 +0000 |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-07-11 17:38:24 +0000 |
commit | cfc298652b7ae5772a10d4e18339d313e7e887b3 (patch) | |
tree | 19cd706e0b953326c71c32ee024879097c54c7d5 /Modules/cmathmodule.c | |
parent | cc37e66d2631bec6b303a2e1527a96fef8836ff8 (diff) | |
download | cpython-cfc298652b7ae5772a10d4e18339d313e7e887b3.tar.gz |
Issue #9165: Add math.isfinite and cmath.isfinite.
Diffstat (limited to 'Modules/cmathmodule.c')
-rw-r--r-- | Modules/cmathmodule.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c index 2af2e53b88..986b241e29 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}, |