summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2019-12-17 22:00:49 -0800
committerCorinna Vinschen <corinna@vinschen.de>2019-12-18 20:53:36 +0100
commit76dcfd0c4d31ef2658564ba2fac8b1852704c45a (patch)
treedbf6a62730996bc9ad21c4cd545d7aab80efb762
parent11f99384d2971356bab2fcac7e29792250abea73 (diff)
downloadcygnal-76dcfd0c4d31ef2658564ba2fac8b1852704c45a.tar.gz
cygnal-76dcfd0c4d31ef2658564ba2fac8b1852704c45a.tar.bz2
cygnal-76dcfd0c4d31ef2658564ba2fac8b1852704c45a.zip
Don't display trailing '.' in _dcvt
In the two helper functions that _dcvt calls for 'f' and 'e' mode, if there are no digits to display after the decimal point, don't add one. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--newlib/libc/stdlib/ecvtbuf.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/newlib/libc/stdlib/ecvtbuf.c b/newlib/libc/stdlib/ecvtbuf.c
index 228362e07..0cb11f889 100644
--- a/newlib/libc/stdlib/ecvtbuf.c
+++ b/newlib/libc/stdlib/ecvtbuf.c
@@ -93,7 +93,8 @@ print_f (struct _reent *ptr,
{
if (p == start)
*buf++ = '0';
- *buf++ = '.';
+ if (decpt < 0 && ndigit > 0)
+ *buf++ = '.';
while (decpt < 0 && ndigit > 0)
{
*buf++ = '0';
@@ -148,11 +149,15 @@ print_e (struct _reent *ptr,
}
*buf++ = *p++;
- if (dot || ndigit != 0)
- *buf++ = '.';
+ if (ndigit > 0)
+ dot = 1;
while (*p && ndigit > 0)
{
+ if (dot) {
+ *buf++ = '.';
+ dot = 0;
+ }
*buf++ = *p++;
ndigit--;
}
@@ -168,6 +173,10 @@ print_e (struct _reent *ptr,
{
while (ndigit > 0)
{
+ if (dot) {
+ *buf++ = '.';
+ dot = 0;
+ }
*buf++ = '0';
ndigit--;
}