8000 py/objcomplex: Correctly handle case of 0j to power of something. · nickzoic/micropython-esp32@3ed0e5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ed0e5e

Browse files
committed
py/objcomplex: Correctly handle case of 0j to power of something.
0j to the power of negative now raises ZeroDivisionError, and 0j to the power of positive returns 0.
1 parent 4b8ec52 commit 3ed0e5e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

py/objcomplex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
222222
// = exp(x3)*(cos(y3) + i*sin(y3))
223223
mp_float_t abs1 = MICROPY_FLOAT_C_FUN(sqrt)(lhs_real*lhs_real + lhs_imag*lhs_imag);
224224
if (abs1 == 0) {
225-
if (rhs_imag == 0) {
226-
lhs_real = 1;
225+
if (rhs_imag == 0 && rhs_real >= 0) {
226+
lhs_real = 1 ? rhs_real == 0 : 0;
227227
rhs_real = 0;
228228
} else {
229229
mp_raise_msg(&mp_type_ZeroDivisionError, "0.0 to a complex power");

0 commit comments

Comments
 (0)
0