-
-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use LLVM for printing compile-time reals to hex strings (and trim excessive zeros for decimal strings) #3410
Conversation
glibc reference on Linux x64: import core.stdc.stdio;
void main()
{
immutable real[] xs = [
real.nan,
-real.nan,
real.infinity,
-real.infinity,
0.0L,
-0.0L,
0x1p-1L,
0x3p-3L,
0x1p+0L,
0x3p-1L,
-0x3p-2L,
100.0L,
1e+300L,
1e-300L,
1.2345678901234567890123456789L,
-12.345678901234567890123456789L,
123456.78901234567890123456789L,
-123456.78901234567890123456789L,
1234567.8901234567890123456789L,
-1234567.8901234567890123456789L,
0.0001234567890123456789012345L,
-0.0001234567890123456789012345L,
0.0000123456789012345678901234L,
-0.0000123456789012345678901234L,
];
foreach (x; xs)
{
printf("%%g = %Lg", x);
printf("\t%%a = %La", x);
printf("\t%%A = %LA", x);
printf("\t%%#g = %#Lg\n", x);
}
} =>
(Previously, |
Some 2 dozen output-checking dmd-testsuite tests would need to be adapted, primarily because of |
79b2f5f
to
9cf4ff1
Compare
It's a pity the decimal strings don't work yet with LLVM, but the hex strings are more important here anyway (used for mangling floating-point template params, as well as for .di header generation in case the short |
Consistent output across platforms is a big win! |
Primary motivation are apparent printf issues for the hex format and quadruple C `long double` in Android's Bionic runtime for x86_64. This required an extra Termux patch until now: https://github.com/termux/termux-packages/blob/3c0e8cd65e6abc2709462c0fe421de5a9f877362/packages/ldc/ldc-x64-sprintf.patch
Primary motivation are apparent printf issues for the hex format and quadruple C
long double
in Android's Bionic runtime for x86_64. This required an extra Termux patch until now:https://github.com/termux/termux-packages/blob/3c0e8cd65e6abc2709462c0fe421de5a9f877362/packages/ldc/ldc-x64-sprintf.patch
(And using the
%g
format for mangling instead of%A
is a horrible workaround.)