[pypy-svn] pypy default: Some more tests for round(), and a fix.

arigo commits-noreply at bitbucket.org
Mon Feb 7 19:22:21 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r41681:2668082371d2
Date: 2011-02-07 19:21 +0100
http://bitbucket.org/pypy/pypy/changeset/2668082371d2/

Log:	Some more tests for round(), and a fix.

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
@@ -646,10 +646,23 @@
         assert res == 18
 
     def test_round(self):
+        assert round(11.234) == 11.0
+        assert round(11.234, -1) == 10.0
+        assert round(11.234, 0) == 11.0
+        assert round(11.234, 1) == 11.2
+        #
         assert round(5e15-1) == 5e15-1
         assert round(5e15) == 5e15
         assert round(-(5e15-1)) == -(5e15-1)
         assert round(-5e15) == -5e15
+        #
+        inf = 1e200 * 1e200
+        assert round(inf) == inf
+        assert round(-inf) == -inf
+        nan = inf / inf
+        assert repr(round(nan)) == repr(nan)
+        #
+        raises(OverflowError, round, 1.6e308, -308)
 
     def test_vars_obscure_case(self):
         class C_get_vars(object):

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
@@ -182,6 +182,9 @@
         z = (z / pow2) / pow1
     else:
         z *= pow1
+    if isinf(z):
+        raise OperationError(space.w_OverflowError,
+                            space.wrap("rounded value too large to represent"))
     return space.wrap(z)
 #
 round.unwrap_spec = [ObjSpace, float, W_Root]


More information about the Pypy-commit mailing list