public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/41867]  New: Translation time Floating Point precision is too small
@ 2009-10-29 15:13 tydeman at tybor dot com
  2009-10-29 15:48 ` [Bug c/41867] " joseph at codesourcery dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: tydeman at tybor dot com @ 2009-10-29 15:13 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-10-31 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-29 15:13 [Bug c/41867] New: Translation time Floating Point precision is too small tydeman at tybor dot com
2009-10-29 15:48 ` [Bug c/41867] " joseph at codesourcery dot com
2009-10-29 19:27 ` tydeman at tybor dot com
2009-10-29 20:26 ` jsm28 at gcc dot gnu dot org
2009-10-31 17:43 ` tydeman at tybor dot com
2009-10-31 18:37 ` jsm28 at gcc dot gnu dot org

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).