mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
Fast path for exact floats in math.hypot() and math.dist() (GH-8949)
This commit is contained in:
parent
89d79b1449
commit
74734f73ca
1 changed files with 21 additions and 9 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue