py: Add mpz modulo operation.

This commit is contained in:
Damien George 2014-03-20 16:28:41 +00:00
parent c412998c49
commit 2d7ff07175
2 changed files with 18 additions and 3 deletions

View File

@ -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:

View File

@ -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)