The following code fails on (at least) Intel x86/x87 systems running Linux:
/* * From C99: * 6.6 Constant expressions * * #5 An expression that evaluates to a constant is required in several * contexts. If a floating expression is evaluated in the translation * environment, the arithmetic precision and range shall be at least * as great as if the expression were being evaluated in the execution * environment. */ #include <float.h> /* *_EPSILON */ #include <stdio.h> /* printf() */ /* * Compute epsilon == Unit Last Place; may be + or - depends upon rounding. */ #define Q2 (((4.F /3.F - 1.F ) - 1.F /4.F )*3.F - 1.F /4.F ) /* * File scope is translation time */ static long double fs_ld2 = Q2; static double fs_d2 = Q2; static float fs_f2 = Q2; int main(void){ /* * Local scope is runtime */ long double ls_ld2 = Q2; double ls_d2 = Q2; float ls_f2 = Q2; if( fs_ld2 != ls_ld2 ){ (void)printf(" 1: BFP: translation time != runtime\n"); } if( fs_d2 != ls_d2 ){ (void)printf(" 2: BFP: translation time != runtime\n"); } if( fs_f2 != ls_f2 ){ (void)printf(" 3: BFP: translation time != runtime\n"); } if( fs_ld2 != fs_d2 ){ (void)printf(" 7: BFP: translation time: variable precision\n"); } if( fs_d2 != fs_f2 ){ (void)printf(" 8: BFP: translation time: variable precision\n"); } if( ls_ld2 != ls_d2 ){ (void)printf("11: BFP:runtime: variable precision\n"); } if( ls_d2 != ls_f2 ){ (void)printf("12: BFP:runtime: variable precision\n"); } (void)printf("ls_ld2=%Lg\n", ls_ld2); (void)printf("ls_d2 =%g\n", ls_d2); (void)printf("ls_f2 =%g\n", ls_f2); (void)printf("LD_EPS=%Lg\n", LDBL_EPSILON); (void)printf(" D_EPS=%g\n", DBL_EPSILON); (void)printf(" F_EPS=%g\n", FLT_EPSILON); (void)printf("fs_ld2=%Lg\n", fs_ld2); (void)printf("fs_d2 =%g\n", fs_d2); (void)printf("fs_f2 =%g\n", fs_f2); return 0; } -- Summary: Translation time Floating Point precision is too small Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tydeman at tybor dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41867