Skip to content

Commit f79cd6a

Browse files
committed
py: Implement mp_obj_new_int_from_float() for MICROPY_LONGINT_IMPL_NONE.
1 parent 12033df commit f79cd6a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

py/objint.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) {
262262
return mp_const_none;
263263
}
264264

265+
#if MICROPY_PY_BUILTINS_FLOAT
266+
mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
267+
// TODO raise an exception if the int won't fit
268+
mp_int_t i = MICROPY_FLOAT_C_FUN(trunc)(val);
269+
return mp_obj_new_int(i);
270+
}
271+
#endif
272+
265273
mp_obj_t mp_obj_new_int(mp_int_t value) {
266274
if (MP_SMALL_INT_FITS(value)) {
267275
return MP_OBJ_NEW_SMALL_INT(value);

0 commit comments

Comments
 (0)