diff options
author | Damien George <damien.p.george@gmail.com> | 2017-04-19 18:46:53 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-04-21 16:21:56 +1000 |
commit | 7a72c0db5a6c2b1f0978516134a95bb6867706ef (patch) | |
tree | 3aea307d9b6233e48380dca9b6d11ff1a5308e39 | |
parent | 58467709972724ac94f6488fefe6d066bfa1589e (diff) | |
download | micropython-7a72c0db5a6c2b1f0978516134a95bb6867706ef.tar.gz micropython-7a72c0db5a6c2b1f0978516134a95bb6867706ef.zip |
py: Reduce str/repr precision of float numbers when floats are 30-bit.
With 30-bit floats there aren't enough bits to faithfully print 7 decimal
digits, so reduce the precision to 6 digits.
-rw-r--r-- | py/objcomplex.c | 4 | ||||
-rw-r--r-- | py/objfloat.c | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/py/objcomplex.c b/py/objcomplex.c index 7ec47edb5b..5f9183f0e7 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -50,7 +50,11 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_ mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in); #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT char buf[16]; + #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C + const int precision = 6; + #else const int precision = 7; + #endif #else char buf[32]; const int precision = 16; diff --git a/py/objfloat.c b/py/objfloat.c index 5cf9954175..d0e6166121 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -113,7 +113,11 @@ STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t mp_float_t o_val = mp_obj_float_get(o_in); #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT char buf[16]; + #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C + const int precision = 6; + #else const int precision = 7; + #endif #else char buf[32]; const int precision = 16; |