summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-11-22 18:09:28 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-11-22 18:09:28 +0200
commit3c4c0698021a9eed5ab66b1c47c0180dd1fabcf4 (patch)
tree17aee76f4bde10c61e2bbe543a1df63261e863ae /py
parentb64e0575fd5c30900c4576185edee26f5e2c54f0 (diff)
downloadmicropython-3c4c0698021a9eed5ab66b1c47c0180dd1fabcf4.tar.gz
micropython-3c4c0698021a9eed5ab66b1c47c0180dd1fabcf4.zip
py/formatfloat: Workaround (fix?) incorrect rounding for %f format.
Diffstat (limited to 'py')
-rw-r--r--py/formatfloat.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/py/formatfloat.c b/py/formatfloat.c
index ac5a74e8fc..ec90906527 100644
--- a/py/formatfloat.c
+++ b/py/formatfloat.c
@@ -308,7 +308,9 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch
}
// Round
- if (f >= FPCONST(5.0)) {
+ // If we print non-exponential format (i.e. 'f'), but a digit we're going
+ // to round by (e) is too far away, then there's nothing to round.
+ if ((org_fmt != 'f' || e <= 1) && f >= FPCONST(5.0)) {
char *rs = s;
rs--;
while (1) {