From 04552ff71b6c722b21597d93481f024c72457cef Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 25 Jul 2017 11:49:22 +1000 Subject: py: Implement raising a big-int to a negative power. Before this patch raising a big-int to a negative power would just return 0. Now it returns a floating-point number with the correct value. --- py/objint_longlong.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'py/objint_longlong.c') diff --git a/py/objint_longlong.c b/py/objint_longlong.c index eb80407bc..1d184a7dc 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -191,6 +191,13 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { case MP_BINARY_OP_POWER: case MP_BINARY_OP_INPLACE_POWER: { + if (rhs_val < 0) { + #if MICROPY_PY_BUILTINS_FLOAT + return mp_obj_float_binary_op(op, lhs_val, rhs_in); + #else + mp_raise_ValueError("negative power with no float support"); + #endif + } long long ans = 1; while (rhs_val > 0) { if (rhs_val & 1) { -- cgit v1.2.3