-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
printf doubles with %lf gives nan #58
Comments
I believe this might be a bug. I haven't had time to compile the project yet, but this might fix it. --- a/libc/fmt/palandprintf.c
+++ b/libc/fmt/palandprintf.c
@@ -215,6 +215,10 @@ hidden int palandprintf(void *fn, void *arg, const char *format, va_list va) {
signbit = sizeof(intmax_t) * 8 - 1;
break;
case 'l':
+ if (format[1] == 'f' || format[1] == 'F') {
+ format++;
+ break;
+ }
if (format[1] == 'l') format++;
/* fallthrough */
case 't': /* ptrdiff_t */ See: https://en.cppreference.com/w/c/io/fprintf
|
Thank you not only for bringing this to my attention, but for taking the time to send a PR too. One thing worth mentioning is that the best way to format floats is Cosmopolitan is by doing the following: printf("%s\n", gc(xdtoa(3.14))); That's the wrapper we define for generalized dtoa which in my opinion formats much more readable numbers than the standard for the printf interface would otherwise enable us to do. I should also mention that Cosmopolitan's floating point printf() is somewhat underdeveloped for that reason. The main thing it's lacking right now is exponents. It also isn't femtoscale accurate like the generalized dtoa functions are. |
Hi, I tried out a bunch of portable executables in Linux and Windows, and they all worked perfectly :).
However, when I compiled and ran the below code:
The output is:
When I compile using
gcc -lm
the output is same for both.Do I have to add a compilation flag to print doubles via
%lf
?The text was updated successfully, but these errors were encountered: