From da77eedafae1d4f9f554f04ca787759f09e9560a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 17 May 2019 15:56:40 -0400 Subject: [PATCH] Enable MICROPY_PY_BUILTINS_ROUND_INT; make round() work beter when it's disabled as well --- py/circuitpy_mpconfig.h | 1 + py/modbuiltins.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index f957886f42..0575bcfe0d 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -89,6 +89,7 @@ #define MICROPY_PY_BUILTINS_MIN_MAX (1) #define MICROPY_PY_BUILTINS_PROPERTY (1) #define MICROPY_PY_BUILTINS_REVERSED (1) +#define MICROPY_PY_BUILTINS_ROUND_INT (1) #define MICROPY_PY_BUILTINS_SET (1) #define MICROPY_PY_BUILTINS_SLICE (1) #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 124dcd05a3..e764f1987e 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -455,13 +455,13 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { return o_in; } - #if !MICROPY_PY_BUILTINS_ROUND_INT - mp_raise_NotImplementedError(NULL); - #else mp_int_t num_dig = mp_obj_get_int(args[1]); if (num_dig >= 0) { return o_in; } + #if !MICROPY_PY_BUILTINS_ROUND_INT + mp_raise_NotImplementedError(NULL); + #else mp_obj_t mult = mp_binary_op(MP_BINARY_OP_POWER, MP_OBJ_NEW_SMALL_INT(10), MP_OBJ_NEW_SMALL_INT(-num_dig)); mp_obj_t half_mult = mp_binary_op(MP_BINARY_OP_FLOOR_DIVIDE, mult, MP_OBJ_NEW_SMALL_INT(2));