mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #25971: Optimized creating Fractions from floats by 2 times and from
Decimals by 3 times. Unified error messages in float.as_integer_ratio(), Decimal.as_integer_ratio(), and Fraction constructors.
This commit is contained in:
parent
5aab44b301
commit
0d250bc119
5 changed files with 22 additions and 45 deletions
|
@ -1466,14 +1466,14 @@ float_as_integer_ratio(PyObject *v, PyObject *unused)
|
|||
CONVERT_TO_DOUBLE(v, self);
|
||||
|
||||
if (Py_IS_INFINITY(self)) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"Cannot pass infinity to float.as_integer_ratio.");
|
||||
return NULL;
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"cannot convert Infinity to integer ratio");
|
||||
return NULL;
|
||||
}
|
||||
if (Py_IS_NAN(self)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Cannot pass NaN to float.as_integer_ratio.");
|
||||
return NULL;
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"cannot convert NaN to integer ratio");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyFPE_START_PROTECT("as_integer_ratio", goto error);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue