From febeff4af429483b41137f0befc70d14c9077ae1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 23 Mar 2017 22:57:08 +1100 Subject: [PATCH] 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. --- py/modmath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/modmath.c b/py/modmath.c index 7c51eab03a..ddab337d05 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -57,7 +57,7 @@ STATIC NORETURN void math_error(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); #define MATH_FUN_1_TO_INT(py_name, c_name) \ - 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); } \ + 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))); } \ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); #define MATH_FUN_1_ERRCOND(py_name, c_name, error_condition) \