Skip to content

Commit 930f451

Browse files
authored
On path with known exact float, extract the double with the fast macro. (pythonGH-21072)
1 parent fe2a48c commit 930f451

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Modules/mathmodule.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,15 @@ static PyObject *
12561256
math_floor(PyObject *module, PyObject *number)
12571257
/*[clinic end generated code: output=c6a65c4884884b8a input=63af6b5d7ebcc3d6]*/
12581258
{
1259+
double x;
1260+
12591261
_Py_IDENTIFIER(__floor__);
12601262

1261-
if (!PyFloat_CheckExact(number)) {
1263+
if (PyFloat_CheckExact(number)) {
1264+
x = PyFloat_AS_DOUBLE(number);
1265+
}
1266+
else
1267+
{
12621268
PyObject *method = _PyObject_LookupSpecial(number, &PyId___floor__);
12631269
if (method != NULL) {
12641270
PyObject *result = _PyObject_CallNoArg(method);
@@ -1267,11 +1273,10 @@ math_floor(PyObject *module, PyObject *number)
12671273
}
12681274
if (PyErr_Occurred())
12691275
return NULL;
1276+
x = PyFloat_AsDouble(number);
1277+
if (x == -1.0 && PyErr_Occurred())
1278+
return NULL;
12701279
}
1271-
double x = PyFloat_AsDouble(number);
1272-
if (x == -1.0 && PyErr_Occurred())
1273-
return NULL;
1274-
12751280
return PyLong_FromDouble(floor(x));
12761281
}
12771282

0 commit comments

Comments
 (0)