diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-22 20:26:17 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-22 20:26:17 +0000 |
commit | a6d53188b7db85af9dc93186e4f36b7009084ea6 (patch) | |
tree | 38b2f947a5d714c5ee79a99f164d94aa780802a5 /py/objfloat.c | |
parent | 463997f638b1c3e5fdb3e0e8a9c4339b0e712f8a (diff) | |
parent | 56402796d87f75fbb9e42fc9e3c0adc027fb7c98 (diff) | |
download | micropython-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/objfloat.c')
-rw-r--r-- | py/objfloat.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/py/objfloat.c b/py/objfloat.c index c51e13e7a1..c4567c4a38 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -1,5 +1,6 @@ #include <stdlib.h> #include <assert.h> +#include <math.h> #include "nlr.h" #include "misc.h" @@ -107,8 +108,12 @@ mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs_in) { case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: val = lhs_val / rhs_val; break; */ case RT_BINARY_OP_TRUE_DIVIDE: - case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: lhs_val /= rhs_val; break; - + case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: + lhs_val /= rhs_val; + if (isinf(lhs_val)){ // check for division by zero + nlr_jump(mp_obj_new_exception_msg(&mp_type_ZeroDivisionError, "float division by zero")); + } + break; case RT_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val); case RT_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val); case RT_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); |