Skip to content

Commit 7a72c0d

Browse files
committed
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.
1 parent 5846770 commit 7a72c0d

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

py/objcomplex.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_
5050
mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in);
5151
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
5252
char buf[16];
53+
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
54+
const int precision = 6;
55+
#else
5356
const int precision = 7;
57+
#endif
5458
#else
5559
char buf[32];
5660
const int precision = 16;

py/objfloat.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
113113
mp_float_t o_val = mp_obj_float_get(o_in);
114114
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
115115
char buf[16];
116+
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
117+
const int precision = 6;
118+
#else
116119
const int precision = 7;
120+
#endif
117121
#else
118122
char buf[32];
119123
const int precision = 16;

0 commit comments

Comments
 (0)