[pypy-svn] pypy default: (fijal, arigo)

arigo commits-noreply at bitbucket.org
Thu Jan 20 12:35:44 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r40982:bc9044423405
Date: 2011-01-20 12:35 +0100
http://bitbucket.org/pypy/pypy/changeset/bc9044423405/

Log:	(fijal, arigo)

	round() precision.

diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -645,6 +645,12 @@
         res = ns["test"]([2,3,4])
         assert res == 18
 
+    def test_round(self):
+        assert round(5e15-1) == 5e15-1
+        assert round(5e15) == 5e15
+        assert round(-(5e15-1)) == -(5e15-1)
+        assert round(-5e15) == -5e15
+
 
 class TestInternal:
     def test_execfile(self, space):

diff --git a/pypy/module/__builtin__/operation.py b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -175,6 +175,8 @@
         z = math.floor(y + 0.5)
     else:
         z = math.ceil(y - 0.5)
+    if math.fabs(y-z) == 1.0:   # obscure case, see the test
+        z = y
 
     if ndigits >= 0:
         z = (z / pow2) / pow1


More information about the Pypy-commit mailing list