mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
Fast path for int inputs to math.dist() and math.hypot() (GH-11692)
This commit is contained in:
parent
ea446409cd
commit
808180c206
2 changed files with 34 additions and 4 deletions
|
|
@ -2144,7 +2144,14 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
|
|||
item = PyTuple_GET_ITEM(p, i);
|
||||
if (PyFloat_CheckExact(item)) {
|
||||
px = PyFloat_AS_DOUBLE(item);
|
||||
} else {
|
||||
}
|
||||
else if (PyLong_CheckExact(item)) {
|
||||
px = PyLong_AsDouble(item);
|
||||
if (px == -1.0 && PyErr_Occurred()) {
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
px = PyFloat_AsDouble(item);
|
||||
if (px == -1.0 && PyErr_Occurred()) {
|
||||
goto error_exit;
|
||||
|
|
@ -2153,7 +2160,14 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
|
|||
item = PyTuple_GET_ITEM(q, i);
|
||||
if (PyFloat_CheckExact(item)) {
|
||||
qx = PyFloat_AS_DOUBLE(item);
|
||||
} else {
|
||||
}
|
||||
else if (PyLong_CheckExact(item)) {
|
||||
qx = PyLong_AsDouble(item);
|
||||
if (qx == -1.0 && PyErr_Occurred()) {
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
qx = PyFloat_AsDouble(item);
|
||||
if (qx == -1.0 && PyErr_Occurred()) {
|
||||
goto error_exit;
|
||||
|
|
@ -2201,7 +2215,14 @@ math_hypot(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
item = args[i];
|
||||
if (PyFloat_CheckExact(item)) {
|
||||
x = PyFloat_AS_DOUBLE(item);
|
||||
} else {
|
||||
}
|
||||
else if (PyLong_CheckExact(item)) {
|
||||
x = PyLong_AsDouble(item);
|
||||
if (x == -1.0 && PyErr_Occurred()) {
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
else {
|
||||
x = PyFloat_AsDouble(item);
|
||||
if (x == -1.0 && PyErr_Occurred()) {
|
||||
goto error_exit;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue