Bug 66282 - Missing x86 floating point conversion on explicit casts violates C standard
Summary: Missing x86 floating point conversion on explicit casts violates C standard
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2015-05-25 21:27 UTC by Timo Kreuzer
Modified: 2015-05-29 16:49 UTC (History)
0 users

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Timo Kreuzer 2015-05-25 21:27:41 UTC
When compiling floating point code, the compiler omits to convert an intermediate computation result, which is cast to double, to 64 bit precision and instead keeps the internal 80 bit precision.

Example code:

void bugbug()
    double x = 4.4;
    double y;

    y = (1 / x);
    if ( y != ((double)(1 / x)) )
        printf("Standard violation!\n");

compiled with "gcc.exe -Wall -g -c fpu.c -o fpu.o"

The expression on the right side inside the if() is not converted to double precision, which is in violation of the C standard.

"Implementations employing wide registers have to take care to honor appropriate
semantics. Values are independent of whether they are represented in a register or in memory. For example, an implicit spilling of a register is not permitted to alter the value. Also, an explicit store and load is required to round to the precision of the storage type. In particular, casts and assignments are required to perform their specified conversion."

Emphasis is on the last sentence.

This was tested on a mingw version of the compiler, but I do not think this is mingw specific.
Comment 1 Andrew Pinski 2015-05-25 22:07:15 UTC
I think 4.9 and above implement this semantics.
Comment 2 Joseph S. Myers 2015-05-29 16:49:49 UTC
To discard intermediate excess precision, use -fexcess-precision=standard or an option implying it such as -ansi or -std=c99 or -std=c11.

*** This bug has been marked as a duplicate of bug 323 ***