- added missing base in two test cases
[libfirm] / ir / be / test / floatcmp.c
1 /*$ -std=c99 $*/
2
3 #include <stdio.h>
4 #include <math.h>
5
6 #define test(type, name, op)                    \
7 static void test_##type##_##name(type a, type b) {       \
8   if (a op b)                                   \
9     printf("%f " #op " %f = true\n", a, b);    \
10   else                                          \
11     printf("%f " #op " %f = false\n", a, b);   \
12 }
13
14 #define testu(type, op)                    \
15 static void test_##type##_##op(type a, type b) {       \
16   if (op(a,b))                                   \
17     printf(#op "(%f, %f) = true\n", a, b);    \
18   else                                          \
19     printf(#op "(%f, %f) = false\n", a, b);   \
20 }
21
22 #define testnu(type, op)                    \
23 static void test_##type##_not##op(type a, type b) {       \
24   if (!op(a,b))                                 \
25     printf("!" #op "(%f, %f) = true\n", a, b);  \
26   else                                          \
27     printf("!" #op "(%f, %f) = false\n", a, b); \
28 }
29
30 test(float, l,  <)
31 test(float, le, <=)
32 test(float, eq, ==)
33 test(float, ge, >=)
34 test(float, g,  >)
35 test(float, lg, !=)
36
37 testu(float, isgreater)
38 testu(float, isgreaterequal)
39 testu(float, isless)
40 testu(float, islessequal)
41 testu(float, islessgreater)
42 testu(float, isunordered)
43
44 testnu(float, isgreater)
45 testnu(float, isgreaterequal)
46 testnu(float, isless)
47 testnu(float, islessequal)
48 testnu(float, islessgreater)
49 testnu(float, isunordered)
50
51 /*-------------------------- */
52 test(double, l,  <)
53 test(double, le, <=)
54 test(double, eq, ==)
55 test(double, ge, >=)
56 test(double, g,  >)
57 test(double, lg, !=)
58
59 testu(double, isgreater)
60 testu(double, isgreaterequal)
61 testu(double, isless)
62 testu(double, islessequal)
63 testu(double, islessgreater)
64 testu(double, isunordered)
65
66 testnu(double, isgreater)
67 testnu(double, isgreaterequal)
68 testnu(double, isless)
69 testnu(double, islessequal)
70 testnu(double, islessgreater)
71 testnu(double, isunordered)
72
73 #undef test
74
75 double dA = 3.0, dB = 4.0, dNan = NAN;
76 float fA = 3.0, fB = 4.0, fNan = NAN;
77
78 int main() {
79 #define test(type, name, a, b) test_##type##_##name(a,b)
80
81   test(float, l,  fA, fB);
82   test(float, le, fA, fB);
83   test(float, eq, fA, fB);
84   test(float, ge, fA, fB);
85   test(float, g,  fA, fB);
86   test(float, lg, fA, fB);
87   test(float, l,  fA, fNan);
88   test(float, le, fA, fNan);
89   test(float, eq, fA, fNan);
90   test(float, ge, fA, fNan);
91   test(float, g,  fA, fNan);
92   test(float, lg, fA, fNan);
93   test(float, lg, fNan, fNan);
94
95   test(float, isgreater, fA, fB);
96   test(float, isgreaterequal, fA, fB);
97   test(float, isless, fA, fB);
98   test(float, islessequal, fA, fB);
99   test(float, islessgreater, fA, fB);
100   test(float, isunordered, fA, fB);
101   test(float, isgreater, fA, fNan);
102   test(float, isgreaterequal, fA, fNan);
103   test(float, isless, fA, fNan);
104   test(float, islessequal, fA, fNan);
105   test(float, islessgreater, fA, fNan);
106   test(float, isunordered, fA, fNan);
107   test(double, islessgreater, fA, fB);
108   test(float, islessgreater, fNan, fNan);
109
110   test(float, notisgreater, fA, fNan);
111   test(float, notisgreaterequal, fA, fNan);
112   test(float, notisless, fA, fNan);
113   test(float, notislessequal, fA, fNan);
114   test(float, notislessgreater, fA, fNan);
115   test(float, notisunordered, fA, fNan);
116
117   test(double, l,  dA, dB);
118   test(double, le, dA, dB);
119   test(double, eq, dA, dB);
120   test(double, ge, dA, dB);
121   test(double, g,  dA, dB);
122   test(double, lg, dA, dB);
123   test(double, l,  dA, dNan);
124   test(double, le, dA, dNan);
125   test(double, eq, dA, dNan);
126   test(double, ge, dA, dNan);
127   test(double, g,  dA, dNan);
128   test(double, lg, dA, dNan);
129   test(double, lg, dNan, dNan);
130
131   test(double, isgreater, dA, dB);
132   test(double, isgreaterequal, dA, dB);
133   test(double, isless, dA, dB);
134   test(double, islessequal, dA, dB);
135   test(double, islessgreater, dA, dB);
136   test(double, isunordered, dA, dB);
137   test(double, isgreater, dA, dNan);
138   test(double, isgreaterequal, dA, dNan);
139   test(double, isless, dA, dNan);
140   test(double, islessequal, dA, dNan);
141   test(double, islessgreater, dA, dNan);
142   test(double, isunordered, dA, dNan);
143   test(double, islessgreater, dA, dB);
144   test(double, islessgreater, dNan, dNan);
145
146   test(double, notisgreater, dA, dNan);
147   test(double, notisgreaterequal, dA, dNan);
148   test(double, notisless, dA, dNan);
149   test(double, notislessequal, dA, dNan);
150   test(double, notislessgreater, dA, dNan);
151   test(double, notisunordered, dA, dNan);
152 }