1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/* Copyright (C) 2009 Free Software Foundation.
Verify that folding of built-in complex math functions with
constant arguments is correctly performed by the compiler.
Origin: Kaveh R. Ghazi, January 28, 2009. */
/* { dg-do link } */
/* All references to link_error should go away at compile-time. The
first number is the line number and the second is the value number
among several tests. These appear in the tree dump file and aid in
debugging. */
extern void link_error(int, int);
#define CONJ(X) __builtin_conjf(X)
/* Return TRUE if the signs of floating point values X and Y are not
equal. This is important when comparing signed zeros. */
#define CKSGN_F(X,Y) \
(__builtin_copysignf(1,(X)) != __builtin_copysignf(1,(Y)))
#define CKSGN(X,Y) \
(__builtin_copysign(1,(X)) != __builtin_copysign(1,(Y)))
#define CKSGN_L(X,Y) \
(__builtin_copysignl(1,(X)) != __builtin_copysignl(1,(Y)))
/* Return TRUE if signs of the real parts, and the signs of the
imaginary parts, of X and Y are not equal. */
#define COMPLEX_CKSGN_F(X,Y) \
(CKSGN_F(__real__ (X), __real__ (Y)) || CKSGN_F (__imag__ (X), __imag__ (Y)))
#define COMPLEX_CKSGN(X,Y) \
(CKSGN(__real__ (X), __real__ (Y)) || CKSGN (__imag__ (X), __imag__ (Y)))
#define COMPLEX_CKSGN_L(X,Y) \
(CKSGN_L(__real__ (X), __real__ (Y)) || CKSGN_L (__imag__ (X), __imag__ (Y)))
/* For complex numbers, test that FUNC(ARG) == (RES). */
#define TESTIT_COMPLEX(VAL_NUM, FUNC, ARG, RES) do { \
if (__builtin_##FUNC##f(ARG) != (RES) \
|| COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG), (RES))) \
link_error(__LINE__, VAL_NUM); \
if (__builtin_##FUNC(ARG) != (RES) \
|| COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
link_error(__LINE__, VAL_NUM); \
if (__builtin_##FUNC##l(ARG) != (RES) \
|| COMPLEX_CKSGN_L(__builtin_##FUNC##l(ARG), (RES))) \
link_error(__LINE__, VAL_NUM); \
} while (0)
/* For complex numbers, call the TESTIT_COMPLEX macro for all
combinations of neg and conj. */
#define TESTIT_COMPLEX_ALLNEG(FUNC, ARG, RES1, RES2, RES3, RES4) do { \
TESTIT_COMPLEX(1, FUNC, (_Complex float)(ARG), RES1); \
TESTIT_COMPLEX(2, FUNC, -CONJ(ARG), RES2); \
TESTIT_COMPLEX(3, FUNC, CONJ(ARG), RES3); \
TESTIT_COMPLEX(4, FUNC, -(_Complex float)(ARG), RES4); \
} while (0)
/* For complex numbers, call the TESTIT_COMPLEX_R macro for all
combinations of neg and conj. */
#define TESTIT_COMPLEX_R_ALLNEG(FUNC, ARG, RES1, RES2, RES3, RES4) do { \
TESTIT_COMPLEX_R(1, FUNC, (_Complex float)(ARG), RES1); \
TESTIT_COMPLEX_R(2, FUNC, -CONJ(ARG), RES2); \
TESTIT_COMPLEX_R(3, FUNC, CONJ(ARG), RES3); \
TESTIT_COMPLEX_R(4, FUNC, -(_Complex float)(ARG), RES4); \
} while (0)
/* For complex numbers, test that FUNC(ARG0, ARG1) == (RES). */
#define TESTIT_COMPLEX2(VAL_NUM, FUNC, ARG0, ARG1, RES) do { \
if (__builtin_##FUNC##f(ARG0, ARG1) != (RES) \
|| COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG0, ARG1), (RES))) \
link_error(__LINE__, VAL_NUM); \
if (__builtin_##FUNC(ARG0, ARG1) != (RES) \
|| COMPLEX_CKSGN(__builtin_##FUNC(ARG0, ARG1), (RES))) \
link_error(__LINE__, VAL_NUM); \
if (__builtin_##FUNC##l(ARG0, ARG1) != (RES) \
|| COMPLEX_CKSGN_L(__builtin_##FUNC##l(ARG0, ARG1), (RES))) \
link_error(__LINE__, VAL_NUM); \
} while (0)
/* For complex numbers, call the TESTIT_COMPLEX2 macro for all
combinations of neg and conj. */
#define TESTIT_COMPLEX2_ALLNEG(FUNC, ARG0, ARG1, RES1, RES2, RES3, RES4, RES5,\
RES6, RES7, RES8, RES9, RES10, RES11, RES12, RES13, RES14, RES15, RES16) do{ \
TESTIT_COMPLEX2(1, FUNC, (_Complex float)(ARG0),(_Complex float)(ARG1), RES1);\
TESTIT_COMPLEX2(2, FUNC, (_Complex float)(ARG0),CONJ(ARG1), RES2); \
TESTIT_COMPLEX2(3, FUNC, (_Complex float)(ARG0),-(_Complex float)(ARG1), RES3); \
TESTIT_COMPLEX2(4, FUNC, (_Complex float)(ARG0),-CONJ(ARG1), RES4); \
TESTIT_COMPLEX2(5, FUNC, -(_Complex float)(ARG0),(_Complex float)(ARG1), RES5); \
TESTIT_COMPLEX2(6, FUNC, -(_Complex float)(ARG0),CONJ(ARG1), RES6); \
TESTIT_COMPLEX2(7, FUNC, -(_Complex float)(ARG0),-(_Complex float)(ARG1), RES7); \
TESTIT_COMPLEX2(8, FUNC, -(_Complex float)(ARG0),-CONJ(ARG1), RES8); \
TESTIT_COMPLEX2(9, FUNC, CONJ(ARG0),(_Complex float)(ARG1), RES9); \
TESTIT_COMPLEX2(10, FUNC, CONJ(ARG0),CONJ(ARG1), RES10); \
TESTIT_COMPLEX2(11, FUNC, CONJ(ARG0),-(_Complex float)(ARG1), RES11); \
TESTIT_COMPLEX2(12, FUNC, CONJ(ARG0),-CONJ(ARG1), RES12); \
TESTIT_COMPLEX2(13, FUNC, -CONJ(ARG0),(_Complex float)(ARG1), RES13); \
TESTIT_COMPLEX2(14, FUNC, -CONJ(ARG0),CONJ(ARG1), RES14); \
TESTIT_COMPLEX2(15, FUNC, -CONJ(ARG0),-(_Complex float)(ARG1), RES15); \
TESTIT_COMPLEX2(16, FUNC, -CONJ(ARG0),-CONJ(ARG1), RES16); \
} while (0)
/* Return TRUE if X differs from EXPECTED by more than 1%. If
EXPECTED is zero, then any difference may return TRUE. We don't
worry about signed zeros. */
#define DIFF1PCT_F(X,EXPECTED) \
(__builtin_fabsf((X)-(EXPECTED)) * 100 > __builtin_fabsf(EXPECTED))
#define DIFF1PCT(X,EXPECTED) \
(__builtin_fabs((X)-(EXPECTED)) * 100 > __builtin_fabs(EXPECTED))
#define DIFF1PCT_L(X,EXPECTED) \
(__builtin_fabsl((X)-(EXPECTED)) * 100 > __builtin_fabsl(EXPECTED))
/* Return TRUE if complex value X differs from EXPECTED by more than
1% in either the real or imaginary parts. */
#define COMPLEX_DIFF1PCT_F(X,EXPECTED) \
(DIFF1PCT_F(__real__ (X), __real__ (EXPECTED)) \
|| DIFF1PCT_F(__imag__ (X), __imag__ (EXPECTED)))
#define COMPLEX_DIFF1PCT(X,EXPECTED) \
(DIFF1PCT(__real__ (X), __real__ (EXPECTED)) \
|| DIFF1PCT(__imag__ (X), __imag__ (EXPECTED)))
#define COMPLEX_DIFF1PCT_L(X,EXPECTED) \
(DIFF1PCT_L(__real__ (X), __real__ (EXPECTED)) \
|| DIFF1PCT_L(__imag__ (X), __imag__ (EXPECTED)))
/* Range test, for complex numbers check that FUNC(ARG) is within 1%
of RES. This is NOT a test for accuracy to the last-bit, we're
merely checking that we get relatively sane results. I.e. the GCC
builtin is hooked up to the correct MPC function call. We first
check the magnitude and then the sign. */
#define TESTIT_COMPLEX_R(VAL_NUM, FUNC, ARG, RES) do { \
if (COMPLEX_DIFF1PCT_F (__builtin_##FUNC##f(ARG), (RES)) \
|| COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG), (RES))) \
link_error(__LINE__, VAL_NUM); \
if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG), (RES)) \
|| COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
link_error(__LINE__, VAL_NUM); \
if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG), (RES)) \
|| COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
link_error(__LINE__, VAL_NUM); \
} while (0)
/* Range test, for complex numbers check that FUNC(ARG0, ARG1) is
within 1% of RES. This is NOT a test for accuracy to the last-bit,
we're merely checking that we get relatively sane results.
I.e. the GCC builtin is hooked up to the correct MPC function call.
We first check the magnitude and then the sign. */
#define TESTIT_COMPLEX_R2(VAL_NUM, FUNC, ARG0, ARG1, RES) do { \
if (COMPLEX_DIFF1PCT_F (__builtin_##FUNC##f(ARG0, ARG1), (RES)) \
|| COMPLEX_CKSGN_F (__builtin_##FUNC##f(ARG0, ARG1), (RES))) \
link_error(__LINE__, VAL_NUM); \
if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG0, ARG1), (RES)) \
|| COMPLEX_CKSGN (__builtin_##FUNC(ARG0, ARG1), (RES))) \
link_error(__LINE__, VAL_NUM); \
if (COMPLEX_DIFF1PCT_L (__builtin_##FUNC##l(ARG0, ARG1), (RES)) \
|| COMPLEX_CKSGN_L (__builtin_##FUNC##l(ARG0, ARG1), (RES))) \
link_error(__LINE__, VAL_NUM); \
} while (0)
/* For complex numbers, call the TESTIT_COMPLEX_R2 macro for all
combinations of neg and conj. */
#define TESTIT_COMPLEX_R2_ALLNEG(FUNC, ARG0, ARG1, RES1, RES2, RES3, RES4, RES5,\
RES6, RES7, RES8, RES9, RES10, RES11, RES12, RES13, RES14, RES15, RES16) do{ \
TESTIT_COMPLEX_R2(1, FUNC, (_Complex float)(ARG0),(_Complex float)(ARG1), RES1);\
TESTIT_COMPLEX_R2(2, FUNC, (_Complex float)(ARG0),CONJ(ARG1), RES2); \
TESTIT_COMPLEX_R2(3, FUNC, (_Complex float)(ARG0),-(_Complex float)(ARG1), RES3); \
TESTIT_COMPLEX_R2(4, FUNC, (_Complex float)(ARG0),-CONJ(ARG1), RES4); \
TESTIT_COMPLEX_R2(5, FUNC, -(_Complex float)(ARG0),(_Complex float)(ARG1), RES5); \
TESTIT_COMPLEX_R2(6, FUNC, -(_Complex float)(ARG0),CONJ(ARG1), RES6); \
TESTIT_COMPLEX_R2(7, FUNC, -(_Complex float)(ARG0),-(_Complex float)(ARG1), RES7); \
TESTIT_COMPLEX_R2(8, FUNC, -(_Complex float)(ARG0),-CONJ(ARG1), RES8); \
TESTIT_COMPLEX_R2(9, FUNC, CONJ(ARG0),(_Complex float)(ARG1), RES9); \
TESTIT_COMPLEX_R2(10, FUNC, CONJ(ARG0),CONJ(ARG1), RES10); \
TESTIT_COMPLEX_R2(11, FUNC, CONJ(ARG0),-(_Complex float)(ARG1), RES11); \
TESTIT_COMPLEX_R2(12, FUNC, CONJ(ARG0),-CONJ(ARG1), RES12); \
TESTIT_COMPLEX_R2(13, FUNC, -CONJ(ARG0),(_Complex float)(ARG1), RES13); \
TESTIT_COMPLEX_R2(14, FUNC, -CONJ(ARG0),CONJ(ARG1), RES14); \
TESTIT_COMPLEX_R2(15, FUNC, -CONJ(ARG0),-(_Complex float)(ARG1), RES15); \
TESTIT_COMPLEX_R2(16, FUNC, -CONJ(ARG0),-CONJ(ARG1), RES16); \
} while (0)
int main (void)
{
TESTIT_COMPLEX (1, cacos, 1, CONJ(0));
TESTIT_COMPLEX_R (1, cacos, -1, CONJ(3.141593F));
TESTIT_COMPLEX (1, cacos, CONJ(1), 0);
TESTIT_COMPLEX_R (1, cacos, CONJ(-1), 3.141593F);
TESTIT_COMPLEX_R_ALLNEG (cacos, 3.45678F + 2.34567FI,
0.60971F - 2.11780FI, 2.531875F - 2.117800FI,
0.60971F + 2.11780FI, 2.531875F + 2.117800FI);
TESTIT_COMPLEX_ALLNEG (casin, 0,
0, -CONJ(0), CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (casin, 3.45678F + 2.34567FI,
0.96107F + 2.11780FI, -0.96107F + 2.11780FI,
0.96107F - 2.11780FI, -0.96107F - 2.11780FI);
TESTIT_COMPLEX_ALLNEG (catan, 0,
0, -CONJ(0), CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (catan, 3.45678F + 2.34567FI,
1.37188F + 0.12997FI, -1.37188F + 0.12997FI,
1.37188F - 0.12997FI, -1.37188F - 0.12997FI);
TESTIT_COMPLEX (1, cacosh, 1, 0);
TESTIT_COMPLEX_R (1, cacosh, -1, 3.141593FI);
TESTIT_COMPLEX (1, cacosh, CONJ(1), CONJ(0));
TESTIT_COMPLEX_R (1, cacosh, CONJ(-1), CONJ(3.141593FI));
TESTIT_COMPLEX_R_ALLNEG (cacosh, 3.45678F + 2.34567FI,
2.11780F + 0.60971FI, 2.11780F + 2.531875FI,
2.11780F - 0.60971FI, 2.11780F - 2.531875FI);
TESTIT_COMPLEX_ALLNEG (casinh, 0,
0, -CONJ(0), CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (casinh, 3.45678F + 2.34567FI,
2.12836F + 0.58310FI, -2.12836F + 0.58310FI,
2.12836F - 0.58310FI, -2.12836F - 0.58310FI);
TESTIT_COMPLEX_ALLNEG (catanh, 0,
0, -CONJ(0), CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (catanh, 3.45678F + 2.34567FI,
0.19693F + 1.43190FI, -0.19693F + 1.43190FI,
0.19693F - 1.43190FI, -0.19693F - 1.43190FI);
TESTIT_COMPLEX_ALLNEG (csin, 0,
0, -0.F, CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (csin, 3.45678F + 2.34567FI,
-1.633059F - 4.917448FI, 1.633059F - 4.917448FI,
-1.633059F + 4.917448FI, 1.633059F + 4.917448FI);
TESTIT_COMPLEX_ALLNEG (ccos, 0,
CONJ(1), 1, 1, CONJ(1));
TESTIT_COMPLEX_R_ALLNEG (ccos, 3.45678F + 2.34567FI,
-5.008512F + 1.603367FI, -5.008512F - 1.603367FI,
-5.008512F - 1.603367FI, -5.008512F + 1.603367FI);
TESTIT_COMPLEX_ALLNEG (ctan, 0,
0, -0.F, CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (ctan, 3.45678F + 2.34567FI,
0.010657F + 0.985230FI, -0.010657F + 0.985230FI,
0.010657F - 0.985230FI, -0.010657F - 0.985230FI);
TESTIT_COMPLEX_ALLNEG (csinh, 0,
0, -0.F, CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (csinh, 3.45678F + 2.34567FI,
-11.083178F + 11.341487FI, 11.083178F +11.341487FI,
-11.083178F - 11.341487FI, 11.083178F -11.341487FI);
TESTIT_COMPLEX_ALLNEG (ccosh, 0,
1, CONJ(1), CONJ(1), 1);
TESTIT_COMPLEX_R_ALLNEG (ccosh, 3.45678F + 2.34567FI,
-11.105238F + 11.318958FI,-11.105238F -11.318958FI,
-11.105238F - 11.318958FI,-11.105238F +11.318958FI);
TESTIT_COMPLEX_ALLNEG (ctanh, 0,
0, -0.F, CONJ(0), CONJ(-0.F));
TESTIT_COMPLEX_R_ALLNEG (ctanh, 3.45678F + 2.34567FI,
1.000040F - 0.001988FI, -1.000040F - 0.001988FI,
1.000040F + 0.001988FI, -1.000040F + 0.001988FI);
TESTIT_COMPLEX (1, clog, 1, 0);
TESTIT_COMPLEX_R (1, clog, -1, 3.141593FI);
TESTIT_COMPLEX (1, clog, CONJ(1), CONJ(0));
TESTIT_COMPLEX_R (1, clog, CONJ(-1), CONJ(3.141593FI));
TESTIT_COMPLEX_R_ALLNEG (clog, 3.45678F + 2.34567FI,
1.429713F + 0.596199FI, 1.429713F + 2.545394FI,
1.429713F - 0.596199FI, 1.429713F - 2.545394FI);
TESTIT_COMPLEX_ALLNEG (csqrt, 0,
0, 0, CONJ(0), CONJ(0));
TESTIT_COMPLEX_R_ALLNEG (csqrt, 3.45678F + 2.34567FI,
1.953750F + 0.600299FI, 0.600299F + 1.953750FI,
1.953750F - 0.600299FI, 0.600299F - 1.953750FI);
TESTIT_COMPLEX2_ALLNEG (cpow, 1, 0,
1, 1, CONJ(1), CONJ(1), CONJ(1), CONJ(1), 1, 1,
CONJ(1), CONJ(1), 1, 1, 1, 1, CONJ(1), CONJ(1));
TESTIT_COMPLEX2_ALLNEG (cpow, 1.FI, 0,
1, 1, CONJ(1), CONJ(1), CONJ(1), CONJ(1), 1, 1,
CONJ(1), CONJ(1), 1, 1, 1, 1, CONJ(1), CONJ(1));
TESTIT_COMPLEX_R2_ALLNEG (cpow, 2, 3,
8, 8, CONJ(1/8.F), CONJ(1/8.F), CONJ(-8), CONJ(-8), -1/8.F, -1/8.F,
CONJ(8), CONJ(8), 1/8.F, 1/8.F, -8, -8, CONJ(-1/8.F), CONJ(-1/8.F));
TESTIT_COMPLEX_R2_ALLNEG (cpow, 3, 4,
81, 81, CONJ(1/81.F), CONJ(1/81.F), CONJ(81), CONJ(81), 1/81.F, 1/81.F,
CONJ(81), CONJ(81), 1/81.F, 1/81.F, 81, 81, CONJ(1/81.F), CONJ(1/81.F));
TESTIT_COMPLEX_R2_ALLNEG (cpow, 3, 5,
243, 243, CONJ(1/243.F), CONJ(1/243.F), CONJ(-243), CONJ(-243), -1/243.F, -1/243.F,
CONJ(243), CONJ(243), 1/243.F, 1/243.F, -243, -243, CONJ(-1/243.F), CONJ(-1/243.F));
TESTIT_COMPLEX_R2_ALLNEG (cpow, 4, 2,
16, 16, CONJ(1/16.F), CONJ(1/16.F), CONJ(16), CONJ(16), 1/16.F, 1/16.F,
CONJ(16), CONJ(16), 1/16.F, 1/16.F, 16, 16, CONJ(1/16.F), CONJ(1/16.F));
TESTIT_COMPLEX_R2_ALLNEG (cpow, 1.5, 3,
3.375F, 3.375F, CONJ(1/3.375F), CONJ(1/3.375F), CONJ(-3.375F), CONJ(-3.375F), -1/3.375F, -1/3.375F,
CONJ(3.375F), CONJ(3.375F), 1/3.375F, 1/3.375F, -3.375F, -3.375F, CONJ(-1/3.375F), CONJ(-1/3.375F));
TESTIT_COMPLEX2 (1, cpow, 16, 0.25F, 2);
TESTIT_COMPLEX_R2 (1, cpow, 3.45678F + 2.34567FI, 1.23456 + 4.56789FI, 0.212485F + 0.319304FI);
TESTIT_COMPLEX_R2 (1, cpow, 3.45678F - 2.34567FI, 1.23456 + 4.56789FI, 78.576402F + -41.756208FI);
TESTIT_COMPLEX_R2 (1, cpow, -1.23456F + 2.34567FI, 2.34567 - 1.23456FI, -110.629847F + -57.021655FI);
TESTIT_COMPLEX_R2 (1, cpow, -1.23456F - 2.34567FI, 2.34567 - 1.23456FI, 0.752336F + 0.199095FI);
return 0;
}
|