mailing list of musl libc
 help / color / mirror / code / Atom feed
* printf doesn't respect locale
@ 2019-09-09 16:31 Daniel Schoepe
  2019-09-09 16:39 ` Daniel Schoepe
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Daniel Schoepe @ 2019-09-09 16:31 UTC (permalink / raw)
  To: musl

Hi,

I think I found a discrepancy between musl's behavior and the POSIX standard:

According to the POSIX standard, the decimal separator used when using
printf to print floating point numbers should come from the locale
(https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html):

"The radix character is defined in the current locale (category
LC_NUMERIC). In the POSIX locale, or in a locale where the radix
character is not defined, the radix character shall default to a
<period> ( '.' )."

However, it seems that in musl, a period is always used for printing
floating point numbers. For example, the following program prints
"12.0" instead of "12,0" (which is printed when using GNU libc):

#include <stdio.h>
#include <locale.h>

int main(int argc, char **argv) {
    setlocale(LC_ALL, "DE_de");
    printf("%f\n", 12.0f);
}

This was tested using the latest git checkout of musl
(a882841baf42e6a8b74cc33a239b84a9a79493db), compiled on Ubuntu 18.04
using the musl-gcc script. It looks like the usage of "." as a
separator is hardcoded in `fmt_fp`, for instance here:
https://git.musl-libc.org/cgit/musl/tree/src/stdio/vfprintf.c#n392

Best regards,
Daniel


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2019-09-11 18:08 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-09 16:31 printf doesn't respect locale Daniel Schoepe
2019-09-09 16:39 ` Daniel Schoepe
2019-09-09 16:51 ` Szabolcs Nagy
2019-09-09 17:55   ` Rich Felker
2019-09-09 17:54 ` Rich Felker
2019-09-10 16:00   ` Daniel Schoepe
2019-09-10 16:31     ` Szabolcs Nagy
2019-09-10 16:44       ` Tim Tassonis
2019-09-10 17:30         ` Rich Felker
2019-09-10 17:10       ` Daniel Schoepe
2019-09-10 17:33         ` Rich Felker
2019-09-10 18:43         ` Szabolcs Nagy
2019-09-10 21:55           ` A. Wilcox
2019-09-11 10:01             ` Szabolcs Nagy
2019-09-11 10:07               ` Jens Gustedt
2019-09-11 11:44                 ` Rich Felker
2019-09-11 12:53                   ` Jens Gustedt
2019-09-11 13:47                     ` Rich Felker
2019-09-11 15:15                       ` Jens Gustedt
2019-09-11 15:38                         ` Rich Felker
2019-09-11 18:08                           ` Jens Gustedt

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).