Skip to content

Commit febeff4

Browse files
committed
py/modmath: Allow trunc/ceil/floor to return a big int if necessary.
Previous to this patch, if the result of the trunc/ceil/floor functions 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 f64a3e2 commit febeff4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

py/modmath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ STATIC NORETURN void math_error(void) {
5757
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
5858

5959
#define MATH_FUN_1_TO_INT(py_name, c_name) \
60-
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { mp_int_t x = MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj)); return mp_obj_new_int(x); } \
60+
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_int_from_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \
6161
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
6262

6363
#define MATH_FUN_1_ERRCOND(py_name, c_name, error_condition) \

0 commit comments

Comments
 (0)