diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-01-28 21:25:58 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-01-28 21:25:58 (GMT) |
commit | 1124e71368c73b592020b4896fb1c5d371efbcef (patch) | |
tree | 3b6b7514894a95a88cfcd3a232c6e074c23bc61e /Python | |
parent | 9de29afa7c083a24a5eabfbbc9bb3515e7026745 (diff) | |
download | cpython-1124e71368c73b592020b4896fb1c5d371efbcef.zip cpython-1124e71368c73b592020b4896fb1c5d371efbcef.tar.gz cpython-1124e71368c73b592020b4896fb1c5d371efbcef.tar.bz2 |
Issue #4707: round(x, n) now returns an integer when x is an integer.
Previously it returned a float.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index f87fdd2..5597bc7 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1717,15 +1717,14 @@ For most object types, eval(repr(object)) == object."); 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) @@ -1746,15 +1745,14 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds) 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\ |