diff options
| author | Dave Hylands | 2015-08-31 15:43:31 -0700 |
|---|---|---|
| committer | Paul Sokolovsky | 2015-09-11 23:09:50 +0300 |
| commit | 9d6128acdccb463edfe9a3b7dbf86417643104bb (patch) | |
| tree | 95adbe8770ad1fc7c818136d5bc0d5abe62d76a7 | |
| parent | e79c6b6312a85a50d113346144d58fa62cb4adc2 (diff) | |
stmhal: fix single precision float printing error
Fixes #1435.
| -rw-r--r-- | py/formatfloat.c | 5 | ||||
| -rw-r--r-- | tests/float/float_array.py | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/py/formatfloat.c b/py/formatfloat.c index cc0636100..a801055a6 100644 --- a/py/formatfloat.c +++ b/py/formatfloat.c @@ -142,7 +142,10 @@ int mp_format_float(float f, char *buf, size_t buf_size, char fmt, int prec, cha char e_sign_char = '-'; if (num.f < 1.0F && num.f >= 0.9999995F) { num.f = 1.0F; - first_dig = '1'; + if (e > 1) { + // numbers less than 1.0 start with 0.xxx + first_dig = '1'; + } if (e == 0) { e_sign_char = '+'; } diff --git a/tests/float/float_array.py b/tests/float/float_array.py index c0f2c587c..033877db3 100644 --- a/tests/float/float_array.py +++ b/tests/float/float_array.py @@ -12,3 +12,5 @@ def test(a): test(array('f')) test(array('d')) + +print('{:.4f}'.format(array('f', b'\xcc\xcc\xcc=')[0])) |
