diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2019-02-07 07:04:02 (GMT) |
---|---|---|
committer | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2019-02-07 07:04:02 (GMT) |
commit | bc098515864d0d1ffe8fb97ca1a0526c30fee45a (patch) | |
tree | 2a39dfe4d826700abc132c01db7a92f0de76a7b7 /Modules/clinic | |
parent | e9bc4172d18db9c182d8e04dd7b033097a994c06 (diff) | |
download | cpython-bc098515864d0d1ffe8fb97ca1a0526c30fee45a.zip cpython-bc098515864d0d1ffe8fb97ca1a0526c30fee45a.tar.gz cpython-bc098515864d0d1ffe8fb97ca1a0526c30fee45a.tar.bz2 |
bpo-35606: Implement math.prod (GH-11359)
Diffstat (limited to 'Modules/clinic')
-rw-r--r-- | Modules/clinic/mathmodule.c.h | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/Modules/clinic/mathmodule.c.h b/Modules/clinic/mathmodule.c.h index 82a4c4a..b99a8de 100644 --- a/Modules/clinic/mathmodule.c.h +++ b/Modules/clinic/mathmodule.c.h @@ -556,4 +556,41 @@ math_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject exit: return return_value; } -/*[clinic end generated code: output=0664f30046da09fe input=a9049054013a1b77]*/ + +PyDoc_STRVAR(math_prod__doc__, +"prod($module, iterable, /, *, start=1)\n" +"--\n" +"\n" +"Calculate the product of all the elements in the input iterable.\n" +"\n" +"The default start value for the product is 1.\n" +"\n" +"When the iterable is empty, return the start value. This function is\n" +"intended specifically for use with numeric values and may reject\n" +"non-numeric types."); + +#define MATH_PROD_METHODDEF \ + {"prod", (PyCFunction)(void(*)(void))math_prod, METH_FASTCALL|METH_KEYWORDS, math_prod__doc__}, + +static PyObject * +math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start); + +static PyObject * +math_prod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"", "start", NULL}; + static _PyArg_Parser _parser = {"O|$O:prod", _keywords, 0}; + PyObject *iterable; + PyObject *start = NULL; + + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, + &iterable, &start)) { + goto exit; + } + return_value = math_prod_impl(module, iterable, start); + +exit: + return return_value; +} +/*[clinic end generated code: output=20505690ca6fe402 input=a9049054013a1b77]*/ |