mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
all: Fix implicit floating point to integer conversions.
These are found when building with -Wfloat-conversion.
This commit is contained in:
@@ -509,7 +509,7 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) {
|
||||
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);
|
||||
mp_float_t mult = MICROPY_FLOAT_C_FUN(pow)(10, (mp_float_t)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);
|
||||
|
||||
Reference in New Issue
Block a user