1*433d6423SLionel Sambuc /* test66: test a whole bunch of basic comparisons.
2*433d6423SLionel Sambuc *
3*433d6423SLionel Sambuc * this test can be used both to generate test cases and run the test
4*433d6423SLionel Sambuc * case. all the results to be computed are in myresults[] on each iteration.
5*433d6423SLionel Sambuc * invoke the test with an argument, e.g. "./test66 gen" to generate
6*433d6423SLionel Sambuc * test66expected.h. then recompile, and run the result. so all you
7*433d6423SLionel Sambuc * have to do to add a (integer-valued) test expression as a function
8*433d6423SLionel Sambuc * of an int, float or double, is increase SUBRESULTS, add the expression
9*433d6423SLionel Sambuc * to myresults[], and regenerate the desired results file.
10*433d6423SLionel Sambuc */
11*433d6423SLionel Sambuc
12*433d6423SLionel Sambuc #include <stdio.h>
13*433d6423SLionel Sambuc #include <assert.h>
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc int max_error = 10;
16*433d6423SLionel Sambuc #include "common.h"
17*433d6423SLionel Sambuc
18*433d6423SLionel Sambuc
19*433d6423SLionel Sambuc
20*433d6423SLionel Sambuc #define RESULTSNAME desired
21*433d6423SLionel Sambuc #define SUBRESULTS 131
22*433d6423SLionel Sambuc
23*433d6423SLionel Sambuc int desired[][SUBRESULTS] = {
24*433d6423SLionel Sambuc #include "test66expected.h"
25*433d6423SLionel Sambuc };
26*433d6423SLionel Sambuc
27*433d6423SLionel Sambuc #define CASES (sizeof(desired)/sizeof(desired[0]))
28*433d6423SLionel Sambuc
main(int argc,char * argv[])29*433d6423SLionel Sambuc int main(int argc, char *argv[])
30*433d6423SLionel Sambuc {
31*433d6423SLionel Sambuc int a, b;
32*433d6423SLionel Sambuc int gen = 0;
33*433d6423SLionel Sambuc int n = 0;
34*433d6423SLionel Sambuc
35*433d6423SLionel Sambuc if(argc != 1) gen = 1;
36*433d6423SLionel Sambuc else start(66);
37*433d6423SLionel Sambuc
38*433d6423SLionel Sambuc for(a = -10; a < 10; a++) {
39*433d6423SLionel Sambuc for(b = -10; b < 10; b++) {
40*433d6423SLionel Sambuc float fa = a/4.0, fb = b/4.0;
41*433d6423SLionel Sambuc double da = a/4.0, db = b/4.0;
42*433d6423SLionel Sambuc signed long long a64s = a, b64s = b, ds, ms;
43*433d6423SLionel Sambuc unsigned long long a64u = a, b64u = b, mu;
44*433d6423SLionel Sambuc signed long a32s = a, b32s = b, ds32, ms32;
45*433d6423SLionel Sambuc unsigned long a32u = a, b32u = b, mu32;
46*433d6423SLionel Sambuc
47*433d6423SLionel Sambuc /* indicate no result */
48*433d6423SLionel Sambuc mu32 = ds32 = ms32 = mu = ds = ms = 31337;
49*433d6423SLionel Sambuc
50*433d6423SLionel Sambuc if(b64s != 0) {
51*433d6423SLionel Sambuc /* some 64-bit arithmetic */
52*433d6423SLionel Sambuc ds = a64s/b64s; ms = a64s%b64s;
53*433d6423SLionel Sambuc mu = a64u%b64u;
54*433d6423SLionel Sambuc ds32 = a32s/b32s; ms32 = a32s%b32s;
55*433d6423SLionel Sambuc mu32 = a32u%b32u;
56*433d6423SLionel Sambuc }
57*433d6423SLionel Sambuc
58*433d6423SLionel Sambuc int myresults[SUBRESULTS] = {
59*433d6423SLionel Sambuc /* these results lots of combinations of float, double, int
60*433d6423SLionel Sambuc * and signed and unsigned 64-bit comparisons (and therefore
61*433d6423SLionel Sambuc * also conversions).
62*433d6423SLionel Sambuc */
63*433d6423SLionel Sambuc a < b, a <= b, a == b, a >= b, a > b, a < fb, a <= fb, a == fb,
64*433d6423SLionel Sambuc a >= fb, a > fb, a < db, a <= db, a == db, a >= db, a > db, a < b64s,
65*433d6423SLionel Sambuc a <= b64s, a == b64s, a >= b64s, a > b64s, a < b64u, a <= b64u, a == b64u,
66*433d6423SLionel Sambuc a >= b64u, a > b64u, fa < b, fa <= b, fa == b, fa >= b, fa > b, fa < fb,
67*433d6423SLionel Sambuc fa <= fb, fa == fb, fa >= fb, fa > fb, fa < db, fa <= db, fa == db,
68*433d6423SLionel Sambuc fa >= db, fa > db, fa < b64s, fa <= b64s, fa == b64s, fa >= b64s,
69*433d6423SLionel Sambuc fa > b64s, fa < b64u, fa <= b64u, fa == b64u, fa >= b64u, fa > b64u,
70*433d6423SLionel Sambuc da < b, da <= b, da == b, da >= b, da > b, da < fb, da <= fb, da == fb,
71*433d6423SLionel Sambuc da >= fb, da > fb, da < db, da <= db, da == db, da >= db, da > db,
72*433d6423SLionel Sambuc da < b64s, da <= b64s, da == b64s, da >= b64s, da > b64s, da < b64u,
73*433d6423SLionel Sambuc da <= b64u, da == b64u, da >= b64u, da > b64u, a64s < b, a64s <= b, a64s == b,
74*433d6423SLionel Sambuc a64s >= b, a64s > b, a64s < fb, a64s <= fb, a64s == fb, a64s >= fb,
75*433d6423SLionel Sambuc a64s > fb, a64s < db, a64s <= db, a64s == db, a64s >= db, a64s > db,
76*433d6423SLionel Sambuc a64s < b64s, a64s <= b64s, a64s == b64s, a64s >= b64s, a64s > b64s,
77*433d6423SLionel Sambuc a64s < b64u, a64s <= b64u, a64s == b64u, a64s >= b64u, a64s > b64u, a64u < b,
78*433d6423SLionel Sambuc a64u <= b, a64u == b, a64u >= b, a64u > b, a64u < fb, a64u <= fb,
79*433d6423SLionel Sambuc a64u == fb, a64u >= fb, a64u > fb, a64u < db, a64u <= db, a64u == db,
80*433d6423SLionel Sambuc a64u >= db, a64u > db, a64u < b64s, a64u <= b64s, a64u == b64s,
81*433d6423SLionel Sambuc a64u >= b64s, a64u > b64s, a64u < b64u, a64u <= b64u, a64u == b64u,
82*433d6423SLionel Sambuc a64u >= b64u, a64u > b64u,
83*433d6423SLionel Sambuc
84*433d6423SLionel Sambuc /* 64-bit divison, modulo operations */
85*433d6423SLionel Sambuc (int) ds, (int) ms, (int) mu,
86*433d6423SLionel Sambuc
87*433d6423SLionel Sambuc /* 32-bit divison, modulo operations */
88*433d6423SLionel Sambuc (int) ds32, (int) ms32, (int) mu32
89*433d6423SLionel Sambuc
90*433d6423SLionel Sambuc };
91*433d6423SLionel Sambuc
92*433d6423SLionel Sambuc if(gen) {
93*433d6423SLionel Sambuc int r;
94*433d6423SLionel Sambuc printf("{ ");
95*433d6423SLionel Sambuc for(r = 0; r < SUBRESULTS; r++) {
96*433d6423SLionel Sambuc printf("%d, ", myresults[r]);
97*433d6423SLionel Sambuc }
98*433d6423SLionel Sambuc printf(" }, \n");
99*433d6423SLionel Sambuc } else {
100*433d6423SLionel Sambuc int subresults;
101*433d6423SLionel Sambuc int s;
102*433d6423SLionel Sambuc subresults = sizeof(desired[n])/
103*433d6423SLionel Sambuc sizeof(desired[n][0]);
104*433d6423SLionel Sambuc assert(subresults == SUBRESULTS);
105*433d6423SLionel Sambuc for(s = 0; s < subresults; s++) {
106*433d6423SLionel Sambuc if(desired[n][s] != myresults[s]) {
107*433d6423SLionel Sambuc printf("a, b = %d, %d: %d != %d\n",
108*433d6423SLionel Sambuc a, b, desired[n][s],
109*433d6423SLionel Sambuc myresults[s]);
110*433d6423SLionel Sambuc e(n);
111*433d6423SLionel Sambuc } else {
112*433d6423SLionel Sambuc assert(desired[n][s] == myresults[s]);
113*433d6423SLionel Sambuc }
114*433d6423SLionel Sambuc }
115*433d6423SLionel Sambuc }
116*433d6423SLionel Sambuc
117*433d6423SLionel Sambuc n++;
118*433d6423SLionel Sambuc }
119*433d6423SLionel Sambuc }
120*433d6423SLionel Sambuc
121*433d6423SLionel Sambuc if(!gen) {
122*433d6423SLionel Sambuc assert(n == CASES);
123*433d6423SLionel Sambuc quit();
124*433d6423SLionel Sambuc }
125*433d6423SLionel Sambuc
126*433d6423SLionel Sambuc return 0;
127*433d6423SLionel Sambuc }
128*433d6423SLionel Sambuc
129