diff --git a/Modules/clinic/mathmodule.c.h b/Modules/clinic/mathmodule.c.h index 54bf75dbf2468e..81eec310ddb21d 100644 --- a/Modules/clinic/mathmodule.c.h +++ b/Modules/clinic/mathmodule.c.h @@ -8,64 +8,6 @@ preserve #endif #include "pycore_modsupport.h" // _PyArg_CheckPositional() -PyDoc_STRVAR(math_gcd__doc__, -"gcd($module, /, *integers)\n" -"--\n" -"\n" -"Greatest Common Divisor."); - -#define MATH_GCD_METHODDEF \ - {"gcd", _PyCFunction_CAST(math_gcd), METH_FASTCALL, math_gcd__doc__}, - -static PyObject * -math_gcd_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args); - -static PyObject * -math_gcd(PyObject *module, PyObject *const *args, Py_ssize_t nargs) -{ - PyObject *return_value = NULL; - Py_ssize_t nvararg = nargs; - PyObject *const *__clinic_args = NULL; - - if (!_PyArg_CheckPositional("gcd", nargs, 0, PY_SSIZE_T_MAX)) { - goto exit; - } - __clinic_args = args + 0; - return_value = math_gcd_impl(module, nvararg, __clinic_args); - -exit: - return return_value; -} - -PyDoc_STRVAR(math_lcm__doc__, -"lcm($module, /, *integers)\n" -"--\n" -"\n" -"Least Common Multiple."); - -#define MATH_LCM_METHODDEF \ - {"lcm", _PyCFunction_CAST(math_lcm), METH_FASTCALL, math_lcm__doc__}, - -static PyObject * -math_lcm_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args); - -static PyObject * -math_lcm(PyObject *module, PyObject *const *args, Py_ssize_t nargs) -{ - PyObject *return_value = NULL; - Py_ssize_t nvararg = nargs; - PyObject *const *__clinic_args = NULL; - - if (!_PyArg_CheckPositional("lcm", nargs, 0, PY_SSIZE_T_MAX)) { - goto exit; - } - __clinic_args = args + 0; - return_value = math_lcm_impl(module, nvararg, __clinic_args); - -exit: - return return_value; -} - PyDoc_STRVAR(math_ceil__doc__, "ceil($module, x, /)\n" "--\n" @@ -409,46 +351,6 @@ math_dist(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -PyDoc_STRVAR(math_hypot__doc__, -"hypot($module, /, *coordinates)\n" -"--\n" -"\n" -"Multidimensional Euclidean distance from the origin to a point.\n" -"\n" -"Roughly equivalent to:\n" -" sqrt(sum(x**2 for x in coordinates))\n" -"\n" -"For a two dimensional point (x, y), gives the hypotenuse\n" -"using the Pythagorean theorem: sqrt(x*x + y*y).\n" -"\n" -"For example, the hypotenuse of a 3/4/5 right triangle is:\n" -"\n" -" >>> hypot(3.0, 4.0)\n" -" 5.0"); - -#define MATH_HYPOT_METHODDEF \ - {"hypot", _PyCFunction_CAST(math_hypot), METH_FASTCALL, math_hypot__doc__}, - -static PyObject * -math_hypot_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args); - -static PyObject * -math_hypot(PyObject *module, PyObject *const *args, Py_ssize_t nargs) -{ - PyObject *return_value = NULL; - Py_ssize_t nvararg = nargs; - PyObject *const *__clinic_args = NULL; - - if (!_PyArg_CheckPositional("hypot", nargs, 0, PY_SSIZE_T_MAX)) { - goto exit; - } - __clinic_args = args + 0; - return_value = math_hypot_impl(module, nvararg, __clinic_args); - -exit: - return return_value; -} - PyDoc_STRVAR(math_sumprod__doc__, "sumprod($module, p, q, /)\n" "--\n" @@ -1109,4 +1011,4 @@ math_ulp(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=69376c19d96a9c50 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=755da3b1dbd9e45f input=a9049054013a1b77]*/ diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index ad23dadd7b86cc..058f57770755aa 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -719,17 +719,8 @@ m_log10(double x) } -/*[clinic input] -math.gcd - - *integers as args: object - -Greatest Common Divisor. -[clinic start generated code]*/ - static PyObject * -math_gcd_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args) -/*[clinic end generated code: output=b57687fcf431c1b8 input=94e675b7ceeaf0c9]*/ +math_gcd(PyObject *module, PyObject * const *args, Py_ssize_t nargs) { // Fast-path for the common case: gcd(int, int) if (nargs == 2 && PyLong_CheckExact(args[0]) && PyLong_CheckExact(args[1])) @@ -772,6 +763,12 @@ math_gcd_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args) return res; } +PyDoc_STRVAR(math_gcd_doc, +"gcd($module, *integers)\n" +"--\n" +"\n" +"Greatest Common Divisor."); + static PyObject * long_lcm(PyObject *a, PyObject *b) @@ -801,17 +798,8 @@ long_lcm(PyObject *a, PyObject *b) } -/*[clinic input] -math.lcm - - *integers as args: object - -Least Common Multiple. -[clinic start generated code]*/ - static PyObject * -math_lcm_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args) -/*[clinic end generated code: output=f3eff0c25e4d7030 input=e64c33e85f4c47c6]*/ +math_lcm(PyObject *module, PyObject * const *args, Py_ssize_t nargs) { PyObject *res, *x; Py_ssize_t i; @@ -851,6 +839,13 @@ math_lcm_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args) } +PyDoc_STRVAR(math_lcm_doc, +"lcm($module, *integers)\n" +"--\n" +"\n" +"Least Common Multiple."); + + /* Call is_error when errno != 0, and where x is the result libm * returned. is_error will usually set up an exception and return * true (1), but may return false (0) without setting up an exception. @@ -2626,28 +2621,9 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q) return NULL; } -/*[clinic input] -math.hypot - - *coordinates as args: object - -Multidimensional Euclidean distance from the origin to a point. - -Roughly equivalent to: - sqrt(sum(x**2 for x in coordinates)) - -For a two dimensional point (x, y), gives the hypotenuse -using the Pythagorean theorem: sqrt(x*x + y*y). - -For example, the hypotenuse of a 3/4/5 right triangle is: - - >>> hypot(3.0, 4.0) - 5.0 -[clinic start generated code]*/ - +/* AC: cannot convert yet, waiting for *args support */ static PyObject * -math_hypot_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args) -/*[clinic end generated code: output=dcb6d4b7a1102ee1 input=5c0061a2d11235ed]*/ +math_hypot(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { Py_ssize_t i; PyObject *item; @@ -2688,6 +2664,22 @@ math_hypot_impl(PyObject *module, Py_ssize_t nargs, PyObject *const *args) #undef NUM_STACK_ELEMS +PyDoc_STRVAR(math_hypot_doc, + "hypot(*coordinates) -> value\n\n\ +Multidimensional Euclidean distance from the origin to a point.\n\ +\n\ +Roughly equivalent to:\n\ + sqrt(sum(x**2 for x in coordinates))\n\ +\n\ +For a two dimensional point (x, y), gives the hypotenuse\n\ +using the Pythagorean theorem: sqrt(x*x + y*y).\n\ +\n\ +For example, the hypotenuse of a 3/4/5 right triangle is:\n\ +\n\ + >>> hypot(3.0, 4.0)\n\ + 5.0\n\ +"); + /** sumprod() ***************************************************************/ /* Forward declaration */ @@ -4120,14 +4112,14 @@ static PyMethodDef math_methods[] = { MATH_FREXP_METHODDEF MATH_FSUM_METHODDEF {"gamma", math_gamma, METH_O, math_gamma_doc}, - MATH_GCD_METHODDEF - MATH_HYPOT_METHODDEF + {"gcd", _PyCFunction_CAST(math_gcd), METH_FASTCALL, math_gcd_doc}, + {"hypot", _PyCFunction_CAST(math_hypot), METH_FASTCALL, math_hypot_doc}, MATH_ISCLOSE_METHODDEF MATH_ISFINITE_METHODDEF MATH_ISINF_METHODDEF MATH_ISNAN_METHODDEF MATH_ISQRT_METHODDEF - MATH_LCM_METHODDEF + {"lcm", _PyCFunction_CAST(math_lcm), METH_FASTCALL, math_lcm_doc}, MATH_LDEXP_METHODDEF {"lgamma", math_lgamma, METH_O, math_lgamma_doc}, {"log", _PyCFunction_CAST(math_log), METH_FASTCALL, math_log_doc},