summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-20 16:28:41 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-20 16:28:41 +0000
commit2d7ff071755f869bff1814dd886add1fe7000062 (patch)
treef7b60495037a609b243767fb851e4d59f4a2fc47
parentc412998c491dcad3d6fa9f7c9797fedaebd25798 (diff)
downloadmicropython-2d7ff071755f869bff1814dd886add1fe7000062.tar.gz
micropython-2d7ff071755f869bff1814dd886add1fe7000062.zip
py: Add mpz modulo operation.
-rw-r--r--py/objint_mpz.c11
-rw-r--r--tests/basics/int-big-mod.py10
2 files changed, 18 insertions, 3 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 342e8ec276..21e3202a95 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -100,9 +100,14 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mpz_deinit(&rem);
break;
}
-
- //case RT_BINARY_OP_MODULO:
- //case RT_BINARY_OP_INPLACE_MODULO:
+ case RT_BINARY_OP_MODULO:
+ case RT_BINARY_OP_INPLACE_MODULO: {
+ // TODO check that this operation matches the CPython operation
+ mpz_t quo; mpz_init_zero(&quo);
+ mpz_divmod_inpl(&quo, &res->mpz, zlhs, zrhs);
+ mpz_deinit(&quo);
+ break;
+ }
//case RT_BINARY_OP_AND:
//case RT_BINARY_OP_INPLACE_AND:
diff --git a/tests/basics/int-big-mod.py b/tests/basics/int-big-mod.py
new file mode 100644
index 0000000000..77c0ffc468
--- /dev/null
+++ b/tests/basics/int-big-mod.py
@@ -0,0 +1,10 @@
+# test % operation on big integers
+
+delta = 100000000000000000000000000000012345
+
+for i in range(11):
+ for j in range(11):
+ x = delta * (i)# - 5) # TODO reinstate negative number test when % is working with sign correctly
+ y = delta * (j)# - 5) # TODO reinstate negative number test when % is working with sign correctly
+ if y != 0:
+ print(x % y)