![]() |
|
Message-ID: <CAKdOdAonsh8=ts2jU4ouz57F4BHV1jMrh0oJm9g1pbnQcaQrww@mail.gmail.com>
Date: Tue, 1 Jul 2025 07:55:20 +0200
From: Michal Terepeta <michalt@...gle.com>
To: musl@...ts.openwall.com
Cc: t5y-external <t5y-external@...gle.com>
Subject: Wrong formatting of doubles?
Hi,
We're working on a RISC-V system and using musl as our libc. A recent change
in musl seems to have caused wrong formatting (printf) of double values:
https://git.musl-libc.org/cgit/musl/commit/src/stdio/vfprintf.c?id=572a2e2eb91f00f2f25d301cfb50f435e7ae16b3
Using a simple binary to print max double [1] with the current code I get:
```
The maximum value of a double (printf %e): 1.348676e+308
The maximum value of a double (printf %E): 1.348676E+308
The maximum value of a double (printf %g): 3.13486e+308
```
With the patch [2] that reverts most of the above change, I get the expected
output:
```
The maximum value of a double (printf %e): 1.797693e+308
The maximum value of a double (printf %E): 1.797693E+308
The maximum value of a double (printf %g): 1.79769e+308
```
It'd be great if someone could take a look if they can also repro and perhaps
revert the change?
Many thanks!
Michal
[1] Repro program:
```
#include <float.h>
#include <stdio.h>
int main() {
printf("The maximum value of a double (printf %%e): %e\n", DBL_MAX);
printf("The maximum value of a double (printf %%E): %E\n", DBL_MAX);
printf("The maximum value of a double (printf %%g): %g\n", DBL_MAX);
return 0;
}
```
[2] Patch to test:
```
diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
index 010041ca6c..01004158bf 100644
--- a/src/stdio/vfprintf.c
+++ b/src/stdio/vfprintf.c
@@ -180,12 +180,8 @@
static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t, int ps)
{
- int bufsize = (ps==BIGLPRE)
- ? (LDBL_MANT_DIG+28)/29 + 1 + // mantissa expansion
- (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9 // exponent expansion
- : (DBL_MANT_DIG+28)/29 + 1 +
- (DBL_MAX_EXP+DBL_MANT_DIG+28+8)/9;
- uint32_t big[bufsize];
+ uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion
+ + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion
uint32_t *a, *d, *r, *z;
int e2=0, e, i, j, l;
char buf[9+LDBL_MANT_DIG/4], *s;
```
Download attachment "smime.p7s" of type "application/pkcs7-signature" (5279 bytes)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.