From 12033df511a5a5f0237a764379aacfbceb6c45dd Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 30 Dec 2014 00:22:10 +0200 Subject: py: Partially fix float to int conversion. This fixes conversion when float type has more mantissa bits than small int, and float value has small exponent. This is for example the case of 32-bit platform using doubles, and converting value of time.time(). Conversion of floats with larg exponnet is still not handled correctly. --- py/objint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'py/objint.c') diff --git a/py/objint.c b/py/objint.c index 7f0e2b2506..8f626190ce 100644 --- a/py/objint.c +++ b/py/objint.c @@ -65,7 +65,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_ return mp_parse_num_integer(s, l, 0); #if MICROPY_PY_BUILTINS_FLOAT } else if (MP_OBJ_IS_TYPE(args[0], &mp_type_float)) { - return MP_OBJ_NEW_SMALL_INT((MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0])))); + return mp_obj_new_int_from_float(mp_obj_float_get(args[0])); #endif } else { // try to convert to small int (eg from bool) -- cgit v1.2.3