Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 51146:9c1f06b273f7 3.0
Merged revisions 69068 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r69068 | mark.dickinson | 2009-01-28 21:25:58 +0000 (Wed, 28 Jan 2009) | 3 lines
Issue #4707: round(x, n) now returns an integer when x is an integer.
Previously it returned a float.
........
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Wed, 28 Jan 2009 21:41:53 +0000 |
| parents | c7abfab4dcdb |
| children | 0162cd4f55be |
line wrap: on
line diff
--- a/Python/bltinmodule.c Wed Jan 28 21:06:01 2009 +0000 +++ b/Python/bltinmodule.c Wed Jan 28 21:41:53 2009 +0000 @@ -1718,15 +1718,14 @@ static PyObject * builtin_round(PyObject *self, PyObject *args, PyObject *kwds) { -#define UNDEF_NDIGITS (-0x7fffffff) /* Unlikely ndigits value */ static PyObject *round_str = NULL; - int ndigits = UNDEF_NDIGITS; + PyObject *ndigits = NULL; static char *kwlist[] = {"number", "ndigits", 0}; PyObject *number, *round; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i:round", - kwlist, &number, &ndigits)) - return NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round", + kwlist, &number, &ndigits)) + return NULL; if (Py_TYPE(number)->tp_dict == NULL) { if (PyType_Ready(Py_TYPE(number)) < 0) @@ -1747,15 +1746,14 @@ return NULL; } - if (ndigits == UNDEF_NDIGITS) - return PyObject_CallFunction(round, "O", number); + if (ndigits == NULL) + return PyObject_CallFunction(round, "O", number); else - return PyObject_CallFunction(round, "Oi", number, ndigits); -#undef UNDEF_NDIGITS + return PyObject_CallFunction(round, "OO", number, ndigits); } PyDoc_STRVAR(round_doc, -"round(number[, ndigits]) -> floating point number\n\ +"round(number[, ndigits]) -> number\n\ \n\ Round a number to a given precision in decimal digits (default 0 digits).\n\ This returns an int when called with one argument, otherwise the\n\
