]> granicus.if.org Git - python/commitdiff
Issue #9742: Sneaky fix for build failure on Solaris 9.
authorMark Dickinson <mdickinson@enthought.com>
Sat, 17 Nov 2012 20:18:52 +0000 (20:18 +0000)
committerMark Dickinson <mdickinson@enthought.com>
Sat, 17 Nov 2012 20:18:52 +0000 (20:18 +0000)
Objects/floatobject.c

index 30f7b3489da11b7e9a9726e26b8944ffddd42df9..ba867ef149f8c869ba35150e4128011f47f25244 100644 (file)
@@ -1088,6 +1088,15 @@ _Py_double_round(double x, int ndigits) {
     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: