2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / excess-precision-3.c
blob3de61b4392393ab49ca065f4f6bd8710ec522a1d
1 /* Excess precision tests. Test excess precision is removed when
2 necessary. */
3 /* { dg-do run } */
4 /* { dg-options "-O2 -mfpmath=387 -fexcess-precision=standard" } */
6 #include <float.h>
7 #include <stdarg.h>
9 extern void abort (void);
10 extern void exit (int);
12 volatile float f1 = 1.0f;
13 volatile float f2 = 0x1.0p-30f;
14 volatile float f3 = 0x1.0p-60f;
15 volatile double d1 = 1.0;
16 volatile double d2 = 0x1.0p-30;
17 volatile double d3 = 0x1.0p-60;
18 volatile float fadd1 = 1.0f + 0x1.0p-30f;
19 volatile double dadd2 = 1.0 + 0x1.0p-30 + 0x1.0p-60;
20 volatile double dh = 0x1.0p-24;
21 volatile float fha = 1.0f + 0x1.0p-23f;
23 void
24 test_assign (void)
26 float f;
27 double d;
28 f = f1 + f2;
29 if (f != fadd1)
30 abort ();
31 d = f1 + f2;
32 if (d != dadd2)
33 abort ();
34 d = d1 + d2 + d3;
35 if (d != dadd2)
36 abort ();
37 /* Verify rounding direct to float without double rounding. */
38 f = d1 + dh + d3;
39 if (f != fha)
40 abort ();
43 void
44 test_init (void)
46 float f = f1 + f2;
47 double d = d1 + d2 + d3;
48 if (f != fadd1)
49 abort ();
50 if (d != dadd2)
51 abort ();
54 volatile int i1 = 0x40000001;
55 volatile unsigned int u1 = 0x80000001u;
56 volatile long long ll1 = 0x4000000000000001ll;
57 volatile unsigned long long ull1 = 0x8000000000000001ull;
59 void
60 test_cast (void)
62 if ((float)(f1 + f2) != fadd1)
63 abort ();
64 if ((double)(d1 + d2 + d3) != dadd2)
65 abort ();
66 if ((double)(f1 + f2 + f3) != dadd2)
67 abort ();
68 if ((float)i1 != 0x1.0p30f)
69 abort ();
70 if ((float)u1 != 0x1.0p31f)
71 abort ();
72 if ((float)ll1 != 0x1.0p62f)
73 abort ();
74 if ((float)ull1 != 0x1.0p63f)
75 abort ();
76 if ((double)ll1 != 0x1.0p62)
77 abort ();
78 if ((double)ull1 != 0x1.0p63)
79 abort ();
82 static inline void
83 check_float (float f)
85 if (f != fadd1)
86 abort ();
89 static inline void
90 check_double (double d)
92 if (d != dadd2)
93 abort ();
96 static inline void
97 check_float_nonproto (f)
98 float f;
100 if (f != fadd1)
101 abort ();
104 static inline void
105 check_double_nonproto (d)
106 double d;
108 if (d != dadd2)
109 abort ();
112 static void
113 check_double_va (int i, ...)
115 va_list ap;
116 va_start (ap, i);
117 if (va_arg (ap, double) != dadd2)
118 abort ();
119 va_end (ap);
122 void
123 test_call (void)
125 check_float (f1 + f2);
126 check_double (d1 + d2 + d3);
127 check_double (f1 + f2 + f3);
128 check_float_nonproto (f1 + f2);
129 check_double_nonproto (d1 + d2 + d3);
130 check_double_nonproto (f1 + f2 + f3);
131 check_double_va (0, d1 + d2 + d3);
132 check_double_va (0, f1 + f2 + f3);
135 static inline float
136 return_float (void)
138 return f1 + f2;
141 static inline double
142 return_double1 (void)
144 return d1 + d2 + d3;
147 static inline double
148 return_double2 (void)
150 return f1 + f2 + f3;
153 void
154 test_return (void)
156 if (return_float () != fadd1)
157 abort ();
158 if (return_double1 () != dadd2)
159 abort ();
160 if (return_double2 () != dadd2)
161 abort ();
164 volatile float flt_min = FLT_MIN;
165 volatile double dbl_min = DBL_MIN;
166 volatile float flt_max = FLT_MAX;
167 volatile double dbl_max = DBL_MAX;
169 void
170 test_builtin (void)
172 /* Classification macros convert to the semantic type. signbit and
173 comparison macros do not. */
174 if (!__builtin_isinf (flt_max * flt_max))
175 abort ();
176 if (!__builtin_isinf (dbl_max * dbl_max))
177 abort ();
178 if (__builtin_isnormal (flt_max * flt_max))
179 abort ();
180 if (__builtin_isnormal (dbl_max * dbl_max))
181 abort ();
182 if (__builtin_isfinite (flt_max * flt_max))
183 abort ();
184 if (__builtin_isfinite (dbl_max * dbl_max))
185 abort ();
186 if (!__builtin_isgreater (flt_min * flt_min, 0.0f))
187 abort ();
188 if (!__builtin_isgreaterequal (flt_min * flt_min, 0.0f))
189 abort ();
190 if (!__builtin_isless (0.0f, flt_min * flt_min))
191 abort ();
192 if (__builtin_islessequal (flt_min * flt_min, 0.0f))
193 abort ();
194 if (!__builtin_islessgreater (flt_min * flt_min, 0.0f))
195 abort ();
196 if (!__builtin_isgreater (dbl_min * dbl_min, 0.0))
197 abort ();
198 if (!__builtin_isgreaterequal (dbl_min * dbl_min, 0.0))
199 abort ();
200 if (!__builtin_isless (0.0, dbl_min * dbl_min))
201 abort ();
202 if (__builtin_islessequal (dbl_min * dbl_min, 0.0))
203 abort ();
204 if (!__builtin_islessgreater (dbl_min * dbl_min, 0.0))
205 abort ();
209 main (void)
211 test_assign ();
212 test_init ();
213 test_cast ();
214 test_call ();
215 test_return ();
216 test_builtin ();
217 exit (0);