summaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-31 12:01:09 +0100
committerDamien George <damien.p.george@gmail.com>2014-03-31 12:01:09 +0100
commit1aa2c1026348b057dca2008a165c6d4341a66606 (patch)
tree2ff1af1263d3947631e1af33697393e699f6d383 /py/runtime.c
parent523b575039d96d63669ad8c1fa318ba4db046aca (diff)
parent6ded55a61f6bbf007d518fc4531287de08fe51c4 (diff)
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 7e0287945..f827fd831 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -348,13 +348,20 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
}
case MP_BINARY_OP_FLOOR_DIVIDE:
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
- {
+ if (rhs_val == 0) {
+ goto zero_division;
+ }
lhs_val = python_floor_divide(lhs_val, rhs_val);
break;
- }
+
#if MICROPY_ENABLE_FLOAT
case MP_BINARY_OP_TRUE_DIVIDE:
- case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val);
+ case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
+ if (rhs_val == 0) {
+zero_division:
+ nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "division by zero"));
+ }
+ return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val);
#endif
case MP_BINARY_OP_MODULO: