From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9840E3858C33; Thu, 20 Jul 2023 10:03:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9840E3858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689847395; bh=zlT2RWzIBS7pgWBXPTRcb7VqQ59X3ZT3XpcZUWboWOc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qR/dW5lzg3yzWEGycPB2+WlZKiXduoe42JsxAQOnbg++MbjoySSvtxGWNBWIHbvpY o6CkPyL4E/T/LKXdGNA+z2k9xyy9iK2nciHksLZYM9zE2YbV4/RfHt7plWIpWsCMOq fwvQqQ2jA16weUMafNQQLbfLZt4WdzNlu4TMvL2c= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110749] wrong show float Date: Thu, 20 Jul 2023 10:03:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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=3D110749 --- Comment #3 from Jonathan Wakely --- Your program is using the default precision for printing a double: 6 significant figures. 101.92249999999999943 with 6 digits of precision is 101.922 (because (24 ro= unds to 2). 101.92249999999999943 with 7 digits of precision is 101.9225 (because 49 ro= unds to 5). If you use std::setprecision(7) << std::abs(value) you will get 101.9225: 000000000090.8425 000000000101.9225 If you use std::setprecision(17) you will get the same values as GDB shows: 090.842500000000001 000000000101.9225 If you use std::setprecision(18) you'll see that Andreas is correct: 090.8425000000000011 0101.922499999999999 This is not a GCC bug, this is just how floating-point numbers work.=