1 /* Determine some float parameters, much like gcc's "enquire.c". */
2 /* Bruno Haible 24.8.1996 */
4 /* This program expects to be compiled by an ANSI C or C++ compiler. */
8 #if !(defined(__STDC__) || defined(__cplusplus))
9 /* Only for use in function parameter lists and as function return type. */
17 #ifdef HAVE_LONGDOUBLE
18 typedef long double ldouble;
21 static void header (void)
23 printf("/* Rounding modes, for use below */\n");
24 printf("#define rounds_to_nearest 0 /* 0.5 ulp */\n");
25 printf("#define rounds_to_zero 1 /* 1 ulp */\n");
26 printf("#define rounds_to_infinity 2 /* 1 ulp */\n");
27 printf("#define rounds_to_minus_infinity 3 /* 1 ulp */\n");
31 #define check(type,typeprefix,typestr,equalfn,mainfn) \
32 static boolean equalfn (type* x, type* y); \
33 static void mainfn (void) \
36 int epsilon_bits = -1; \
37 int negepsilon_bits = -1; \
38 { type x = 1.0; type y; type z; \
39 for (y = 1.0; ; y = 0.5*y) \
40 { z = x + y; if (equalfn(&x,&z)) break; \
41 z = z - x; if (!equalfn(&y,&z)) break; \
44 { type x = 1.0; type y; type z; \
45 for (y = -1.0; ; y = 0.5*y) \
46 { z = x + y; if (equalfn(&x,&z)) break; \
47 z = z - x; if (!equalfn(&y,&z)) break; \
50 printf("/* Properties of type `%s': */\n",typestr); \
51 printf("/* Largest n for which 1+2^(-n) is exactly represented is %d. */\n",epsilon_bits); \
52 printf("/* Largest n for which 1-2^(-n) is exactly represented is %d. */\n",negepsilon_bits); \
53 if (negepsilon_bits <= epsilon_bits) \
54 { printf("#error \"No exponent jump at 1.0 for type %s!\"\n",typestr); \
58 { if (negepsilon_bits > epsilon_bits+1) \
59 printf("/* Base for type `%s' is 2^%d\n",typestr,negepsilon_bits-epsilon_bits); \
60 mant_bits = epsilon_bits+1; \
61 printf("#define %s_mant_bits %d\n",typeprefix,mant_bits); \
63 { int i; type x, y1, y2, ys1, ys2, z1, z2, zs1, zs2; \
64 x = 1.0; for (i = 0; i < epsilon_bits; i++) { x = 0.5*x; } \
65 y1 = 1.0 + 5.0*x; y2 = 1.0 + 6.0*x; \
66 ys1 = 1.0 + 5.4*x; ys2 = 1.0 + 5.6*x; \
67 z1 = -1.0 + (-5.0)*x; z2 = -1.0 + (-6.0)*x; \
68 zs1 = -1.0 + (-5.4)*x; zs2 = -1.0 + (-5.6)*x; \
69 if (equalfn(&ys1,&y1) && equalfn(&ys2,&y2) && equalfn(&zs1,&z1) && equalfn(&zs2,&z2)) \
70 printf("#define %s_rounds rounds_to_nearest\n",typeprefix); \
71 else if (equalfn(&ys1,&y1) && equalfn(&ys2,&y1) && equalfn(&zs1,&z1) && equalfn(&zs2,&z1)) \
72 printf("#define %s_rounds rounds_to_zero\n",typeprefix); \
73 else if (equalfn(&ys1,&y2) && equalfn(&ys2,&y2) && equalfn(&zs1,&z1) && equalfn(&zs2,&z1)) \
74 printf("#define %s_rounds rounds_to_infinity\n",typeprefix); \
75 else if (equalfn(&ys1,&y1) && equalfn(&ys2,&y1) && equalfn(&zs1,&z2) && equalfn(&zs2,&z2)) \
76 printf("#define %s_rounds rounds_to_minus_infinity\n",typeprefix); \
78 printf("#error \"Unknown rounding mode for type %s!\"\n",typestr); \
82 static boolean equalfn (type* x, type* y) { return *x == *y; } \
84 check(float,"float","float",equal_float,main_float)
85 check(double,"double","double",equal_double,main_double)
86 #ifdef HAVE_LONGDOUBLE
87 check(ldouble,"long_double","long double",equal_ldouble,main_ldouble)
90 /* Some systems (arm/linux) store doubles as little endian but with higher
91 * and lower word reversed. */
92 static void flipped_double (void)
94 typedef struct { unsigned lo, hi; } dfloat;
95 union { dfloat eksplicit; double machine_double; } x;
97 dfloat test = x.eksplicit;
98 if (test.lo==0 && test.hi!=0) {
99 printf("#define double_wordorder_bigendian_p 0\n");
100 } else if (test.lo!=0 && test.hi==0) {
101 printf("#define double_wordorder_bigendian_p 1\n");
103 /* Dazed and confused! Better not define anything.
104 * Code should rely on CL_CPU_BIG_ENDIAN_P instead. */
114 #ifdef HAVE_LONGDOUBLE
119 if (ferror(stdout)) return 1;