Skip to content

Commit c236ebf

Browse files
committed
py/modbuiltins: Allow round() to return a big int if necessary.
Previous to this patch, if the result of the round function overflowed a small int, or was inf or nan, then a garbage value was returned. With this patch the correct big-int is returned if necessary and exceptions are raised for inf or nan.
1 parent 125eae1 commit c236ebf

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

py/modbuiltins.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,11 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) {
478478
}
479479
mp_float_t val = mp_obj_get_float(o_in);
480480
mp_float_t rounded = MICROPY_FLOAT_C_FUN(nearbyint)(val);
481+
return mp_obj_new_int_from_float(rounded);
481482
#else
482483
mp_int_t r = mp_obj_get_int(o_in);
483-
#endif
484484
return mp_obj_new_int(r);
485+
#endif
485486
}
486487
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_round_obj, 1, 2, mp_builtin_round);
487488

0 commit comments

Comments
 (0)