Commits

Philip Jenvey committed e762cce

math.{ceil,floor} now return ints

Comments (0)

Files changed (2)

pypy/module/math/interp_math.py

 def floor(space, w_x):
     """floor(x)
 
-       Return the floor of x as a float.
+       Return the floor of x as an int.
        This is the largest integral value <= x.
     """
+    from pypy.objspace.std.longobject import newlong_from_float
     w_descr = space.lookup(w_x, '__floor__')
     if w_descr is not None:
         return space.get_and_call_function(w_descr, w_x)
     x = _get_double(space, w_x)
-    return space.wrap(math.floor(x))
+    return newlong_from_float(space, math.floor(x))
 
 def sqrt(space, w_x):
     """sqrt(x)
 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.
     """
+    from pypy.objspace.std.longobject import newlong_from_float
     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)
+    return newlong_from_float(space, math1_w(space, math.ceil, w_x))
 
 def sinh(space, w_x):
     """sinh(x)

pypy/module/math/test/test_math.py

             setattr(Z, '__{}__'.format(name), lambda self: i)
             func = getattr(math, name)
             assert func(Z()) == i
+
+    def test_int_results(self):
+        import math
+        for func in math.ceil, math.floor:
+            assert type(func(0.5)) is int
+            raises(OverflowError, func, float('inf'))
+            raises(ValueError, func, float('nan'))