Skip to content

Commit 9d6128a

Browse files
dhylandspfalcon
authored andcommitted
stmhal: fix single precision float printing error
Fixes adafruit#1435.
1 parent e79c6b6 commit 9d6128a

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

py/formatfloat.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ int mp_format_float(float f, char *buf, size_t buf_size, char fmt, int prec, cha
142142
char e_sign_char = '-';
143143
if (num.f < 1.0F && num.f >= 0.9999995F) {
144144
num.f = 1.0F;
145-
first_dig = '1';
145+
if (e > 1) {
146+
// numbers less than 1.0 start with 0.xxx
147+
first_dig = '1';
148+
}
146149
if (e == 0) {
147150
e_sign_char = '+';
148151
}

tests/float/float_array.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ def test(a):
1212

1313
test(array('f'))
1414
test(array('d'))
15+
16+
print('{:.4f}'.format(array('f', b'\xcc\xcc\xcc=')[0]))

0 commit comments

Comments
 (0)