summaryrefslogtreecommitdiff
path: root/py/objfloat.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-10 13:19:55 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-10 13:19:55 +0000
commit0a8458c353b60420f17050d819912df9b168d0cb (patch)
tree2543d369ab81180697aaf39040171208a93f0250 /py/objfloat.c
parent0527f0c338ef8c085c5209981e167d85e03ae728 (diff)
parentca5a241e48b0cc392a555ad3dec5d008089bfd53 (diff)
Merge branch 'format-float' of github.com:dhylands/micropython into dhylands-format-float
Diffstat (limited to 'py/objfloat.c')
-rw-r--r--py/objfloat.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index 8ba9946b7..5b953f05e 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -12,12 +12,21 @@
#include "runtime0.h"
#if MICROPY_ENABLE_FLOAT
+#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
+#include "format-float.h"
+#endif
mp_obj_t mp_obj_new_float(mp_float_t value);
STATIC void float_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
mp_obj_float_t *o = o_in;
+#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
+ char buf[32];
+ format_float(o->value, buf, sizeof(buf), 'g', 6, '\0');
+ print(env, "%s", buf);
+#else
print(env, "%.8g", (double) o->value);
+#endif
}
STATIC mp_obj_t float_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {