diff options
author | Rachel Dowdall <rjdowdall@gmail.com> | 2014-03-22 17:29:27 +0000 |
---|---|---|
committer | Rachel Dowdall <rjdowdall@gmail.com> | 2014-03-22 17:29:27 +0000 |
commit | cde8631f15db9941986f8d04534e52462a76094b (patch) | |
tree | 56651a2b887a7bfdfef37df391b24d28dac36fc4 /py/objint_mpz.c | |
parent | 721c55dced099a797f0910839c7c4f9ac7599ed4 (diff) | |
download | micropython-cde8631f15db9941986f8d04534e52462a76094b.tar.gz micropython-cde8631f15db9941986f8d04534e52462a76094b.zip |
Fixed modulo operator on ints and mp ints to agree with python. Added intdivmod.c and tests/basics/modulo.py.
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r-- | py/objint_mpz.c | 5 |
1 files changed, 4 insertions, 1 deletions
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; } |