1 parent 12033df commit f79cd6aCopy full SHA for f79cd6a
1 file changed
py/objint.c
@@ -262,6 +262,14 @@ mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) {
262
return mp_const_none;
263
}
264
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
+
273
mp_obj_t mp_obj_new_int(mp_int_t value) {
274
if (MP_SMALL_INT_FITS(value)) {
275
return MP_OBJ_NEW_SMALL_INT(value);
0 commit comments