Author: Timo Paulssen <[email protected]>
Branch: py3k-ceil-floor
Changeset: r59071:6a1c5f8e7931
Date: 2012-11-23 13:28 +0100
http://bitbucket.org/pypy/pypy/changeset/6a1c5f8e7931/
Log: use math1, test custom classes with __float__, fix docstring.
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
@@ -164,19 +164,19 @@
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):
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
@@ -325,6 +325,12 @@
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
@@ -364,3 +370,9 @@
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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit