diff options
author | Damien George <damien.p.george@gmail.com> | 2015-01-07 12:10:47 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-01-07 12:10:47 +0000 |
commit | ad2307c92c15f0aa90dbd0741fd2538719d0b5e1 (patch) | |
tree | 3082ec3627306b5f674364900f2ede2bceb40a8e /py/objint_mpz.c | |
parent | d8bfd77ad5df1417094f125efa9b97a8d35c03cb (diff) |
py: Temporary fix for conversion of float to int when fits in small int.
Addresses issue #1044 (see also #1040). Could do with a better fix.
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r-- | py/objint_mpz.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 49a9a91e2..02b3ec0fe 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -303,6 +303,9 @@ mp_obj_t mp_obj_new_int_from_float(mp_float_t val) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OverflowError, "can't convert inf to int")); } else if (cl == FP_NAN) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "can't convert NaN to int")); + } else if (MICROPY_FLOAT_C_FUN(fabs)(val) < 10000) { + // temporary(?) fix for optimising case where int will be small int + return MP_OBJ_NEW_SMALL_INT(MICROPY_FLOAT_C_FUN(trunc)(val)); } else { mp_obj_int_t *o = mp_obj_int_new_mpz(); mpz_set_from_float(&o->mpz, val); |