mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue 19933: Provide default argument for ndigits in round. Patch by Vajrasky Kok.
This commit is contained in:
parent
807b80d4ec
commit
cb39d1f466
4 changed files with 16 additions and 4 deletions
|
@ -986,8 +986,9 @@ float_round(PyObject *v, PyObject *args)
|
|||
x = PyFloat_AsDouble(v);
|
||||
if (!PyArg_ParseTuple(args, "|O", &o_ndigits))
|
||||
return NULL;
|
||||
if (o_ndigits == NULL) {
|
||||
/* single-argument round: round to nearest integer */
|
||||
if (o_ndigits == NULL || o_ndigits == Py_None) {
|
||||
/* single-argument round or with None ndigits:
|
||||
* round to nearest integer */
|
||||
rounded = round(x);
|
||||
if (fabs(x-rounded) == 0.5)
|
||||
/* halfway case: round to even */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue