From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14627 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: printf doesn't respect locale Date: Mon, 9 Sep 2019 18:51:00 +0200 Message-ID: <20190909165100.GH22009@port70.net> References: Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="250757"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) To: musl@lists.openwall.com Original-X-From: musl-return-14643-gllmg-musl=m.gmane.org@lists.openwall.com Mon Sep 09 18:51:15 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1i7Msl-00134N-4N for gllmg-musl@m.gmane.org; Mon, 09 Sep 2019 18:51:15 +0200 Original-Received: (qmail 21892 invoked by uid 550); 9 Sep 2019 16:51:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 21874 invoked from network); 9 Sep 2019 16:51:12 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:14627 Archived-At: * Daniel Schoepe [2019-09-09 17:31:01 +0100]: > 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 > ( '.' )." > > 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): musl is posix conform. it just only supports LC_NUMERIC locales where the radix character is a period. if you see a musl based system where LC_NUMERIC is defined otherwise then report the issue to the integrator or distributor of that system. > > #include > #include > > int main(int argc, char **argv) { > setlocale(LC_ALL, "DE_de"); > printf("%f\n", 12.0f); > } the musl DE_de locale must use . as radix, so the output is expected. > > 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