From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14626 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Schoepe Newsgroups: gmane.linux.lib.musl.general Subject: Re: printf doesn't respect locale Date: Mon, 9 Sep 2019 17:39:10 +0100 Message-ID: References: Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="200743"; mail-complaints-to="usenet@blaine.gmane.org" To: musl@lists.openwall.com Original-X-From: musl-return-14642-gllmg-musl=m.gmane.org@lists.openwall.com Mon Sep 09 18:39:36 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 1i7MhU-000q73-NM for gllmg-musl@m.gmane.org; Mon, 09 Sep 2019 18:39:36 +0200 Original-Received: (qmail 10049 invoked by uid 550); 9 Sep 2019 16:39:34 -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 10013 invoked from network); 9 Sep 2019 16:39:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schoepe.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=ead/3UOCuTWtfP+mIaI+nQOU2p9cDTlY5GQH2OirphU=; b=Yk36th9PjRG79Vx6P1ODcIRif8pFHTzg1kzp8f6Jz6zaoxnNL++F9R0Ir4uFthBRdc 8bQnkMVD8rUxeySlK5TCkWp5KAPk+F1ovuT6tFeJXE0Z+o9S+VymevQjaDfPQkSL+BTE lBnrIihAP8r+hPzJPOa2uqYyTEPwd9/1aVwVQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=ead/3UOCuTWtfP+mIaI+nQOU2p9cDTlY5GQH2OirphU=; b=S4PkCHc6j0rkskI62wBExelMTiktqJQw74sGcFTMsRG7DNaQqbNiWUIGh4boGNM91r 1+GIgI5TWKAd7zOCv52AYzdodpLVnsXz8pagOpYyWm6LCmS8iH+8zfYWv86e6LuWfttL +rnKqfVp/xo6uqhjwi/FVZdRPqAVBafRAgjxp+vHErfEXX2B6yJYh0KOryQaTjdov1bl UEHO79z0GXwruV5csUHFTPbvzUpCswOzacQiclh3H1s7y9C3gMmFYMrCE+FiVjC7tlUC dnv9VtFZ1VFgyK7e3f5sVimSnbpxPJWyKfzTO7gbOnTy7Yk1DA6hghJKwG44pnt7/fnN Qp9w== X-Gm-Message-State: APjAAAVOHGZYrmwoeGCLmxPn57kKAr5/UoBkZnCjn6gu89SIC+9PatAE USqFYa/Ohctwu/6tzoFpHhvzQYtBoMEC4XlhEKGM4ML2eXc= X-Google-Smtp-Source: APXvYqzy40W5ZQwbsbtS/7Jph0I70EIS9MIVMJWNXDuZsWCP+2O+P1pp5VNuJFycBJ862jY+BGBN+byARAbkzYBBVqU= X-Received: by 2002:ac8:34c9:: with SMTP id x9mr24725253qtb.65.1568047161798; Mon, 09 Sep 2019 09:39:21 -0700 (PDT) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:14626 Archived-At: Small correction: The example works as the standard suggests on OSX, but exhibits the same behavior as with musl with GNU libc as well. On Mon, Sep 9, 2019 at 5:31 PM Daniel Schoepe wrote: > > 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 > ( '.' )." > > 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 > #include > > 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