1 /* Basic tests for _FloatN / _FloatNx types: compile and execution
2 tests for valid code. Before including this file, define WIDTH as
3 the value N; define EXT to 1 for _FloatNx and 0 for _FloatN. */
4
5 #include <stdarg.h>
6
7 #define CONCATX(X, Y) X ## Y
8 #define CONCAT(X, Y) CONCATX (X, Y)
9 #define CONCAT3(X, Y, Z) CONCAT (CONCAT (X, Y), Z)
10 #define CONCAT4(W, X, Y, Z) CONCAT (CONCAT (CONCAT (W, X), Y), Z)
11
12 #if EXT
13 # define TYPE CONCAT3 (_Float, WIDTH, x)
14 # define CST(C) CONCAT4 (C, f, WIDTH, x)
15 # define CSTU(C) CONCAT4 (C, F, WIDTH, x)
16 #else
17 # define TYPE CONCAT (_Float, WIDTH)
18 # define CST(C) CONCAT3 (C, f, WIDTH)
19 # define CSTU(C) CONCAT3 (C, F, WIDTH)
20 #endif
21
22 extern void exit (int);
23 extern void abort (void);
24
25 volatile TYPE a = CST (1.0), b = CSTU (2.5), c = -CST (2.5);
26 volatile TYPE a2 = CST (1.0), z = CST (0.0), nz = -CST (0.0);
27
28 /* These types are not subject to default argument promotions. */
29
30 TYPE
vafn(TYPE arg1,...)31 vafn (TYPE arg1, ...)
32 {
33 va_list ap;
34 TYPE ret;
35 va_start (ap, arg1);
36 ret = arg1 + va_arg (ap, TYPE);
37 va_end (ap);
38 return ret;
39 }
40
41 TYPE
krfn(arg)42 krfn (arg)
43 TYPE arg;
44 {
45 return arg + 1;
46 }
47
48 TYPE krprofn (TYPE);
49 TYPE
krprofn(arg)50 krprofn (arg)
51 TYPE arg;
52 {
53 return arg * 3;
54 }
55
56 TYPE
profn(TYPE arg)57 profn (TYPE arg)
58 {
59 return arg / 4;
60 }
61
62 int
main(void)63 main (void)
64 {
65 volatile TYPE r;
66 r = -b;
67 if (r != c)
68 abort ();
69 r = a + b;
70 if (r != CST (3.5))
71 abort ();
72 r = a - b;
73 if (r != -CST (1.5))
74 abort ();
75 r = 2 * c;
76 if (r != -5)
77 abort ();
78 r = b * c;
79 if (r != -CST (6.25))
80 abort ();
81 r = b / (a + a);
82 if (r != CST (1.25))
83 abort ();
84 r = c * 3;
85 if (r != -CST (7.5))
86 abort ();
87 volatile int i = r;
88 if (i != -7)
89 abort ();
90 r = vafn (a, c);
91 if (r != -CST (1.5))
92 abort ();
93 r = krfn (b);
94 if (r != CST (3.5))
95 abort ();
96 r = krprofn (a);
97 if (r != CST (3.0))
98 abort ();
99 r = profn (a);
100 if (r != CST (0.25))
101 abort ();
102 if ((a < b) != 1)
103 abort ();
104 if ((b < a) != 0)
105 abort ();
106 if ((a < a2) != 0)
107 abort ();
108 if ((nz < z) != 0)
109 abort ();
110 if ((a <= b) != 1)
111 abort ();
112 if ((b <= a) != 0)
113 abort ();
114 if ((a <= a2) != 1)
115 abort ();
116 if ((nz <= z) != 1)
117 abort ();
118 if ((a > b) != 0)
119 abort ();
120 if ((b > a) != 1)
121 abort ();
122 if ((a > a2) != 0)
123 abort ();
124 if ((nz > z) != 0)
125 abort ();
126 if ((a >= b) != 0)
127 abort ();
128 if ((b >= a) != 1)
129 abort ();
130 if ((a >= a2) != 1)
131 abort ();
132 if ((nz >= z) != 1)
133 abort ();
134 i = (nz == z);
135 if (i != 1)
136 abort ();
137 i = (a == b);
138 if (i != 0)
139 abort ();
140 exit (0);
141 }
142