diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-22 20:54:01 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-22 20:54:01 +0000 |
commit | eabdf6718a8d9d10c810b8cd440b82a11d517205 (patch) | |
tree | 955749df1f3f5ba17d5dac9fc742606dc5d0794a /py/objint_mpz.c | |
parent | 8138205bea96afb6b59e3147fbaab754cb218ea2 (diff) | |
download | micropython-eabdf6718a8d9d10c810b8cd440b82a11d517205.tar.gz micropython-eabdf6718a8d9d10c810b8cd440b82a11d517205.zip |
py: Add function to convert long int to float.
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r-- | py/objint_mpz.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 39ea7ca115..05e300ddc9 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -215,9 +215,10 @@ mp_obj_t mp_obj_new_int_from_long_str(const char *str) { machine_int_t mp_obj_int_get(mp_obj_t self_in) { if (MP_OBJ_IS_SMALL_INT(self_in)) { return MP_OBJ_SMALL_INT_VALUE(self_in); + } else { + mp_obj_int_t *self = self_in; + return mpz_as_int(&self->mpz); } - mp_obj_int_t *self = self_in; - return mpz_as_int(&self->mpz); } machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) { @@ -225,4 +226,15 @@ machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) { return mp_obj_int_get(self_in); } +#if MICROPY_ENABLE_FLOAT +mp_float_t mp_obj_int_as_float(mp_obj_t self_in) { + if (MP_OBJ_IS_SMALL_INT(self_in)) { + return MP_OBJ_SMALL_INT_VALUE(self_in); + } else { + mp_obj_int_t *self = self_in; + return mpz_as_float(&self->mpz); + } +} +#endif + #endif |