[Bug c/50773] float values are printed with greater precision than the float data type has when given as an argument to printf()
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Oct 18 10:43:00 GMT 2011
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;
}
More information about the Gcc-bugs
mailing list