summaryrefslogtreecommitdiffstatshomepage
path: root/py/objint_longlong.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/objint_longlong.c')
-rw-r--r--py/objint_longlong.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/py/objint_longlong.c b/py/objint_longlong.c
index ec55c77849..5f48b71340 100644
--- a/py/objint_longlong.c
+++ b/py/objint_longlong.c
@@ -40,6 +40,10 @@
#include "runtime0.h"
#include "runtime.h"
+#if MICROPY_PY_BUILTINS_FLOAT
+#include <math.h>
+#endif
+
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
// Python3 no longer has "l" suffix for long ints. We allow to use it
@@ -187,6 +191,14 @@ mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
return o;
}
+#if MICROPY_PY_BUILTINS_FLOAT
+mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
+ // TODO raise an exception if the unsigned long long won't fit
+ long long i = MICROPY_FLOAT_C_FUN(trunc)(val);
+ return mp_obj_new_int_from_ll(i);
+}
+#endif
+
mp_obj_t mp_obj_new_int_from_str_len(const char **str, mp_uint_t len, bool neg, mp_uint_t base) {
// TODO this does not honor the given length of the string, but it all cases it should anyway be null terminated
// TODO check overflow