Skip to content

Commit 4b8ec52

Browse files
committed
py/objfloat: Raise ZeroDivisionError for 0 to negative power.
1 parent 05c70fd commit 4b8ec52

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

py/objfloat.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
228228
}
229229
break;
230230
case MP_BINARY_OP_POWER:
231-
case MP_BINARY_OP_INPLACE_POWER: lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val); break;
231+
case MP_BINARY_OP_INPLACE_POWER:
232+
if (lhs_val == 0 && rhs_val < 0) {
233+
goto zero_division_error;
234+
}
235+
lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val);
236+
break;
232237
case MP_BINARY_OP_DIVMOD: {
233238
if (rhs_val == 0) {
234239
goto zero_division_error;

0 commit comments

Comments
 (0)