Author: Timo Paulssen <timona...@perpetuum-immobile.de>
Branch: py3k-ceil-floor
Changeset: r59061:739ba9767011
Date: 2012-11-23 00:58 +0100
http://bitbucket.org/pypy/pypy/changeset/739ba9767011/

Log:    math.ceil behaves a lot like cpython now.

diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -256,7 +256,8 @@
     w_descr = space.lookup(w_x, '__ceil__')
     if w_descr is not None:
         return space.get_and_call_function(w_descr, w_x)
-    return math1(space, math.ceil, w_x)
+    w_ceil_float_result = space.wrap(math.ceil(space.float_w(w_x)))
+    return space.call_function(space.w_int, w_ceil_float_result)
 
 def sinh(space, w_x):
     """sinh(x)
diff --git a/pypy/module/math/test/test_direct.py 
b/pypy/module/math/test/test_direct.py
--- a/pypy/module/math/test/test_direct.py
+++ b/pypy/module/math/test/test_direct.py
@@ -21,7 +21,7 @@
 
 
 unary_math_functions = ['acos', 'asin', 'atan',
-                        'ceil', 'cos', 'cosh', 'exp', 'fabs', 'floor',
+                        'cos', 'cosh', 'exp', 'fabs', 'floor',
                         'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'log', 'log10',
                         'acosh', 'asinh', 'atanh', 'log1p', 'expm1']
 binary_math_functions = ['atan2', 'fmod', 'hypot', 'pow']
@@ -86,8 +86,6 @@
         ('atan', (-INFINITY,), -math.pi / 2),
         ('atanh', (INFINITY,), ValueError),
         ('atanh', (-INFINITY,), ValueError),
-        ('ceil', (INFINITY,), positiveinf),
-        ('ceil', (-INFINITY,), negativeinf),
         ('cos', (INFINITY,), ValueError),
         ('cos', (-INFINITY,), ValueError),
         ('cosh', (INFINITY,), positiveinf),
diff --git a/pypy/module/math/test/test_math.py 
b/pypy/module/math/test/test_math.py
--- a/pypy/module/math/test/test_math.py
+++ b/pypy/module/math/test/test_math.py
@@ -3,10 +3,6 @@
 from pypy.module.math.test import test_direct
 
 # taken from cpython test case test/test_math.py
-eps = 1E-05
-
-def almost_equal(a, b):
-    return abs(a-b) <= eps
 
 class AppTestMath:
     spaceconfig = dict(usemodules=['math', 'struct'])
@@ -294,6 +290,11 @@
             assert func(Z()) == i
 
     def test_ceil(self):
+        eps = 1E-05
+
+        def almost_equal(a, b):
+            return abs(a-b) <= eps
+        # adapted from the cpython test case
         import math
         raises(TypeError, math.ceil)
         assert type(math.ceil(0.4)) is int
@@ -307,7 +308,7 @@
         class TestCeil:
             def __ceil__(self):
                 return 42
-        class TestNoCell:
+        class TestNoCeil:
             pass
         assert almost_equal(math.ceil(TestCeil()), 42)
         raises(TypeError, math.ceil, TestNoCeil())
@@ -316,3 +317,14 @@
         t.__ceil__ = lambda *args: args
         raises(TypeError, math.ceil, t)
         raises(TypeError, math.ceil, t, 0)
+
+        # observed in a cpython interactive shell
+        raises(OverflowError, math.ceil, float("inf"))
+        raises(OverflowError, math.ceil, float("-inf"))
+        raises(ValueError, math.ceil, float("nan"))
+
+        class StrangeCeil:
+            def __ceil__(self):
+                return "this is a string"
+
+        assert math.ceil(StrangeCeil()) == "this is a string"
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to