diff -r 8296b686c6de Objects/floatobject.c --- a/Objects/floatobject.c Wed Oct 31 20:38:52 2012 +0000 +++ b/Objects/floatobject.c Wed Oct 31 22:19:35 2012 +0000 @@ -1088,6 +1088,15 @@ PyObject *result = NULL; _Py_SET_53BIT_PRECISION_HEADER; + /* Easy path for the common case ndigits == 0. */ + if (ndigits == 0) { + rounded = round(x); + if (fabs(rounded-x) == 0.5) + /* halfway between two integers; use round-away-from-zero */ + rounded = x + copysign(0.5, x); + return PyFloat_FromDouble(rounded); + } + /* The basic idea is very simple: convert and round the double to a decimal string using _Py_dg_dtoa, then convert that decimal string back to a double with _Py_dg_strtod. There's one minor difficulty: