@@ -2134,14 +2134,22 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
2134
2134
}
2135
2135
for (i = 0 ; i < n ; i ++ ) {
2136
2136
item = PyTuple_GET_ITEM (p , i );
2137
- px = PyFloat_AsDouble (item );
2138
- if (px == -1.0 && PyErr_Occurred ()) {
2139
- goto error_exit ;
2137
+ if (PyFloat_CheckExact (item )) {
2138
+ px = PyFloat_AS_DOUBLE (item );
2139
+ } else {
2140
+ px = PyFloat_AsDouble (item );
2141
+ if (px == -1.0 && PyErr_Occurred ()) {
2142
+ goto error_exit ;
2143
+ }
2140
2144
}
2141
2145
item = PyTuple_GET_ITEM (q , i );
2142
- qx = PyFloat_AsDouble (item );
2143
- if (qx == -1.0 && PyErr_Occurred ()) {
2144
- goto error_exit ;
2146
+ if (PyFloat_CheckExact (item )) {
2147
+ qx = PyFloat_AS_DOUBLE (item );
2148
+ } else {
2149
+ qx = PyFloat_AsDouble (item );
2150
+ if (qx == -1.0 && PyErr_Occurred ()) {
2151
+ goto error_exit ;
2152
+ }
2145
2153
}
2146
2154
x = fabs (px - qx );
2147
2155
diffs [i ] = x ;
@@ -2183,9 +2191,13 @@ math_hypot(PyObject *self, PyObject *args)
2183
2191
}
2184
2192
for (i = 0 ; i < n ; i ++ ) {
2185
2193
item = PyTuple_GET_ITEM (args , i );
2186
- x = PyFloat_AsDouble (item );
2187
- if (x == -1.0 && PyErr_Occurred ()) {
2188
- goto error_exit ;
2194
+ if (PyFloat_CheckExact (item )) {
2195
+ x = PyFloat_AS_DOUBLE (item );
2196
+ } else {
2197
+ x = PyFloat_AsDouble (item );
2198
+ if (x == -1.0 && PyErr_Occurred ()) {
2199
+ goto error_exit ;
2200
+ }
2189
2201
}
2190
2202
x = fabs (x );
2191
2203
coordinates [i ] = x ;
0 commit comments