Mercurial > cpython-lru_cache-weakref
diff Objects/floatobject.c @ 80479:ff300ccd119d 2.7
Issue #9742: Sneaky fix for build failure on Solaris 9.
| author | Mark Dickinson <mdickinson@enthought.com> |
|---|---|
| date | Sat, 17 Nov 2012 20:18:52 +0000 |
| parents | eaf553b063a7 |
| children | ca8e75190402 |
line wrap: on
line diff
--- a/Objects/floatobject.c Sat Nov 17 21:14:58 2012 +0100 +++ b/Objects/floatobject.c Sat Nov 17 20:18:52 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 + (x > 0.0 ? 0.5 : -0.5); + 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:
