public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/50773] float values are printed with greater precision than the float data type has when given as an argument to printf()
Date: Tue, 18 Oct 2011 10:43:00 -0000	[thread overview]
Message-ID: <bug-50773-4-s2bW91W0PG@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-50773-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50773

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2011-10-18
                 CC|                            |jsm28 at gcc dot gnu.org
         Resolution|INVALID                     |
     Ever Confirmed|0                           |1
      Known to fail|                            |4.7.0

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-18 10:43:08 UTC ---
(In reply to comment #2)
> This is definitely a C front-end bug.  If you look at the gimple dump, you can
> see that the literal 268517138.f isn't being correctly truncated, but instead
> the constant 2.68517138e+8 is being used instead:
> 
> main (int argc, char * * argv)
> {
>   double D.2549;
>   const char * restrict D.2550;
>   double D.2551;
>   const char * restrict D.2552;
>   int D.2553;
>   float a;
> 
>   a = 2.68517152e+8;
>   D.2549 = (double) a;
>   D.2550 = (const char * restrict) &" 268517138.f = %f\t%f\n"[0];
>   printf (D.2550, 2.68517138e+8, D.2549);
> 
> C++ FE does it correctly:
> 
> int main(int, char**) (int argc, char * * argv)
> {
>   double D.2226;
>   double D.2227;
>   double D.2228;
>   double D.2229;
>   int D.2230;
> 
>   {
>     float a;
> 
>     a = 2.68517152e+8;
>     D.2226 = (double) a;
>     D.2227 = (double) 2.68517152e+8;
>     printf (&" 268517138.f = %f\t%f\n"[0], D.2227, D.2226);

Needs -fexcess-precision=standard -m32 to trigger.  libcpp does the
parsing of FP constants IIRC, and the C++ frontend does not implement
-fexcess-precision.

CCing Joseph.

Testcase that fails with -fexcess-precision=standard -m32:

extern void abort (void);
int
main()
{
      float a = 268517138.f;
      if (a != 268517138.f)
        abort ();
      return 0;
}


  parent reply	other threads:[~2011-10-18 10:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-18  9:34 [Bug c/50773] New: " momchil at xaxo dot eu
2011-10-18 10:06 ` [Bug c/50773] " rguenth at gcc dot gnu.org
2011-10-18 10:21 ` aph at gcc dot gnu.org
2011-10-18 10:43 ` rguenth at gcc dot gnu.org [this message]
2011-10-18 14:50 ` joseph at codesourcery dot com
2014-04-18 20:42 ` mpolacek 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-50773-4-s2bW91W0PG@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).