Enable MICROPY_PY_BUILTINS_ROUND_INT; make round() work beter when it's disabled as well
This commit is contained in:
parent
2abf99aa32
commit
da77eedafa
@ -89,6 +89,7 @@
|
|||||||
#define MICROPY_PY_BUILTINS_MIN_MAX (1)
|
#define MICROPY_PY_BUILTINS_MIN_MAX (1)
|
||||||
#define MICROPY_PY_BUILTINS_PROPERTY (1)
|
#define MICROPY_PY_BUILTINS_PROPERTY (1)
|
||||||
#define MICROPY_PY_BUILTINS_REVERSED (1)
|
#define MICROPY_PY_BUILTINS_REVERSED (1)
|
||||||
|
#define MICROPY_PY_BUILTINS_ROUND_INT (1)
|
||||||
#define MICROPY_PY_BUILTINS_SET (1)
|
#define MICROPY_PY_BUILTINS_SET (1)
|
||||||
#define MICROPY_PY_BUILTINS_SLICE (1)
|
#define MICROPY_PY_BUILTINS_SLICE (1)
|
||||||
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (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;
|
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]);
|
mp_int_t num_dig = mp_obj_get_int(args[1]);
|
||||||
if (num_dig >= 0) {
|
if (num_dig >= 0) {
|
||||||
return o_in;
|
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 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));
|
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
Block a user