Commit 6433bd92 authored by Damien George's avatar Damien George
Browse files

py: Add explicit conversion from float to int via int().

parent 804760bf
......@@ -10,6 +10,10 @@
#include "mpz.h"
#include "objint.h"
#if MICROPY_ENABLE_FLOAT
#include <math.h>
#endif
// This dispatcher function is expected to be independent of the implementation
// of long int
STATIC mp_obj_t int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
......@@ -25,6 +29,10 @@ STATIC mp_obj_t int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
uint l;
const char *s = mp_obj_str_get_data(args[0], &l);
return mp_parse_num_integer(s, l, 0);
#if MICROPY_ENABLE_FLOAT
} else if (MP_OBJ_IS_TYPE(args[0], &mp_type_float)) {
return MP_OBJ_NEW_SMALL_INT((machine_int_t)(MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0]))));
#endif
} else {
return MP_OBJ_NEW_SMALL_INT(mp_obj_get_int(args[0]));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment