]> granicus.if.org Git - python/commitdiff
Issue #1869: Fix a couple of minor round() issues.
authorMark Dickinson <dickinsm@gmail.com>
Sat, 18 Apr 2009 14:59:42 +0000 (14:59 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sat, 18 Apr 2009 14:59:42 +0000 (14:59 +0000)
Lib/test/test_builtin.py
Misc/NEWS
Python/bltinmodule.c

index 6671f2c02ebb2611314fcae3c0e5494205e0c0f0..19ce9ec83d39ce82b6b0b6c4ce9c167927050166 100644 (file)
@@ -1224,6 +1224,9 @@ class BuiltinTest(unittest.TestCase):
         self.assertEqual(round(-5.5), -6)
         self.assertEqual(round(-6.5), -7)
 
+        # Issue #1869: integral floats should remain unchanged
+        self.assertEqual(round(5e15+1), 5e15+1)
+
         # Check behavior on ints
         self.assertEqual(round(0), 0)
         self.assertEqual(round(8), 8)
index f226eb1a39ec8a1646e076871ab6c2e16716a964..58197de04901acf6dd4b7dc9c0480d06b4d0ad3e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
 Core and Builtins
 -----------------
 
+- Issue #1869: fix a couple of minor round() issues.  round(5e15+1)
+    was giving 5e15+2; round(-0.0) was losing the sign of the zero.
+
 - Issue #5759: float() didn't call __float__ on str subclasses.
 
 - Issue #5704: the "-3" command-line option now implies "-t".
index 0f3392a56f8532fedf861edc229f8f043f709823..8f6e85555a82693636fd3e3fbbbfdd4a9509b377 100644 (file)
@@ -2081,10 +2081,7 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
                number /= f;
        else
                number *= f;
-       if (number >= 0.0)
-               number = floor(number + 0.5);
-       else
-               number = ceil(number - 0.5);
+       number = round(number);
        if (ndigits < 0)
                number *= f;
        else