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/runtime.c | |
parent | 721c55dced099a797f0910839c7c4f9ac7599ed4 (diff) |
Fixed modulo operator on ints and mp ints to agree with python. Added intdivmod.c and tests/basics/modulo.py.
Diffstat (limited to 'py/runtime.c')
-rw-r--r-- | py/runtime.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/py/runtime.c b/py/runtime.c index 1cc1c2e6b..95c3a4415 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -18,6 +18,7 @@ #include "builtin.h" #include "objarray.h" #include "bc.h" +#include "intdivmod.h" #if 0 // print debugging info #define DEBUG_PRINT (1) @@ -666,10 +667,12 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) { case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val); #endif - // TODO implement modulo as specified by Python case RT_BINARY_OP_MODULO: - case RT_BINARY_OP_INPLACE_MODULO: lhs_val %= rhs_val; break; - + case RT_BINARY_OP_INPLACE_MODULO: + { + lhs_val = python_modulo(lhs_val, rhs_val); + break; + } case RT_BINARY_OP_POWER: case RT_BINARY_OP_INPLACE_POWER: if (rhs_val < 0) { |