diff options
-rw-r--r-- | Modules/mathmodule.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 2d483af..62d3279 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -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; |