Commit 74734f73 authored by Raymond Hettinger's avatar Raymond Hettinger Committed by GitHub

Fast path for exact floats in math.hypot() and math.dist() (GH-8949)

parent 89d79b14
......@@ -2134,14 +2134,22 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
}
for (i=0 ; i<n ; i++) {
item = PyTuple_GET_ITEM(p, i);
px = PyFloat_AsDouble(item);
if (px == -1.0 && PyErr_Occurred()) {
goto error_exit;
if (PyFloat_CheckExact(item)) {
px = PyFloat_AS_DOUBLE(item);
} else {
px = PyFloat_AsDouble(item);
if (px == -1.0 && PyErr_Occurred()) {
goto error_exit;
}
}
item = PyTuple_GET_ITEM(q, i);
qx = PyFloat_AsDouble(item);
if (qx == -1.0 && PyErr_Occurred()) {
goto error_exit;
if (PyFloat_CheckExact(item)) {
qx = PyFloat_AS_DOUBLE(item);
} else {
qx = PyFloat_AsDouble(item);
if (qx == -1.0 && PyErr_Occurred()) {
goto error_exit;
}
}
x = fabs(px - qx);
diffs[i] = x;
......@@ -2183,9 +2191,13 @@ math_hypot(PyObject *self, PyObject *args)
}
for (i=0 ; i<n ; i++) {
item = PyTuple_GET_ITEM(args, i);
x = PyFloat_AsDouble(item);
if (x == -1.0 && PyErr_Occurred()) {
goto error_exit;
if (PyFloat_CheckExact(item)) {
x = PyFloat_AS_DOUBLE(item);
} else {
x = PyFloat_AsDouble(item);
if (x == -1.0 && PyErr_Occurred()) {
goto error_exit;
}
}
x = fabs(x);
coordinates[i] = x;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment