mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
round(0, "ermintrude") succeeded instead of producing a TypeError. Fix this.
This commit is contained in:
parent
9dd5e16c5d
commit
bce783757f
2 changed files with 9 additions and 4 deletions
|
@ -2130,10 +2130,6 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
kwlist, &x, &o_ndigits))
|
||||
return NULL;
|
||||
|
||||
/* nans, infinities and zeros round to themselves */
|
||||
if (!Py_IS_FINITE(x) || x == 0.0)
|
||||
return PyFloat_FromDouble(x);
|
||||
|
||||
if (o_ndigits == NULL) {
|
||||
/* second argument defaults to 0 */
|
||||
ndigits = 0;
|
||||
|
@ -2145,6 +2141,10 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* nans, infinities and zeros round to themselves */
|
||||
if (!Py_IS_FINITE(x) || x == 0.0)
|
||||
return PyFloat_FromDouble(x);
|
||||
|
||||
/* Deal with extreme values for ndigits. For ndigits > NDIGITS_MAX, x
|
||||
always rounds to itself. For ndigits < NDIGITS_MIN, x always
|
||||
rounds to +-0.0. Here 0.30103 is an upper bound for log10(2). */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue