summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-04-18 14:59:42 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-04-18 14:59:42 (GMT)
commit1bdf7e9caba735ba404d49026dacd67636ea5c5f (patch)
tree9012599bfe03eaae427416760ab557002a4bb1e5
parent8e5446f902c58a48796c1f0e25a263b7268afe34 (diff)
downloadcpython-1bdf7e9caba735ba404d49026dacd67636ea5c5f.zip
cpython-1bdf7e9caba735ba404d49026dacd67636ea5c5f.tar.gz
cpython-1bdf7e9caba735ba404d49026dacd67636ea5c5f.tar.bz2
Issue #1869: Fix a couple of minor round() issues.
-rw-r--r--Lib/test/test_builtin.py3
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/bltinmodule.c5
3 files changed, 7 insertions, 4 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 6671f2c..19ce9ec 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -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)
diff --git a/Misc/NEWS b/Misc/NEWS
index f226eb1..58197de 100644
--- 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".
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 0f3392a5..8f6e855 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -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