8000 gh-101123: Add signature for the math.hypot by skirpichev · Pull Request #101124 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-101123: Add signature for the math.hypot #101124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
8000 Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert AC stuff & use solution from the issue description (no perform…
…ance penalty)
  • Loading branch information
skirpichev committed Jan 18, 2023
commit 5d035d7d4c07ff0569965443dc339c9a84f0999c
48 changes: 1 addition & 47 deletions Modules/clinic/mathmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 23 additions & 28 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2761,49 +2761,26 @@ 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, PyObject *args)
/*[clinic end generated code: output=ace3a23188b6798e input=ff33f88cd8b1f06d]*/
math_hypot(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
Py_ssize_t i, nargs;
Py_ssize_t i;
PyObject *item;
double max = 0.0;
double x, result;
int found_nan = 0;
double coord_on_stack[NUM_STACK_ELEMS];
double *coordinates = coord_on_stack;

nargs = PyTuple_GET_SIZE(args);

if (nargs > NUM_STACK_ELEMS) {
coordinates = (double *) PyObject_Malloc(nargs * sizeof(double));
if (coordinates == NULL) {
return PyErr_NoMemory();
}
}
for (i = 0; i < nargs; i++) {
item = PyTuple_GetItem(args, i);
item = args[i];
ASSIGN_DOUBLE(x, item, error_exit);
x = fabs(x);
coordinates[i] = x;
Expand All @@ -2827,6 +2804,24 @@ math_hypot_impl(PyObject *module, PyObject *args)

#undef NUM_STACK_ELEMS

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\n\
");

/** sumprod() ***************************************************************/

/* Forward declaration */
Expand Down Expand Up @@ -4241,7 +4236,6 @@ static PyMethodDef math_methods[] = {
{"cosh", math_cosh, METH_O, math_cosh_doc},
MATH_DEGREES_METHODDEF
MATH_DIST_METHODDEF
MATH_HYPOT_METHODDEF
{"erf", math_erf, METH_O, math_erf_doc},
{"erfc", math_erfc, METH_O, math_erfc_doc},
{"exp", math_exp, METH_O, math_exp_doc},
Expand All @@ -4255,6 +4249,7 @@ static PyMethodDef math_methods[] = {
MATH_FSUM_METHODDEF
{"gamma", math_gamma, METH_O, math_gamma_doc},
{"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
Expand Down
0