py/modbuiltins: Slightly simplify code in builtin round().
@@ -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;
- if (n_args > 1) {
- num_dig = mp_obj_get_int(args[1]);
mp_float_t val = mp_obj_get_float(o_in);
+ if (n_args > 1) {
+ 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
