Author: Armin Rigo <ar...@tunes.org>
Branch: py3.6
Changeset: r98283:22226b5e0778
Date: 2019-12-12 23:21 +0100
http://bitbucket.org/pypy/pypy/changeset/22226b5e0778/

Log:    more like 8e5e71e1a26e: avoids making W_LongObjects for result that
        most often fit in a W_IntObject

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
@@ -156,12 +156,12 @@
        Return the floor of x as an int.
        This is the largest integral value <= x.
     """
-    from pypy.objspace.std.longobject import newlong_from_float
+    from pypy.objspace.std.floatobject import newint_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 newlong_from_float(space, math.floor(x))
+    return newint_from_float(space, math.floor(x))
 
 def sqrt(space, w_x):
     """sqrt(x)
@@ -259,11 +259,11 @@
        Return the ceiling of x as an int.
        This is the smallest integral value >= x.
     """
-    from pypy.objspace.std.longobject import newlong_from_float
+    from pypy.objspace.std.floatobject import newint_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 newlong_from_float(space, math1_w(space, math.ceil, w_x))
+    return newint_from_float(space, math1_w(space, math.ceil, w_x))
 
 def sinh(space, w_x):
     """sinh(x)
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -145,7 +145,8 @@
         return space.w_NotImplemented
     return func_with_new_name(_compare, 'descr_' + opname)
 
-def _newint_from_float(space, floatval):
+def newint_from_float(space, floatval):
+    """This is also used from module/math/interp_math.py"""
     try:
         value = ovfcheck_float_to_int(floatval)
     except OverflowError:
@@ -448,7 +449,7 @@
         return W_FloatObject(a)
 
     def descr_trunc(self, space):
-        return _newint_from_float(space, self.floatval)
+        return newint_from_float(space, self.floatval)
 
     def descr_neg(self, space):
         return W_FloatObject(-self.floatval)
@@ -938,7 +939,7 @@
         if math.fabs(x - rounded) == 0.5:
             # halfway case: round to even
             rounded = 2.0 * rfloat.round_away(x / 2.0)
-        return _newint_from_float(space, rounded)
+        return newint_from_float(space, rounded)
 
     # interpret 2nd argument as a Py_ssize_t; clip on overflow
     ndigits = space.getindex_w(w_ndigits, None)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to