mirror of
https://github.com/python/cpython.git
synced 2025-11-27 21:55:35 +00:00
On path with known exact float, extract the double with the fast macro. (GH-21072)
This commit is contained in:
parent
fe2a48c605
commit
930f4518ae
1 changed files with 10 additions and 5 deletions
|
|
@ -1256,9 +1256,15 @@ static PyObject *
|
||||||
math_floor(PyObject *module, PyObject *number)
|
math_floor(PyObject *module, PyObject *number)
|
||||||
/*[clinic end generated code: output=c6a65c4884884b8a input=63af6b5d7ebcc3d6]*/
|
/*[clinic end generated code: output=c6a65c4884884b8a input=63af6b5d7ebcc3d6]*/
|
||||||
{
|
{
|
||||||
|
double x;
|
||||||
|
|
||||||
_Py_IDENTIFIER(__floor__);
|
_Py_IDENTIFIER(__floor__);
|
||||||
|
|
||||||
if (!PyFloat_CheckExact(number)) {
|
if (PyFloat_CheckExact(number)) {
|
||||||
|
x = PyFloat_AS_DOUBLE(number);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
PyObject *method = _PyObject_LookupSpecial(number, &PyId___floor__);
|
PyObject *method = _PyObject_LookupSpecial(number, &PyId___floor__);
|
||||||
if (method != NULL) {
|
if (method != NULL) {
|
||||||
PyObject *result = _PyObject_CallNoArg(method);
|
PyObject *result = _PyObject_CallNoArg(method);
|
||||||
|
|
@ -1267,11 +1273,10 @@ math_floor(PyObject *module, PyObject *number)
|
||||||
}
|
}
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
x = PyFloat_AsDouble(number);
|
||||||
double x = PyFloat_AsDouble(number);
|
|
||||||
if (x == -1.0 && PyErr_Occurred())
|
if (x == -1.0 && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
return PyLong_FromDouble(floor(x));
|
return PyLong_FromDouble(floor(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue