diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2023-11-28 08:18:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 08:18:33 (GMT) |
commit | f14d741daa1b9e5b9c9fc1edba93d0fa92b5ba8d (patch) | |
tree | 9edcede7869293cf3642624cb17f6d2a7bdb2b25 /Modules | |
parent | 2c68011780bd68463f5183601ea9c10af368dff6 (diff) | |
download | cpython-f14d741daa1b9e5b9c9fc1edba93d0fa92b5ba8d.zip cpython-f14d741daa1b9e5b9c9fc1edba93d0fa92b5ba8d.tar.gz cpython-f14d741daa1b9e5b9c9fc1edba93d0fa92b5ba8d.tar.bz2 |
gh-109802: Increase test coverage for complexobject.c (GH-112452)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapi/complex.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Modules/_testcapi/complex.c b/Modules/_testcapi/complex.c index 400f405..4a70217 100644 --- a/Modules/_testcapi/complex.c +++ b/Modules/_testcapi/complex.c @@ -85,6 +85,58 @@ complex_asccomplex(PyObject *Py_UNUSED(module), PyObject *obj) return PyComplex_FromCComplex(complex); } +static PyObject* +_py_c_neg(PyObject *Py_UNUSED(module), PyObject *num) +{ + Py_complex complex; + + complex = PyComplex_AsCComplex(num); + if (complex.real == -1. && PyErr_Occurred()) { + return NULL; + } + + return PyComplex_FromCComplex(_Py_c_neg(complex)); +} + +#define _PY_C_FUNC2(suffix) \ + static PyObject * \ + _py_c_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \ + { \ + Py_complex num, exp, res; \ + \ + if (!PyArg_ParseTuple(args, "DD", &num, &exp)) { \ + return NULL; \ + } \ + \ + errno = 0; \ + res = _Py_c_##suffix(num, exp); \ + return Py_BuildValue("Di", &res, errno); \ + }; + +_PY_C_FUNC2(sum) +_PY_C_FUNC2(diff) +_PY_C_FUNC2(prod) +_PY_C_FUNC2(quot) +_PY_C_FUNC2(pow) + +static PyObject* +_py_c_abs(PyObject *Py_UNUSED(module), PyObject* obj) +{ + Py_complex complex; + double res; + + NULLABLE(obj); + complex = PyComplex_AsCComplex(obj); + + if (complex.real == -1. && PyErr_Occurred()) { + return NULL; + } + + errno = 0; + res = _Py_c_abs(complex); + return Py_BuildValue("di", res, errno); +} + static PyMethodDef test_methods[] = { {"complex_check", complex_check, METH_O}, @@ -94,6 +146,13 @@ static PyMethodDef test_methods[] = { {"complex_realasdouble", complex_realasdouble, METH_O}, {"complex_imagasdouble", complex_imagasdouble, METH_O}, {"complex_asccomplex", complex_asccomplex, METH_O}, + {"_py_c_sum", _py_c_sum, METH_VARARGS}, + {"_py_c_diff", _py_c_diff, METH_VARARGS}, + {"_py_c_neg", _py_c_neg, METH_O}, + {"_py_c_prod", _py_c_prod, METH_VARARGS}, + {"_py_c_quot", _py_c_quot, METH_VARARGS}, + {"_py_c_pow", _py_c_pow, METH_VARARGS}, + {"_py_c_abs", _py_c_abs, METH_O}, {NULL}, }; |