summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2018-07-31 07:45:49 (GMT)
committerGitHub <noreply@github.com>2018-07-31 07:45:49 (GMT)
commit9c18b1ae527346bc178250ad1ca07bffdacde5dd (patch)
tree117fc5de5a05d5f9da9bed73921d3ef9c02409bc /Modules/clinic
parent9d5727326af53ddd91016d98e16ae7cf829caa95 (diff)
downloadcpython-9c18b1ae527346bc178250ad1ca07bffdacde5dd.zip
cpython-9c18b1ae527346bc178250ad1ca07bffdacde5dd.tar.gz
cpython-9c18b1ae527346bc178250ad1ca07bffdacde5dd.tar.bz2
bpo-33089: Add math.dist() for computing the Euclidean distance between two points (GH-8561)
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/mathmodule.c.h37
1 files changed, 36 insertions, 1 deletions
diff --git a/Modules/clinic/mathmodule.c.h b/Modules/clinic/mathmodule.c.h
index 3a487bd..c4d2786 100644
--- a/Modules/clinic/mathmodule.c.h
+++ b/Modules/clinic/mathmodule.c.h
@@ -269,6 +269,41 @@ exit:
return return_value;
}
+PyDoc_STRVAR(math_dist__doc__,
+"dist($module, p, q, /)\n"
+"--\n"
+"\n"
+"Return the Euclidean distance between two points p and q.\n"
+"\n"
+"The points should be specified as tuples of coordinates.\n"
+"Both tuples must be the same size.\n"
+"\n"
+"Roughly equivalent to:\n"
+" sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))");
+
+#define MATH_DIST_METHODDEF \
+ {"dist", (PyCFunction)math_dist, METH_FASTCALL, math_dist__doc__},
+
+static PyObject *
+math_dist_impl(PyObject *module, PyObject *p, PyObject *q);
+
+static PyObject *
+math_dist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *p;
+ PyObject *q;
+
+ if (!_PyArg_ParseStack(args, nargs, "O!O!:dist",
+ &PyTuple_Type, &p, &PyTuple_Type, &q)) {
+ goto exit;
+ }
+ return_value = math_dist_impl(module, p, q);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(math_pow__doc__,
"pow($module, x, y, /)\n"
"--\n"
@@ -487,4 +522,4 @@ math_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
exit:
return return_value;
}
-/*[clinic end generated code: output=1c35516a10443902 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d936137c1189b89b input=a9049054013a1b77]*/