From cde8631f15db9941986f8d04534e52462a76094b Mon Sep 17 00:00:00 2001 From: Rachel Dowdall Date: Sat, 22 Mar 2014 17:29:27 +0000 Subject: Fixed modulo operator on ints and mp ints to agree with python. Added intdivmod.c and tests/basics/modulo.py. --- py/objint_mpz.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'py/objint_mpz.c') diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 21e3202a95..9c7727ba42 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -102,10 +102,13 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } 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); + // Check signs and do Python style modulo + if (zlhs->neg != zrhs->neg) { + mpz_add_inpl(&res->mpz, &res->mpz, zrhs); + } break; } -- cgit v1.2.3