aboutsummaryrefslogtreecommitdiff
path: root/src/stdio/vfprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio/vfprintf.c')
-rw-r--r--src/stdio/vfprintf.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 497c5e19..360d723a 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -166,7 +166,8 @@ static char *fmt_u(uintmax_t x, char *s)
{
unsigned long y;
for ( ; x>ULONG_MAX; x/=10) *--s = '0' + x%10;
- for (y=x; y; y/=10) *--s = '0' + y%10;
+ for (y=x; y>=10; y/=10) *--s = '0' + y%10;
+ if (y) *--s = '0' + y;
return s;
}
@@ -211,18 +212,11 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
if (y) e2--;
if ((t|32)=='a') {
- long double round = 8.0;
- int re;
-
if (t&32) prefix += 9;
pl += 2;
- if (p<0 || p>=LDBL_MANT_DIG/4-1) re=0;
- else re=LDBL_MANT_DIG/4-1-p;
-
- if (re) {
- round *= 1<<(LDBL_MANT_DIG%4);
- while (re--) round*=16;
+ if (p>=0 && p<(LDBL_MANT_DIG-1+3)/4) {
+ double round = scalbn(1, LDBL_MANT_DIG-1-(p*4));
if (*prefix=='-') {
y=-y;
y-=round;