wprintf with %lf

35 views
Skip to first unread message

Юрий Катков

unread,
Sep 11, 2019, 5:15:53 PM9/11/19
to emscripten-discuss
Hello everyone!

I'm trying to print double with wprintf in stdout and some format specifiers don't work.

int main( int argc, char* argv[] )
{
double val = 0.123;

wprintf( L"1 %lf\n", val ); // FAIL
wprintf( L"2 %lf\n", static_cast<float>( val ) ); //FAIL
wprintf( L"3 %f\n", val ); // OK
wprintf( L"4 %f\n", static_cast<float>( val ) ); // OK
printf( "5 %lf\n", val ); // OK
printf( "6 %lf\n", static_cast<float>( val ) ); // OK
printf( "7 %f\n", val ); // OK
printf( "8 %f\n", static_cast<float>( val ) ); // OK

return 0;
}

And what I see in console:
3 0.123000
4 0.123000
5 0.123000
6 0.123000
7 0.123000
8 0.123000

Why %ls doesn't work with wprintf ?

Brion Vibber

unread,
Sep 11, 2019, 6:17:09 PM9/11/19
to emscripten Mailing List
I think this is a bug in the musl implementation of the standard C library; 8-bit printf implements %lf but wide-char wprintf does not. (This can be seen in vfprintf.c and vfwprintf.c under emscripten/system/lib/libc/musl/src/stdio)

It looks like you can use %F for doubles on both functions, however.

-- brion

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/e4cce172-ac25-45f7-9bd1-879b96208c23%40googlegroups.com.

Brion Vibber

unread,
Sep 12, 2019, 2:11:25 AM9/12/19
to emscripten Mailing List
I've reported the bug to the musl mailing list with a fix patch for the wprintf implementation.

-- brion

Юрий Катков

unread,
Sep 12, 2019, 4:47:31 AM9/12/19
to emscripten-discuss
Thanks a lot!
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages