From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 296633858026; Mon, 27 Sep 2021 14:27:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 296633858026 From: "zimmerma+gcc at loria dot fr" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zimmerma+gcc at loria dot fr X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Sep 2021 14:27:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102498 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 #include #include const long double a =3D 0xc.90fdaa22168c235p-1l; const long double b =3D 0xc.90fdaa22168c235p-2l; int main() { fesetround (FE_TONEAREST); printf ("FE_TONEAREST: a=3D%La b=3D%La\n", a, b); fesetround (FE_TOWARDZERO); printf ("FE_TOWARDZERO: a=3D%La b=3D%La\n", a, b); fesetround (FE_UPWARD); printf ("FE_UPWARD: a=3D%La b=3D%La\n", a, b); fesetround (FE_DOWNWARD); printf ("FE_DOWNWARD: a=3D%La b=3D%La\n", a, b); } I get: $ gcc -frounding-math -O0 -fno-builtin e.c -lm $ ./a.out=20 FE_TONEAREST: a=3D0xc.90fdaa22168c235p-1 b=3D0xc.90fdaa22168c235p-2 FE_TOWARDZERO: a=3D0xc.90fdaa22168c235p-1 b=3D0xc.90fdaa22168c234p-2 FE_UPWARD: a=3D0xc.90fdaa22168c235p-1 b=3D0xc.90fdaa22168c235p-2 FE_DOWNWARD: a=3D0xc.90fdaa22168c235p-1 b=3D0xc.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=