From 2d7ff071755f869bff1814dd886add1fe7000062 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 20 Mar 2014 16:28:41 +0000 Subject: [PATCH] py: Add mpz modulo operation. --- py/objint_mpz.c | 11 ++++++++--- tests/basics/int-big-mod.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/basics/int-big-mod.py 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)