summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--py/objfloat.c7
-rw-r--r--tests/float/complex1.py4
2 files changed, 11 insertions, 0 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index 55a9379ff..0831be3fd 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -298,6 +298,13 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
if (lhs_val == 0 && rhs_val < 0) {
goto zero_division_error;
}
+ if (lhs_val < 0 && rhs_val != MICROPY_FLOAT_C_FUN(floor)(rhs_val)) {
+ #if MICROPY_PY_BUILTINS_COMPLEX
+ return mp_obj_complex_binary_op(MP_BINARY_OP_POWER, lhs_val, 0, rhs_in);
+ #else
+ mp_raise_ValueError("complex values not supported");
+ #endif
+ }
lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val);
break;
case MP_BINARY_OP_DIVMOD: {
diff --git a/tests/float/complex1.py b/tests/float/complex1.py
index 7f0b317b3..854410545 100644
--- a/tests/float/complex1.py
+++ b/tests/float/complex1.py
@@ -53,6 +53,10 @@ print(type(hash(1j)))
# float on lhs should delegate to complex
print(1.2 + 3j)
+# negative base and fractional power should create a complex
+ans = (-1) ** 2.3; print("%.5g %.5g" % (ans.real, ans.imag))
+ans = (-1.2) ** -3.4; print("%.5g %.5g" % (ans.real, ans.imag))
+
# check printing of inf/nan
print(float('nan') * 1j)
print(float('inf') * (1 + 1j))