Source

pypy / pypy / module / math / interp_math.py

Diff from to

File pypy/module/math/interp_math.py

 
 def trunc(space, w_x):
     """Truncate x."""
+    w_descr = space.lookup(w_x, '__trunc__')
+    if w_descr is not None:
+        return space.get_and_call_function(w_descr, w_x)
     return space.trunc(w_x)
 
 def copysign(space, w_x, w_y):
        Return the floor of x as a float.
        This is the largest integral value <= x.
     """
+    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 the ceiling of x as a float.
        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)
     return math1(space, math.ceil, w_x)
 
 def sinh(space, w_x):