Merge pull request #1896 from dhalbert/round-int-4.0.x
Enable MICROPY_PY_BUILTINS_ROUND_INT; make round() work better when flag is disabled
This commit is contained in:
commit
70e0b5c0d0
|
@ -27,7 +27,7 @@ FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Thermistor
|
|||
|
||||
# Tweak inlining depending on language.
|
||||
ifeq ($(TRANSLATION), zh_Latn_pinyin)
|
||||
CFLAGS_INLINE_LIMIT = 35
|
||||
CFLAGS_INLINE_LIMIT = 25
|
||||
else
|
||||
CFLAGS_INLINE_LIMIT = 55
|
||||
endif
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue