diff options
author | Rachel Dowdall <rjdowdall@gmail.com> | 2014-03-22 20:29:56 +0000 |
---|---|---|
committer | Rachel Dowdall <rjdowdall@gmail.com> | 2014-03-22 20:29:56 +0000 |
commit | 2d15deebdcf7d6fb8f78907e0c6ca9cb9c2aa000 (patch) | |
tree | 4dba583967542dd95ebdf3f62865f9bb56db2350 /py/compile.c | |
parent | cde8631f15db9941986f8d04534e52462a76094b (diff) | |
download | micropython-2d15deebdcf7d6fb8f78907e0c6ca9cb9c2aa000.tar.gz micropython-2d15deebdcf7d6fb8f78907e0c6ca9cb9c2aa000.zip |
Fixed floor division on mp ints and small ints. Added a floordivide test case.
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/py/compile.c b/py/compile.c index 4eab094230..0a10b81768 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <string.h> #include <assert.h> +#include <math.h> #include "misc.h" #include "mpconfig.h" @@ -141,12 +142,13 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) { } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_SLASH)) { ; // pass } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_PERCENT)) { - // XXX implement this properly as Python's % operator acts differently to C's - //pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 % arg1); pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, python_modulo(arg0, arg1)); } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_DBL_SLASH)) { - // XXX implement this properly as Python's // operator acts differently to C's - pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, arg0 / arg1); + //pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, + // floor((mp_float_t)arg0 / arg1)); + pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, + python_floor_divide(arg0, arg1)); + } else { // shouldn't happen assert(0); |