Timo Paulssen avatar Timo Paulssen committed 6a1c5f8

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

Comments (0)

Files changed (2)

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):

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.