Skip to content

Commit bbb0843

Browse files
committed
py/objfloat: Fix case of raising 0 to -infinity.
It was raising an exception but it should return infinity.
1 parent b75cb83 commit bbb0843

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

py/objfloat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
293293
break;
294294
case MP_BINARY_OP_POWER:
295295
case MP_BINARY_OP_INPLACE_POWER:
296-
if (lhs_val == 0 && rhs_val < 0) {
296+
if (lhs_val == 0 && rhs_val < 0 && !isinf(rhs_val)) {
297297
goto zero_division_error;
298298
}
299299
if (lhs_val < 0 && rhs_val != MICROPY_FLOAT_C_FUN(floor)(rhs_val)) {

tests/float/builtin_float_pow.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# test builtin pow function with float args
2+
3+
print(pow(0.0, 0.0))
4+
print(pow(0, 1.0))
5+
print(pow(1.0, 1))
6+
print(pow(2.0, 3.0))
7+
print(pow(2.0, -4.0))
8+
9+
print(pow(0.0, float('inf')))
10+
print(pow(0.0, float('-inf')))
11+
print(pow(0.0, float('nan')))

0 commit comments

Comments
 (0)