Commits

Timo Paulssen  committed 6a1c5f8

use math1, test custom classes with __float__, fix docstring.

  • Participants
  • Parent commits 0c17239
  • Branches py3k-ceil-floor

Comments (0)

Files changed (2)

File pypy/module/math/interp_math.py

     w_descr = space.lookup(w_x, '__floor__')
     if w_descr is not None:
         return space.get_and_call_function(w_descr, w_x)
-    w_floor_float_result = space.wrap(math.floor(space.float_w(w_x)))
+    w_floor_float_result = math1(space, math.floor, w_x)
     return space.call_function(space.w_int, w_floor_float_result)
 
 def ceil(space, w_x):
     """ceil(x)
 
-       Return the ceiling of x as a float.
+       Return the ceiling of x as an int.
        This is the smallest integral value >= x.
     """
     w_descr = space.lookup(w_x, '__ceil__')
     if w_descr is not None:
         return space.get_and_call_function(w_descr, w_x)
-    w_ceil_float_result = space.wrap(math.ceil(space.float_w(w_x)))
+    w_ceil_float_result = math1(space, math.ceil, w_x)
     return space.call_function(space.w_int, w_ceil_float_result)
 
 def sqrt(space, w_x):

File pypy/module/math/test/test_math.py

 
         assert math.ceil(StrangeCeil()) == "this is a string"
 
+        class CustomFloat:
+            def __float__(self):
+                return 99.9
+
+        assert math.ceil(CustomFloat()) == 100
+
     def test_floor(self):
         # adapted from the cpython test case
         import math
         assert math.floor(StrangeCeil()) == "this is a string"
 
         assert math.floor(1.23e167) - 1.23e167 == 0.0
+ 
+        class CustomFloat:
+            def __float__(self):
+                return 99.9
+
+        assert math.floor(CustomFloat()) == 99