[pypy-commit] pypy default: int_mul

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


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r65427:941cffc3ef01
Date: 2013-07-17 12:26 +0200
http://bitbucket.org/pypy/pypy/changeset/941cffc3ef01/

Log:	int_mul

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
@@ -9,3 +9,7 @@
 @unwrap_spec(n=int, m=int)
 def int_sub(space, n, m):
     return space.wrap(intmask(n - m))
+
+ at unwrap_spec(n=int, m=int)
+def int_mul(space, n, m):
+    return space.wrap(intmask(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
@@ -3,6 +3,23 @@
 class AppTestIntOp:
     spaceconfig = dict(usemodules=['__pypy__'])
 
+    def w_intmask(self, n):
+        import sys
+        n &= (sys.maxint*2+1)
+        if n > sys.maxint:
+            n -= 2*(sys.maxint+1)
+        return int(n)
+
+    def test_intmask(self):
+        import sys
+        assert self.intmask(sys.maxint) == sys.maxint
+        assert self.intmask(sys.maxint+1) == -sys.maxint-1
+        assert self.intmask(-sys.maxint-2) == sys.maxint
+        N = 2 ** 128
+        assert self.intmask(N+sys.maxint) == sys.maxint
+        assert self.intmask(N+sys.maxint+1) == -sys.maxint-1
+        assert self.intmask(N-sys.maxint-2) == sys.maxint
+
     def test_int_add(self):
         import sys
         from __pypy__ import intop
@@ -16,3 +33,10 @@
         assert intop.int_sub(40, -2) == 42
         assert intop.int_sub(sys.maxint, -1) == -sys.maxint-1
         assert intop.int_sub(-2, sys.maxint) == sys.maxint
+
+    def test_int_mul(self):
+        import sys
+        from __pypy__ import intop
+        assert intop.int_mul(40, -2) == -80
+        assert intop.int_mul(-sys.maxint, -sys.maxint) == (
+            self.intmask(sys.maxint ** 2))


More information about the pypy-commit mailing list