summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-12 11:50:52 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-12 11:50:52 -0400
commite514228043c2618f925bcfe8db71b0ff4e2b2113 (patch)
treed88c4d86a0e98961b6938347b6ce4c543e874f11
parent209f2bbd95cfac3a71bb8afa452c794d1ccf94cf (diff)
downloadmusl-e514228043c2618f925bcfe8db71b0ff4e2b2113.tar.gz
fix printf("%.9g", 1.1) and similar not dropping trailing zeros
-rw-r--r--src/stdio/vfprintf.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index a8cf41b6..f19058d3 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -330,9 +330,10 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
else if (i==i/2 && d+1==z) small=0x10p-1;
else small=0x11p-1;
if (pl && *prefix=='-') round*=-1, small*=-1;
+ *d -= x;
/* Decide whether to round by probing round+small */
if (round+small != round) {
- *d = *d - x + i;
+ *d = *d + i;
while (*d > 999999999) {
*d--=0;
(*d)++;
@@ -341,6 +342,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
for (i=10, e=9*(r-a); *a>=i; i*=10, e++);
}
}
+ if (z>d+1) z=d+1;
for (; !z[-1] && z>a; z--);
}