Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/ieee/fp-cmp-5.c

raw
1 /* Like fp-cmp-4.c, but test that the setcc patterns are correct. */
2
3 void abort (void);
4 void exit (int);
5
6 static int
7 test_isunordered(double x, double y)
8 {
9 return __builtin_isunordered(x, y);
10 }
11
12 static int
13 test_not_isunordered(double x, double y)
14 {
15 return !__builtin_isunordered(x, y);
16 }
17
18 static int
19 test_isless(double x, double y)
20 {
21 return __builtin_isless(x, y);
22 }
23
24 static int
25 test_not_isless(double x, double y)
26 {
27 return !__builtin_isless(x, y);
28 }
29
30 static int
31 test_islessequal(double x, double y)
32 {
33 return __builtin_islessequal(x, y);
34 }
35
36 static int
37 test_not_islessequal(double x, double y)
38 {
39 return !__builtin_islessequal(x, y);
40 }
41
42 static int
43 test_isgreater(double x, double y)
44 {
45 return __builtin_isgreater(x, y);
46 }
47
48 static int
49 test_not_isgreater(double x, double y)
50 {
51 return !__builtin_isgreater(x, y);
52 }
53
54 static int
55 test_isgreaterequal(double x, double y)
56 {
57 return __builtin_isgreaterequal(x, y);
58 }
59
60 static int
61 test_not_isgreaterequal(double x, double y)
62 {
63 return !__builtin_isgreaterequal(x, y);
64 }
65
66 static int
67 test_islessgreater(double x, double y)
68 {
69 return __builtin_islessgreater(x, y);
70 }
71
72 static int
73 test_not_islessgreater(double x, double y)
74 {
75 return !__builtin_islessgreater(x, y);
76 }
77
78 static void
79 one_test(double x, double y, int expected,
80 int (*pos) (double, double), int (*neg) (double, double))
81 {
82 if ((*pos)(x, y) != expected)
83 abort ();
84 if ((*neg)(x, y) != !expected)
85 abort ();
86 }
87
88 #define NAN (0.0 / 0.0)
89
90 int
91 main()
92 {
93 struct try
94 {
95 double x, y;
96 int result[6];
97 };
98
99 static struct try const data[] =
100 {
101 { NAN, NAN, { 1, 0, 0, 0, 0, 0 } },
102 { 0.0, NAN, { 1, 0, 0, 0, 0, 0 } },
103 { NAN, 0.0, { 1, 0, 0, 0, 0, 0 } },
104 { 0.0, 0.0, { 0, 0, 1, 0, 1, 0 } },
105 { 1.0, 2.0, { 0, 1, 1, 0, 0, 1 } },
106 { 2.0, 1.0, { 0, 0, 0, 1, 1, 1 } },
107 };
108
109 struct test
110 {
111 int (*pos)(double, double);
112 int (*neg)(double, double);
113 };
114
115 static struct test const tests[] =
116 {
117 { test_isunordered, test_not_isunordered },
118 { test_isless, test_not_isless },
119 { test_islessequal, test_not_islessequal },
120 { test_isgreater, test_not_isgreater },
121 { test_isgreaterequal, test_not_isgreaterequal },
122 { test_islessgreater, test_not_islessgreater }
123 };
124
125 const int n = sizeof(data) / sizeof(data[0]);
126 int i, j;
127
128 for (i = 0; i < n; ++i)
129 for (j = 0; j < 6; ++j)
130 one_test (data[i].x, data[i].y, data[i].result[j],
131 tests[j].pos, tests[j].neg);
132
133 exit (0);
134 }