1 /* Test front-end conversions, optimizer conversions, and run-time
2 conversions between different arithmetic types.
4 Constants are specified in a non-obvious way to make them work for
5 any word size. Their value on a 32-bit machine is indicated in the
8 Note that this code is NOT intended for testing of accuracy of fp
40 fnear (float x, float y)
43 return t == 0 || x / t > 1000000.0;
47 dnear (double x, double y)
50 return t == 0 || x / t > 100000000000000.0;
53 test_integer_to_float()
55 if (u2f(0U) != (float) 0U) /* 0 */
57 if (!fnear (u2f(~0U), (float) ~0U)) /* 0xffffffff */
59 if (!fnear (u2f((~0U) >> 1), (float) ((~0U) >> 1))) /* 0x7fffffff */
61 if (u2f(~((~0U) >> 1)) != (float) ~((~0U) >> 1)) /* 0x80000000 */
64 if (u2d(0U) != (double) 0U) /* 0 */
66 if (!dnear (u2d(~0U), (double) ~0U)) /* 0xffffffff */
68 if (!dnear (u2d((~0U) >> 1),(double) ((~0U) >> 1))) /* 0x7fffffff */
70 if (u2d(~((~0U) >> 1)) != (double) ~((~0U) >> 1)) /* 0x80000000 */
73 if (s2f(0) != (float) 0) /* 0 */
75 if (!fnear (s2f(~0), (float) ~0)) /* 0xffffffff */
77 if (!fnear (s2f((int)((~0U) >> 1)), (float)(int)((~0U) >> 1))) /* 0x7fffffff */
79 if (s2f((int)(~((~0U) >> 1))) != (float)(int)~((~0U) >> 1)) /* 0x80000000 */
82 if (s2d(0) != (double) 0) /* 0 */
84 if (!dnear (s2d(~0), (double) ~0)) /* 0xffffffff */
86 if (!dnear (s2d((int)((~0U) >> 1)), (double)(int)((~0U) >> 1))) /* 0x7fffffff */
88 if (s2d((int)~((~0U) >> 1)) != (double)(int)~((~0U) >> 1)) /* 0x80000000 */
95 unsigned long long int u;
102 unsigned long long int u;
121 test_longlong_integer_to_float()
123 if (ull2f(0ULL) != (float) 0ULL) /* 0 */
125 if (ull2f(~0ULL) != (float) ~0ULL) /* 0xffffffff */
127 if (ull2f((~0ULL) >> 1) != (float) ((~0ULL) >> 1)) /* 0x7fffffff */
129 if (ull2f(~((~0ULL) >> 1)) != (float) ~((~0ULL) >> 1)) /* 0x80000000 */
132 if (ull2d(0ULL) != (double) 0ULL) /* 0 */
135 /* Some 68881 targets return values in fp0, with excess precision.
136 But the compile-time conversion to double works correctly. */
137 if (! dnear (ull2d(~0ULL), (double) ~0ULL)) /* 0xffffffff */
139 if (! dnear (ull2d((~0ULL) >> 1), (double) ((~0ULL) >> 1))) /* 0x7fffffff */
142 if (ull2d(~0ULL) != (double) ~0ULL) /* 0xffffffff */
144 if (ull2d((~0ULL) >> 1) != (double) ((~0ULL) >> 1)) /* 0x7fffffff */
147 if (ull2d(~((~0ULL) >> 1)) != (double) ~((~0ULL) >> 1)) /* 0x80000000 */
150 if (sll2f(0LL) != (float) 0LL) /* 0 */
152 if (sll2f(~0LL) != (float) ~0LL) /* 0xffffffff */
154 if (! fnear (sll2f((long long int)((~0ULL) >> 1)), (float)(long long int)((~0ULL) >> 1))) /* 0x7fffffff */
156 if (sll2f((long long int)(~((~0ULL) >> 1))) != (float)(long long int)~((~0ULL) >> 1)) /* 0x80000000 */
159 if (sll2d(0LL) != (double) 0LL) /* 0 */
161 if (sll2d(~0LL) != (double) ~0LL) /* 0xffffffff */
163 if (!dnear (sll2d((long long int)((~0ULL) >> 1)), (double)(long long int)((~0ULL) >> 1))) /* 0x7fffffff */
165 if (! dnear (sll2d((long long int)~((~0ULL) >> 1)), (double)(long long int)~((~0ULL) >> 1))) /* 0x80000000 */
194 test_float_to_integer()
204 if (f2u((float) ((~0U) >> 1)) != (~0U) >> 1 && /* 0x7fffffff */
205 f2u((float) ((~0U) >> 1)) != ((~0U) >> 1) + 1)
207 if (f2u((float) ~((~0U) >> 1)) != ~((~0U) >> 1)) /* 0x80000000 */
210 /* CYGNUS LOCAL -- amylaar/32bit doubles */
211 /* These tests require double precision, so for hosts that don't offer
212 that much precision, just ignore these test. */
213 if (sizeof (double) >= 8) {
214 /* END CYGNUS LOCAL -- amylaar/32bit doubles */
223 if (d2u((double) (~0U)) != ~0U) /* 0xffffffff */
225 if (d2u((double) ((~0U) >> 1)) != (~0U) >> 1) /* 0x7fffffff */
227 if (d2u((double) ~((~0U) >> 1)) != ~((~0U) >> 1)) /* 0x80000000 */
229 /* CYGNUS LOCAL -- amylaar/32bit doubles */
231 /* END CYGNUS LOCAL -- amylaar/32bit doubles */
242 if (f2s(-0.999) != 0)
246 if (f2s(-1.99) != -1)
248 if (f2s((float)(int)~((~0U) >> 1)) != (int)~((~0U) >> 1)) /* 0x80000000 */
251 /* CYGNUS LOCAL -- amylaar/32bit doubles */
252 /* These tests require double precision, so for hosts that don't offer
253 that much precision, just ignore these test. */
254 if (sizeof (double) >= 8) {
255 /* END CYGNUS LOCAL -- amylaar/32bit doubles */
264 if (d2s(-0.999) != 0)
268 if (d2s(-1.99) != -1)
270 if (d2s((double) ((~0U) >> 1)) != (~0U) >> 1) /* 0x7fffffff */
272 if (d2s((double)(int)~((~0U) >> 1)) != (int)~((~0U) >> 1)) /* 0x80000000 */
274 /* CYGNUS LOCAL -- amylaar/32bit doubles */
276 /* END CYGNUS LOCAL -- amylaar/32bit doubles */
280 unsigned long long int
283 return (unsigned long long int) f;
286 unsigned long long int
289 return (unsigned long long int) d;
295 return (long long int) f;
301 return (long long int) d;
304 test_float_to_longlong_integer()
306 if (f2ull(0.0) != 0LL)
308 if (f2ull(0.999) != 0LL)
310 if (f2ull(1.0) != 1LL)
312 if (f2ull(1.99) != 1LL)
314 if (f2ull((float) ((~0ULL) >> 1)) != (~0ULL) >> 1 && /* 0x7fffffff */
315 f2ull((float) ((~0ULL) >> 1)) != ((~0ULL) >> 1) + 1)
317 if (f2ull((float) ~((~0ULL) >> 1)) != ~((~0ULL) >> 1)) /* 0x80000000 */
320 if (d2ull(0.0) != 0LL)
322 if (d2ull(0.999) != 0LL)
324 if (d2ull(1.0) != 1LL)
326 if (d2ull(1.99) != 1LL)
328 if (d2ull((double) ((~0ULL) >> 1)) != (~0ULL) >> 1 && /* 0x7fffffff */
329 d2ull((double) ((~0ULL) >> 1)) != ((~0ULL) >> 1) + 1)
331 if (d2ull((double) ~((~0ULL) >> 1)) != ~((~0ULL) >> 1)) /* 0x80000000 */
335 if (f2sll(0.0) != 0LL)
337 if (f2sll(0.999) != 0LL)
339 if (f2sll(1.0) != 1LL)
341 if (f2sll(1.99) != 1LL)
343 if (f2sll(-0.999) != 0LL)
345 if (f2sll(-1.0) != -1LL)
347 if (f2sll(-1.99) != -1LL)
349 if (f2sll((float)(long long int)~((~0ULL) >> 1)) != (long long int)~((~0ULL) >> 1)) /* 0x80000000 */
352 if (d2sll(0.0) != 0LL)
354 if (d2sll(0.999) != 0LL)
356 if (d2sll(1.0) != 1LL)
358 if (d2sll(1.99) != 1LL)
360 if (d2sll(-0.999) != 0LL)
362 if (d2sll(-1.0) != -1LL)
364 if (d2sll(-1.99) != -1LL)
366 if (d2sll((double)(long long int)~((~0ULL) >> 1)) != (long long int)~((~0ULL) >> 1)) /* 0x80000000 */
373 test_integer_to_float();
374 test_float_to_integer();
376 test_longlong_integer_to_float();
377 test_float_to_longlong_integer();