From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B73E13858C5F; Thu, 9 Feb 2023 17:01:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B73E13858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675962092; bh=3ZEGjJ/hpa/8SLtLv4nDbdPUwUKYNAlTAH/S0aSb1Ps=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HYU9OjfFutgZr8j5E771DtBM1jtiEHxm+v4OTXGNvNXsKyluOJkjcv4Ukfzx3JR2y d8+OcUVZq2Egcq3TyymeZK3BdbUyzN0NJdhxtfFzncQ7VnoDVgmud+2Y+MaHedS9mv HFfwYbqRdjBmNFCn0jtHCOCx6gncbAI8EXcgBuzo= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/108742] Incorrect constant folding with (or exposed by) -fexcess-precision=standard Date: Thu, 09 Feb 2023 17:01:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108742 --- Comment #9 from Jakub Jelinek --- (In reply to Michael Matz from comment #7) > (In reply to Jakub Jelinek from comment #5) > > https://eel.is/c++draft/cfloat.syn points to the C standard for > > FLT_EVAL_METHOD > > (plus https://eel.is/c++draft/expr#pre-6 talks about excess precision t= oo) > > and e.g. C17 > > 5.2.4.2.2/9): > > "2 evaluate all operations and constants to the range and precision of = the > > long double type." > >=20 > > Note the " and constants" above. >=20 > Yes. But that leaves unspecified exactly to what bit pattern the string > "4.2" should be converted to. It should be converted to the closest long double, which is 0x8.6666666666668p-1, otherwise the constants wouldn't be evaluated to the range and precision of= the long double type, only to double type then extended to long double. In that case there would be no point to mention the " and constants" above, only operations wo= uld have excess precision, so double d; ... d =3D d + 4.2; would be d =3D (doub= le) ((long double) d + (long double) (double) 4.2), while it actuall should be = d =3D (double) ((long double) d + 4.2L); > 4 An unsuffixed floating constant has type double. Sure, see the typeof above, 4.2 with FLT_EVAL_METHOD =3D=3D 2 has typeof do= uble, but value of 4.2L. If you want 4.2 in double precision, you need (double) 4.2 = or (double) 4.2L or (double) 4.2f (all of them the same), or assign 4.2 to a double object.=