This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/50773] float values are printed with greater precision than the float data type has when given as an argument to printf()
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 18 Oct 2011 14:49:28 +0000
- Subject: [Bug c/50773] float values are printed with greater precision than the float data type has when given as an argument to printf()
- Auto-submitted: auto-generated
- References: <bug-50773-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50773
--- Comment #4 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2011-10-18 14:49:28 UTC ---
On Tue, 18 Oct 2011, rguenth at gcc dot gnu.org wrote:
> 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;
> }
I don't see any bug there. With -fexcess-precision=standard,
FLT_EVAL_METHOD is 2, "evaluate all operations and constants to the range
and precision of the long double type". Thus 268517138.f has type float
but a value represented to the precision of long double - and the
conversion to the precision of float takes place for the initialization
but not for the comparison. (Without -fexcess-precision=standard -
outside any conformance mode - FLT_EVAL_METHOD is still 2, but exactly
what happens is unpredictable.)