public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110749] wrong show float
Date: Thu, 20 Jul 2023 10:03:15 +0000	[thread overview]
Message-ID: <bug-110749-4-EpRZlyDfta@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110749-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110749

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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 rounds
to 2).

101.92249999999999943 with 7 digits of precision is 101.9225 (because 49 rounds
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.

  parent reply	other threads:[~2023-07-20 10:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20  6:46 [Bug c++/110749] New: " alexsyrezerv at mail dot ru
2023-07-20  7:31 ` [Bug c++/110749] " schwab@linux-m68k.org
2023-07-20  9:09 ` alexsyrezerv at mail dot ru
2023-07-20 10:03 ` redi at gcc dot gnu.org [this message]
2023-07-20 10:58 ` alexsyrezerv at mail dot ru
2023-07-20 11:08 ` alexsyrezerv at mail dot ru
2023-07-20 12:10 ` redi at gcc dot gnu.org
2023-07-20 12:10 ` redi 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-110749-4-EpRZlyDfta@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: link
Be 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).