# HG changeset patch # User Philip Jenvey # Date 1355175681 28800 # Branch py3k # Node ID e762ccefabae4d101efb34ed2cd410e9bb1812fb # Parent 2de9445698d18edbf6ee15e789e7fc14f392e925 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'))