summaryrefslogtreecommitdiff
path: root/py/objint_mpz.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r--py/objint_mpz.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 5480bd385..1dc1def33 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -41,6 +41,10 @@
#include "runtime0.h"
#include "runtime.h"
+#if MICROPY_PY_BUILTINS_FLOAT
+#include <math.h>
+#endif
+
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ
#if MICROPY_PY_SYS_MAXSIZE
@@ -298,6 +302,14 @@ mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) {
return mp_obj_new_int_from_ll(value);
}
+#if MICROPY_PY_BUILTINS_FLOAT
+mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
+ // TODO: This doesn't handle numbers with large exponent
+ 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) {
mp_obj_int_t *o = mp_obj_int_new_mpz();
mp_uint_t n = mpz_set_from_str(&o->mpz, *str, len, neg, base);