From 4b8ec5256d3d27b6cd69afeda62d645df4719ea9 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 3 Feb 2017 00:01:37 +1100 Subject: [PATCH] py/objfloat: Raise ZeroDivisionError for 0 to negative power. --- py/objfloat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/py/objfloat.c b/py/objfloat.c index 73d07feac8..9292490a9e 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -228,7 +228,12 @@ mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_i } break; case MP_BINARY_OP_POWER: - case MP_BINARY_OP_INPLACE_POWER: lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val); break; + case MP_BINARY_OP_INPLACE_POWER: + if (lhs_val == 0 && rhs_val < 0) { + goto zero_division_error; + } + lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val); + break; case MP_BINARY_OP_DIVMOD: { if (rhs_val == 0) { goto zero_division_error;