Commits

Timo Paulssen committed 739ba97

math.ceil behaves a lot like cpython now.

Comments (0)

Files changed (3)

pypy/module/math/interp_math.py

     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)

pypy/module/math/test/test_direct.py

 
 
 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']
         ('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),

pypy/module/math/test/test_math.py

 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'])
             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
         class TestCeil:
             def __ceil__(self):
                 return 42
-        class TestNoCell:
+        class TestNoCeil:
             pass
         assert almost_equal(math.ceil(TestCeil()), 42)
         raises(TypeError, math.ceil, TestNoCeil())
         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"