summaryrefslogtreecommitdiffstatshomepage
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-22 20:26:17 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-22 20:26:17 +0000
commita6d53188b7db85af9dc93186e4f36b7009084ea6 (patch)
tree38b2f947a5d714c5ee79a99f164d94aa780802a5 /py/compile.c
parent463997f638b1c3e5fdb3e0e8a9c4339b0e712f8a (diff)
parent56402796d87f75fbb9e42fc9e3c0adc027fb7c98 (diff)
downloadmicropython-a6d53188b7db85af9dc93186e4f36b7009084ea6.tar.gz
micropython-a6d53188b7db85af9dc93186e4f36b7009084ea6.zip
Merge pull request #359 from rjdowdall/master
Fixed some math functions and added more exceptions.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/py/compile.c b/py/compile.c
index bb688d5d8e..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"
@@ -15,6 +16,7 @@
#include "obj.h"
#include "compile.h"
#include "runtime.h"
+#include "intdivmod.h"
// TODO need to mangle __attr names
@@ -140,11 +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);