musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/stdio
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018年08月23日 15:24:03 -0400
committerRich Felker <dalias@aerifal.cx>2018年08月23日 15:24:03 -0400
commitcfa0a54c082d41db6446638eed1d57f163434092 (patch)
tree91f68ffa2487046482925443e7abe39b8388a4da /src/stdio
parent6aeb131b4c1aee30d7f7125a8a88ce6f41172f01 (diff)
downloadmusl-cfa0a54c082d41db6446638eed1d57f163434092.tar.gz
fix printf precision specifier for hex floats on non-ld80 archs
the code to perform rounding to the desired precision wrongly assumed the long double mantissa was an integral number of nibbles (hex digits) in length. this is true for 80-bit extended precision (64-bit mantissa) but not for double (53) or quad (113). scale the rounding value by 1<<(LDBL_MANT_DIG%4) to compensate.
Diffstat (limited to 'src/stdio')
-rw-r--r--src/stdio/vfprintf.c 1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 50fb55c1..5e7be717 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -220,6 +220,7 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
else re=LDBL_MANT_DIG/4-1-p;
if (re) {
+ round *= 1<<(LDBL_MANT_DIG%4);
while (re--) round*=16;
if (*prefix=='-') {
y=-y;
generated by cgit v1.2.1 (git 2.18.0) at 2025年10月05日 20:18:29 +0000

AltStyle によって変換されたページ (->オリジナル) /