[pypy-commit] pypy default: int_floordiv

arigo noreply at buildbot.pypy.org
Wed Jul 17 13:51:11 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r65428:ee9c24742973
Date: 2013-07-17 12:32 +0200
http://bitbucket.org/pypy/pypy/changeset/ee9c24742973/

Log:	int_floordiv

diff --git a/pypy/module/__pypy__/interp_intop.py b/pypy/module/__pypy__/interp_intop.py
--- a/pypy/module/__pypy__/interp_intop.py
+++ b/pypy/module/__pypy__/interp_intop.py
@@ -1,5 +1,7 @@
 from pypy.interpreter.gateway import unwrap_spec
 from rpython.rlib.rarithmetic import intmask
+from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.lltypesystem.lloperation import llop
 
 
 @unwrap_spec(n=int, m=int)
@@ -13,3 +15,7 @@
 @unwrap_spec(n=int, m=int)
 def int_mul(space, n, m):
     return space.wrap(intmask(n * m))
+
+ at unwrap_spec(n=int, m=int)
+def int_floordiv(space, n, m):
+    return space.wrap(llop.int_floordiv(lltype.Signed, n, m))
diff --git a/pypy/module/__pypy__/test/test_intop.py b/pypy/module/__pypy__/test/test_intop.py
--- a/pypy/module/__pypy__/test/test_intop.py
+++ b/pypy/module/__pypy__/test/test_intop.py
@@ -40,3 +40,13 @@
         assert intop.int_mul(40, -2) == -80
         assert intop.int_mul(-sys.maxint, -sys.maxint) == (
             self.intmask(sys.maxint ** 2))
+
+    def test_int_floordiv(self):
+        import sys
+        from __pypy__ import intop
+        assert intop.int_floordiv(41, 3) == 13
+        assert intop.int_floordiv(41, -3) == -13
+        assert intop.int_floordiv(-41, 3) == -13
+        assert intop.int_floordiv(-41, -3) == 13
+        assert intop.int_floordiv(-sys.maxint, -1) == sys.maxint
+        assert intop.int_floordiv(sys.maxint, -1) == -sys.maxint


More information about the pypy-commit mailing list