Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / fpprec-1.c
blob0174e7c6c324fa5ff2619c6a76c22301b5f9d43b
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fno-math-errno -fno-trapping-math -msse2 -mfpmath=sse" } */
4 #include "sse2-check.h"
6 double x[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
7 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023, /* +-DBL_MAX */
8 -0x1p-52, 0x1p-52, /* +-DBL_EPSILON */
9 /* nextafter/before 0.5, 1.0 and 1.5 */
10 0x1.0000000000001p-1, 0x1.fffffffffffffp-2,
11 0x1.0000000000001p+0, 0x1.fffffffffffffp-1,
12 0x1.8000000000001p+0, 0x1.7ffffffffffffp+0,
13 -0.0, 0.0, -0.5, 0.5, -1.0, 1.0, -1.5, 1.5, -2.0, 2.0,
14 -2.5, 2.5 };
15 #define NUM (sizeof(x)/sizeof(double))
17 double expect_round[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
18 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
19 -0.0, 0.0,
20 1.0, 0.0, 1.0, 1.0, 2.0, 1.0,
21 -0.0, 0.0, -1.0, 1.0, -1.0, 1.0, -2.0, 2.0, -2.0, 2.0,
22 -3.0, 3.0 };
24 double expect_rint[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
25 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
26 -0.0, 0.0,
27 1.0, 0.0, 1.0, 1.0, 2.0, 1.0,
28 -0.0, 0.0, -0.0, 0.0, -1.0, 1.0, -2.0, 2.0, -2.0, 2.0,
29 -2.0, 2.0 };
31 double expect_floor[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
32 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
33 -1.0, 0.0,
34 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
35 -0.0, 0.0, -1.0, 0.0, -1.0, 1.0, -2.0, 1.0, -2.0, 2.0,
36 -3.0, 2.0 };
38 double expect_ceil[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
39 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
40 -0.0, 1.0,
41 1.0, 1.0, 2.0, 1.0, 2.0, 2.0,
42 -0.0, 0.0, -0.0, 1.0, -1.0, 1.0, -1.0, 2.0, -2.0, 2.0,
43 -2.0, 3.0 };
45 double expect_trunc[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
46 -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
47 -0.0, 0.0,
48 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
49 -0.0, 0.0, -0.0, 0.0, -1.0, 1.0, -1.0, 1.0, -2.0, 2.0,
50 -2.0, 2.0 };
53 #define CHECK(fn) \
54 void check_ ## fn (void) \
55 { \
56 int i; \
57 for (i = 0; i < NUM; ++i) \
58 { \
59 double res = __builtin_ ## fn (x[i]); \
60 if (__builtin_memcmp (&res, &expect_ ## fn [i], sizeof(double)) != 0) \
61 printf( # fn " [%i]: %.18e %.18e\n", i, expect_ ## fn [i], res), abort (); \
62 } \
65 CHECK(round)
66 CHECK(rint)
67 CHECK(floor)
68 CHECK(ceil)
69 CHECK(trunc)
71 static void
72 sse2_test (void)
74 check_round ();
75 check_rint ();
76 check_floor ();
77 check_ceil ();
78 check_trunc ();