public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "zimmerma+gcc at loria dot fr" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/102498] New: wrong output of printf with long double constant and non-default rounding mode Date: Mon, 27 Sep 2021 14:27:34 +0000 [thread overview] Message-ID: <bug-102498-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102498 Bug ID: 102498 Summary: wrong output of printf with long double constant and non-default rounding mode Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: zimmerma+gcc at loria dot fr Target Milestone: --- with the following program: #include <stdio.h> #include <math.h> #include <fenv.h> const long double a = 0xc.90fdaa22168c235p-1l; const long double b = 0xc.90fdaa22168c235p-2l; int main() { fesetround (FE_TONEAREST); printf ("FE_TONEAREST: a=%La b=%La\n", a, b); fesetround (FE_TOWARDZERO); printf ("FE_TOWARDZERO: a=%La b=%La\n", a, b); fesetround (FE_UPWARD); printf ("FE_UPWARD: a=%La b=%La\n", a, b); fesetround (FE_DOWNWARD); printf ("FE_DOWNWARD: a=%La b=%La\n", a, b); } I get: $ gcc -frounding-math -O0 -fno-builtin e.c -lm $ ./a.out FE_TONEAREST: a=0xc.90fdaa22168c235p-1 b=0xc.90fdaa22168c235p-2 FE_TOWARDZERO: a=0xc.90fdaa22168c235p-1 b=0xc.90fdaa22168c234p-2 FE_UPWARD: a=0xc.90fdaa22168c235p-1 b=0xc.90fdaa22168c235p-2 FE_DOWNWARD: a=0xc.90fdaa22168c235p-1 b=0xc.90fdaa22168c234p-2 The value 'a' is printed the same whatever the rounding mode, but 'b' (which approximates pi to nearest) is wrongly printed for FE_TOWARDZERO and FE_DOWNWARD. According to Alexander Monakov, the same problem should happen with og_2 10, log_2 e, log_10 2, and log_e 2, see https://sourceware.org/pipermail/libc-alpha/2021-September/131411.html
next reply other threads:[~2021-09-27 14:27 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-27 14:27 zimmerma+gcc at loria dot fr [this message] 2021-09-27 15:00 ` [Bug c/102498] wrong output of printf with long double constant (pi) " vincent-gcc at vinc17 dot net 2021-09-27 15:11 ` [Bug target/102498] " jakub at gcc dot gnu.org 2021-09-27 15:20 ` jakub at gcc dot gnu.org 2021-09-27 16:50 ` vincent-gcc at vinc17 dot net 2021-09-27 22:35 ` [Bug target/102498] [9/10/11/12 Regression] Long double constant and non-default rounding mode on x86 pinskia at gcc dot gnu.org 2021-09-28 0:57 ` vincent-gcc at vinc17 dot net 2021-09-28 1:14 ` pinskia at gcc dot gnu.org 2021-09-28 8:17 ` vincent-gcc at vinc17 dot net 2021-09-28 11:03 ` cvs-commit at gcc dot gnu.org 2021-09-28 11:07 ` cvs-commit at gcc dot gnu.org 2021-09-28 11:10 ` [Bug target/102498] [9/10 " jakub at gcc dot gnu.org 2022-05-10 8:20 ` cvs-commit at gcc dot gnu.org 2022-05-10 8:46 ` zimmerma+gcc at loria dot fr 2022-05-10 11:57 ` vincent-gcc at vinc17 dot net 2022-05-10 12:00 ` vincent-gcc at vinc17 dot net 2022-05-11 6:22 ` cvs-commit at gcc dot gnu.org 2022-05-11 6:36 ` jakub at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102498-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).