py/modbuiltins: Slightly simplify code in builtin round().
This commit is contained in:
parent
a07fc5b640
commit
d5cf5f70fd
|
@ -457,16 +457,14 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) {
|
|||
return o_in;
|
||||
}
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
mp_int_t num_dig = 0;
|
||||
mp_float_t val = mp_obj_get_float(o_in);
|
||||
if (n_args > 1) {
|
||||
num_dig = mp_obj_get_int(args[1]);
|
||||
mp_float_t val = mp_obj_get_float(o_in);
|
||||
mp_int_t num_dig = mp_obj_get_int(args[1]);
|
||||
mp_float_t mult = MICROPY_FLOAT_C_FUN(pow)(10, num_dig);
|
||||
// TODO may lead to overflow
|
||||
mp_float_t rounded = MICROPY_FLOAT_C_FUN(nearbyint)(val * mult) / mult;
|
||||
return mp_obj_new_float(rounded);
|
||||
}
|
||||
mp_float_t val = mp_obj_get_float(o_in);
|
||||
mp_float_t rounded = MICROPY_FLOAT_C_FUN(nearbyint)(val);
|
||||
return mp_obj_new_int_from_float(rounded);
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue