From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5EEE43858CDB; Fri, 31 Mar 2023 12:33:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5EEE43858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680266036; bh=Jc1qQC0pH0LLPqDQJcPXM/kB3f4u+3YcdrxsjeSocZY=; h=From:To:Subject:Date:From; b=HfLztRXAUEPRFsrfF0h0o15xLQ+3CaKQ7uAt8Kcddpfb7QC1OPBOE9qi4D3S3uBfz +KszAhPfFMFvh7CKfW1XfCX0DLYISCaLzu+S+88IlpZyRHveJ2MiXR6GJNZo8tPfn+ KlMvnSSqFShxWCqpUMITc9HfDv5lIAZvtt4tNxtw= From: "rcopley at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109359] New: Compile-time rounding of double literal to float is incorrect with -frounding-math Date: Fri, 31 Mar 2023 12:33:56 +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: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rcopley at gmail dot com 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109359 Bug ID: 109359 Summary: Compile-time rounding of double literal to float is incorrect with -frounding-math Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rcopley at gmail dot com Target Milestone: --- The following program should print: 0.001914 0.630538 With "g++ -frounding-math", it prints instead: -8023756970655744.000000 0.872496 This bug is present in trunk, and since gcc 12.1, and does not appear to be platform specific. Compiler explorer link: https://godbolt.org/z/aMhcYcY66 #include float xs[] =3D {0.001914, 0.630539}; int main() { std::size_t size =3D sizeof xs / sizeof xs[0]; for (std::size_t i =3D 0; i !=3D size; ++i) { std::printf("%f\n", xs[i]); } }=