diff options
author | Damien George <damien.p.george@gmail.com> | 2017-09-26 12:57:51 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-09-26 12:57:51 +1000 |
commit | bdc6e86e079dd8a82e9ead1d4041c2e17c882437 (patch) | |
tree | 07a5e178f400151ff6cd6d81752ebe0f3df0ae49 /py/objfloat.c | |
parent | 62849b7010abffb7b0a9c9875930efe7cb77519c (diff) |
py/objfloat: Support raising a negative number to a fractional power.
This returns a complex number, following CPython behaviour. For ports that
don't have complex numbers enabled this will raise a ValueError which gives
a fail-safe for scripts that were written assuming complex numbers exist.
Diffstat (limited to 'py/objfloat.c')
-rw-r--r-- | py/objfloat.c | 7 |
1 files changed, 7 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: { |