Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r59386:e762ccefabae
Date: 2012-12-10 13:41 -0800
http://bitbucket.org/pypy/pypy/changeset/e762ccefabae/

Log:    math.{ceil,floor} now return ints

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
@@ -158,14 +158,15 @@
 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)
@@ -250,13 +251,14 @@
 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)
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
@@ -307,3 +307,10 @@
             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'))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to