summaryrefslogtreecommitdiffstatshomepage
path: root/py/mpprint.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-05-28 14:22:12 +0000
committerDamien George <damien.p.george@gmail.com>2015-05-28 14:22:12 +0000
commit79474c6b164fb66a8d348bfa57613f9dbf5af4e8 (patch)
treed449229d7ee01f114d092a624943bb42d79a72a5 /py/mpprint.c
parent2cae0f62908812b6cd925943ee70e7e0bef0387e (diff)
downloadmicropython-79474c6b164fb66a8d348bfa57613f9dbf5af4e8.tar.gz
micropython-79474c6b164fb66a8d348bfa57613f9dbf5af4e8.zip
py: Remove unnecessary extra handling of padding of nan/inf.
C's printf will pad nan/inf differently to CPython. Our implementation originally conformed to C, now it conforms to CPython's way. Tests for this are also added in this patch.
Diffstat (limited to 'py/mpprint.c')
-rw-r--r--py/mpprint.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/py/mpprint.c b/py/mpprint.c
index 51c16f4e3d..6da6614b7c 100644
--- a/py/mpprint.c
+++ b/py/mpprint.c
@@ -363,21 +363,11 @@ int mp_print_float(const mp_print_t *print, mp_float_t f, char fmt, int flags, c
if ((flags & PF_FLAG_PAD_AFTER_SIGN) && buf[0] < '0') {
// We have a sign character
s++;
- if (*s <= '9' || (flags & PF_FLAG_PAD_NAN_INF)) {
- // We have a number, or we have a inf/nan and PAD_NAN_INF is set
- // With '{:06e}'.format(float('-inf')) you get '-00inf'
- chrs += mp_print_strn(print, &buf[0], 1, 0, 0, 1);
- width--;
- len--;
- }
+ chrs += mp_print_strn(print, &buf[0], 1, 0, 0, 1);
+ width--;
+ len--;
}
- if (*s > 'A' && (flags & PF_FLAG_PAD_NAN_INF) == 0) {
- // We have one of the inf or nan variants, suppress zero fill.
- // With printf, if you use: printf("%06e", -inf) then you get " -inf"
- // so suppress the zero fill.
- fill = ' ';
- }
chrs += mp_print_strn(print, s, len, flags, fill, width);
return chrs;