2 * Copyright (c) 2004 Stefan Farfeleder <stefanf@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 /* All of our functions have side effects, __pure2 causes functions calls to
31 * be optimised away. Stop that. */
39 int n_float, n_double, n_long_double;
40 int n_float_complex, n_double_complex, n_long_double_complex;
44 #define TGMACRO(FNC) \
46 TGMACRO_COMPLEX(c ## FNC)
48 #define TGMACRO_REAL(FNC) \
49 float (FNC ## f)(float x) { n_float++; } \
50 double (FNC)(double x) { n_double++; } \
51 long double (FNC ## l)(long double x) { n_long_double++; }
53 #define TGMACRO_REAL_REAL(FNC) \
54 float (FNC ## f)(float x, float y) { n_float++; } \
55 double (FNC)(double x, double y) { n_double++; } \
57 (FNC ## l)(long double x, long double y) { n_long_double++; }
59 #define TGMACRO_REAL_FIXED_RET(FNC, TYPE) \
60 TYPE (FNC ## f)(float x) { n_float++; } \
61 TYPE (FNC)(double x) { n_double++; } \
62 TYPE (FNC ## l)(long double x) { n_long_double++; }
64 #define TGMACRO_COMPLEX(FNC) \
65 float complex (FNC ## f)(float complex x) { n_float_complex++; }\
66 double complex (FNC)(double complex x) { n_double_complex++; } \
68 (FNC ## l)(long double complex x) { n_long_double_complex++; }
70 #define TGMACRO_COMPLEX_REAL_RET(FNC) \
71 float (FNC ## f)(float complex x) { n_float_complex++; } \
72 double (FNC)(double complex x) { n_double_complex++; } \
74 (FNC ## l)(long double complex x) { n_long_double_complex++; }
92 TGMACRO_REAL_REAL(pow)
93 float complex (cpowf)(float complex x, float complex y) { n_float_complex++; }
95 (cpow)(double complex x, double complex y) { n_double_complex++; }
97 (cpowl)(long double complex x, long double complex y)
98 { n_long_double_complex++; }
101 TGMACRO_COMPLEX_REAL_RET(cabs)
104 TGMACRO_REAL_REAL(atan2)
107 TGMACRO_REAL_REAL(copysign)
112 TGMACRO_REAL_REAL(fdim)
114 float (fmaf)(float x, float y, float z) { n_float++; }
115 double (fma)(double x, double y, double z) { n_double++; }
117 (fmal)(long double x, long double y, long double z) { n_long_double++; }
118 TGMACRO_REAL_REAL(fmax)
119 TGMACRO_REAL_REAL(fmin)
120 TGMACRO_REAL_REAL(fmod)
121 float (frexpf)(float x, int *e) { n_float++; }
122 double (frexp)(double x, int *e) { n_double++; }
123 long double (frexpl)(long double x, int *e) { n_long_double++; }
124 TGMACRO_REAL_REAL(hypot)
125 TGMACRO_REAL_FIXED_RET(ilogb, int)
126 float (ldexpf)(float x, int e) { n_float++; }
127 double (ldexp)(double x, int e) { n_double++; }
128 long double (ldexpl)(long double x, int e) { n_long_double++; }
130 TGMACRO_REAL_FIXED_RET(llrint, long long)
131 TGMACRO_REAL_FIXED_RET(llround, long long)
136 TGMACRO_REAL_FIXED_RET(lrint, long)
137 TGMACRO_REAL_FIXED_RET(lround, long)
138 TGMACRO_REAL(nearbyint)
139 TGMACRO_REAL_REAL(nextafter)
140 float (nexttowardf)(float x, long double y) { n_float++; }
141 double (nexttoward)(double x, long double y) { n_double++; }
142 long double (nexttowardl)(long double x, long double y) { n_long_double++; }
143 TGMACRO_REAL_REAL(remainder)
144 float (remquof)(float x, float y, int *q) { n_float++; }
145 double (remquo)(double x, double y, int *q) { n_double++; }
146 long double (remquol)(long double x, long double y, int *q) { n_long_double++; }
149 float (scalbnf)(float x, int n) { n_float++; }
150 double (scalbn)(double x, int n) { n_double++; }
151 long double (scalbnl)(long double x, int n) { n_long_double++; }
152 float (scalblnf)(float x, long n) { n_float++; }
153 double (scalbln)(double x, long n) { n_double++; }
154 long double (scalblnl)(long double x, long n) { n_long_double++; }
159 TGMACRO_COMPLEX_REAL_RET(carg)
160 TGMACRO_COMPLEX_REAL_RET(cimag)
161 TGMACRO_COMPLEX(conj)
162 TGMACRO_COMPLEX(cproj)
163 TGMACRO_COMPLEX_REAL_RET(creal)
169 long double complex ldc;
172 unsigned long long ull;
176 #define SAMETYPE(EXP, TYPE) \
177 __builtin_types_compatible_p(__typeof__(EXP), TYPE)
179 #define CLEAR_COUNTERS \
180 (n_float = n_double = n_long_double = 0, \
181 n_float_complex = n_double_complex = n_long_double_complex = 0, 1)
183 #define RUN_TEST(EXP, TYPE) (EXP, SAMETYPE(EXP, TYPE))
185 #define PASS_REAL_ARG_REAL_RET(FNC) PASS_REAL_ARG_REAL_RET_(FNC,)
187 #define PASS_REAL_ARG_REAL_RET_(FNC, SUFFIX) \
189 RUN_TEST(FNC(1.l), long double) && \
190 RUN_TEST(FNC(ld), long double) && \
191 n_long_double ## SUFFIX == 2 && \
192 RUN_TEST(FNC(1.), double) && \
193 RUN_TEST(FNC(d), double) && \
194 RUN_TEST(FNC(1ull), double) && \
195 RUN_TEST(FNC(ull), double) && \
196 RUN_TEST(FNC(1), double) && \
197 RUN_TEST(FNC(i), double) && \
198 RUN_TEST(FNC((_Bool)0), double) && \
199 RUN_TEST(FNC(b), double) && \
200 n_double ## SUFFIX == 8 && \
201 RUN_TEST(FNC(1.f), float) && \
202 RUN_TEST(FNC(f), float) && \
203 n_float ## SUFFIX == 2
205 #define PASS_REAL_ARG_FIXED_RET(FNC, RET) \
207 RUN_TEST(FNC(1.l), RET) && \
208 RUN_TEST(FNC(ld), RET) && \
209 n_long_double == 2 && \
210 RUN_TEST(FNC(1.), RET) && \
211 RUN_TEST(FNC(d), RET) && \
212 RUN_TEST(FNC(1ull), RET) && \
213 RUN_TEST(FNC(ull), RET) && \
214 RUN_TEST(FNC(1), RET) && \
215 RUN_TEST(FNC(i), RET) && \
216 RUN_TEST(FNC((_Bool)0), RET) && \
217 RUN_TEST(FNC(b), RET) && \
219 RUN_TEST(FNC(1.f), RET) && \
220 RUN_TEST(FNC(f), RET) && \
223 #define PASS_REAL_FIXED_ARG_REAL_RET(FNC, ARG2) \
225 RUN_TEST(FNC(1.l, ARG2), long double) && \
226 RUN_TEST(FNC(ld, ARG2), long double) && \
227 n_long_double == 2 && \
228 RUN_TEST(FNC(1., ARG2), double) && \
229 RUN_TEST(FNC(d, ARG2), double) && \
230 RUN_TEST(FNC(1ull, ARG2), double) && \
231 RUN_TEST(FNC(ull, ARG2), double) && \
232 RUN_TEST(FNC(1, ARG2), double) && \
233 RUN_TEST(FNC(i, ARG2), double) && \
234 RUN_TEST(FNC((_Bool)0, ARG2), double) && \
235 RUN_TEST(FNC(b, ARG2), double) && \
237 RUN_TEST(FNC(1.f, ARG2), float) && \
238 RUN_TEST(FNC(f, ARG2), float) && \
241 #define PASS_REAL_REAL_ARG_REAL_RET(FNC) \
243 RUN_TEST(FNC(1.l, 1.l), long double) && \
244 RUN_TEST(FNC(1.l, 1.), long double) && \
245 RUN_TEST(FNC(1.l, 1.f), long double) && \
246 RUN_TEST(FNC(1.l, 1), long double) && \
247 RUN_TEST(FNC(1.l, (_Bool)0), long double) && \
248 RUN_TEST(FNC(1.l, ld), long double) && \
249 RUN_TEST(FNC(1., ld), long double) && \
250 RUN_TEST(FNC(1.f, ld), long double) && \
251 RUN_TEST(FNC(1, ld), long double) && \
252 RUN_TEST(FNC((_Bool)0, ld), long double) && \
253 n_long_double == 10 && \
254 RUN_TEST(FNC(d, 1.), double) && \
255 RUN_TEST(FNC(d, 1.f), double) && \
256 RUN_TEST(FNC(d, 1l), double) && \
257 RUN_TEST(FNC(d, (_Bool)0), double) && \
258 RUN_TEST(FNC(1., 1.), double) && \
259 RUN_TEST(FNC(1.f, 1.), double) && \
260 RUN_TEST(FNC(1l, 1.), double) && \
261 RUN_TEST(FNC((_Bool)0, 1.), double) && \
262 RUN_TEST(FNC(1ull, f), double) && \
263 RUN_TEST(FNC(1.f, ull), double) && \
264 RUN_TEST(FNC(1, 1l), double) && \
265 RUN_TEST(FNC(1u, i), double) && \
266 RUN_TEST(FNC((_Bool)0, 1.f), double) && \
267 RUN_TEST(FNC(1.f, b), double) && \
269 RUN_TEST(FNC(1.f, 1.f), float) && \
270 RUN_TEST(FNC(1.f, 1.f), float) && \
271 RUN_TEST(FNC(f, 1.f), float) && \
272 RUN_TEST(FNC(f, f), float) && \
275 #define PASS_REAL_REAL_FIXED_ARG_REAL_RET(FNC, ARG3) \
277 RUN_TEST(FNC(1.l, 1.l, ARG3), long double) && \
278 RUN_TEST(FNC(1.l, 1., ARG3), long double) && \
279 RUN_TEST(FNC(1.l, 1.f, ARG3), long double) && \
280 RUN_TEST(FNC(1.l, 1, ARG3), long double) && \
281 RUN_TEST(FNC(1.l, (_Bool)0, ARG3), long double) && \
282 RUN_TEST(FNC(1.l, ld, ARG3), long double) && \
283 RUN_TEST(FNC(1., ld, ARG3), long double) && \
284 RUN_TEST(FNC(1.f, ld, ARG3), long double) && \
285 RUN_TEST(FNC(1, ld, ARG3), long double) && \
286 RUN_TEST(FNC((_Bool)0, ld, ARG3), long double) && \
287 n_long_double == 10 && \
288 RUN_TEST(FNC(d, 1., ARG3), double) && \
289 RUN_TEST(FNC(d, 1.f, ARG3), double) && \
290 RUN_TEST(FNC(d, 1l, ARG3), double) && \
291 RUN_TEST(FNC(d, (_Bool)0, ARG3), double) && \
292 RUN_TEST(FNC(1., 1., ARG3), double) && \
293 RUN_TEST(FNC(1.f, 1., ARG3), double) && \
294 RUN_TEST(FNC(1l, 1., ARG3), double) && \
295 RUN_TEST(FNC((_Bool)0, 1., ARG3), double) && \
296 RUN_TEST(FNC(1ull, f, ARG3), double) && \
297 RUN_TEST(FNC(1.f, ull, ARG3), double) && \
298 RUN_TEST(FNC(1, 1l, ARG3), double) && \
299 RUN_TEST(FNC(1u, i, ARG3), double) && \
300 RUN_TEST(FNC((_Bool)0, 1.f, ARG3), double) && \
301 RUN_TEST(FNC(1.f, b, ARG3), double) && \
303 RUN_TEST(FNC(1.f, 1.f, ARG3), float) && \
304 RUN_TEST(FNC(1.f, 1.f, ARG3), float) && \
305 RUN_TEST(FNC(f, 1.f, ARG3), float) && \
306 RUN_TEST(FNC(f, f, ARG3), float) && \
309 #define PASS_REAL_REAL_REAL_ARG_REAL_RET(FNC) \
311 RUN_TEST(FNC(ld, d, f), long double) && \
312 RUN_TEST(FNC(1, ld, ld), long double) && \
313 RUN_TEST(FNC(1, d, ld), long double) && \
314 n_long_double == 3 && \
315 RUN_TEST(FNC(1, f, 1.f), double) && \
316 RUN_TEST(FNC(f, d, 1.f), double) && \
317 RUN_TEST(FNC(f, 1.f, 1.), double) && \
319 RUN_TEST(FNC(f, 1.f, f), float) && \
322 #define PASS_REAL_ARG_COMPLEX_RET(FNC) \
324 RUN_TEST(FNC(1.l), long double complex) && \
325 RUN_TEST(FNC(ld), long double complex) && \
326 n_long_double_complex == 2 && \
327 RUN_TEST(FNC(1.), double complex) && \
328 RUN_TEST(FNC(d), double complex) && \
329 RUN_TEST(FNC(1l), double complex) && \
330 RUN_TEST(FNC(i), double complex) && \
331 RUN_TEST(FNC(b), double complex) && \
332 n_double_complex == 5 && \
333 RUN_TEST(FNC(1.f), float complex) && \
334 RUN_TEST(FNC(f), float complex) && \
337 #define PASS_COMPLEX_ARG_COMPLEX_RET(FNC) \
339 RUN_TEST(FNC(ldc), long double complex) && \
340 n_long_double_complex == 1 && \
341 RUN_TEST(FNC(dc), double complex) && \
342 n_double_complex == 1 && \
343 RUN_TEST(FNC(fc), float complex) && \
344 RUN_TEST(FNC(I), float complex) && \
347 #define PASS_COMPLEX_ARG_REAL_RET(FNC) \
349 RUN_TEST(FNC(ldc), long double) && \
350 n_long_double_complex == 1 && \
351 RUN_TEST(FNC(dc), double) && \
352 n_double_complex == 1 && \
353 RUN_TEST(FNC(fc), float) && \
354 RUN_TEST(FNC(I), float) && \
357 #define PASS_COMPLEX_COMPLEX_ARG_COMPLEX_RET(FNC) \
359 RUN_TEST(FNC(ldc, ldc), long double complex) && \
360 RUN_TEST(FNC(ldc, dc), long double complex) && \
361 RUN_TEST(FNC(ldc, fc), long double complex) && \
362 RUN_TEST(FNC(ldc, ld), long double complex) && \
363 RUN_TEST(FNC(ldc, d), long double complex) && \
364 RUN_TEST(FNC(ldc, f), long double complex) && \
365 RUN_TEST(FNC(ldc, i), long double complex) && \
366 RUN_TEST(FNC(dc, ldc), long double complex) && \
367 RUN_TEST(FNC(I, ldc), long double complex) && \
368 RUN_TEST(FNC(1.l, ldc), long double complex) && \
369 RUN_TEST(FNC(1., ldc), long double complex) && \
370 RUN_TEST(FNC(1.f, ldc), long double complex) && \
371 RUN_TEST(FNC(1, ldc), long double complex) && \
372 RUN_TEST(FNC(ld, dc), long double complex) && \
373 RUN_TEST(FNC(ld, fc), long double complex) && \
374 RUN_TEST(FNC(I, 1.l), long double complex) && \
375 RUN_TEST(FNC(dc, 1.l), long double complex) && \
376 n_long_double_complex == 17 && \
377 RUN_TEST(FNC(dc, dc), double complex) && \
378 RUN_TEST(FNC(dc, fc), double complex) && \
379 RUN_TEST(FNC(dc, d), double complex) && \
380 RUN_TEST(FNC(dc, f), double complex) && \
381 RUN_TEST(FNC(dc, ull), double complex) && \
382 RUN_TEST(FNC(I, dc), double complex) && \
383 RUN_TEST(FNC(1., dc), double complex) && \
384 RUN_TEST(FNC(1, dc), double complex) && \
385 RUN_TEST(FNC(fc, d), double complex) && \
386 RUN_TEST(FNC(1, I), double complex) && \
387 n_double_complex == 10 && \
388 RUN_TEST(FNC(fc, fc), float complex) && \
389 RUN_TEST(FNC(fc, I), float complex) && \
390 RUN_TEST(FNC(1.f, fc), float complex) && \
394 #define PRINT(STR, X) do { \
399 printf("%s %d - %s\n", result ? "ok" : "not ok", currtest, (STR)); \
410 PASS_REAL_ARG_REAL_RET(acos) &&
411 PASS_COMPLEX_ARG_COMPLEX_RET(acos));
414 PASS_REAL_ARG_REAL_RET(asin) &&
415 PASS_COMPLEX_ARG_COMPLEX_RET(asin));
418 PASS_REAL_ARG_REAL_RET(atan) &&
419 PASS_COMPLEX_ARG_COMPLEX_RET(atan));
422 PASS_REAL_ARG_REAL_RET(acosh) &&
423 PASS_COMPLEX_ARG_COMPLEX_RET(acosh));
426 PASS_REAL_ARG_REAL_RET(asinh) &&
427 PASS_COMPLEX_ARG_COMPLEX_RET(asinh));
430 PASS_REAL_ARG_REAL_RET(atanh) &&
431 PASS_COMPLEX_ARG_COMPLEX_RET(atanh));
434 PASS_REAL_ARG_REAL_RET(cos) &&
435 PASS_COMPLEX_ARG_COMPLEX_RET(cos));
438 PASS_REAL_ARG_REAL_RET(sin) &&
439 PASS_COMPLEX_ARG_COMPLEX_RET(sin));
442 PASS_REAL_ARG_REAL_RET(tan) &&
443 PASS_COMPLEX_ARG_COMPLEX_RET(tan));
446 PASS_REAL_ARG_REAL_RET(cosh) &&
447 PASS_COMPLEX_ARG_COMPLEX_RET(cosh));
450 PASS_REAL_ARG_REAL_RET(sinh) &&
451 PASS_COMPLEX_ARG_COMPLEX_RET(sinh));
454 PASS_REAL_ARG_REAL_RET(tanh) &&
455 PASS_COMPLEX_ARG_COMPLEX_RET(tanh));
458 PASS_REAL_ARG_REAL_RET(exp) &&
459 PASS_COMPLEX_ARG_COMPLEX_RET(exp));
462 PASS_REAL_ARG_REAL_RET(log) &&
463 PASS_COMPLEX_ARG_COMPLEX_RET(log));
466 PASS_REAL_REAL_ARG_REAL_RET(pow) &&
467 PASS_COMPLEX_COMPLEX_ARG_COMPLEX_RET(pow));
470 PASS_REAL_ARG_REAL_RET(sqrt) &&
471 PASS_COMPLEX_ARG_COMPLEX_RET(sqrt));
474 PASS_REAL_ARG_REAL_RET(fabs) &&
475 PASS_COMPLEX_ARG_REAL_RET(fabs));
479 PASS_REAL_REAL_ARG_REAL_RET(atan2));
482 PASS_REAL_ARG_REAL_RET(cbrt));
485 PASS_REAL_ARG_REAL_RET(ceil));
488 PASS_REAL_REAL_ARG_REAL_RET(copysign));
491 PASS_REAL_ARG_REAL_RET(erf));
494 PASS_REAL_ARG_REAL_RET(erfc));
497 PASS_REAL_ARG_REAL_RET(exp2));
500 PASS_REAL_ARG_REAL_RET(expm1));
503 PASS_REAL_REAL_ARG_REAL_RET(fdim));
506 PASS_REAL_ARG_REAL_RET(floor));
509 PASS_REAL_REAL_REAL_ARG_REAL_RET(fma));
512 PASS_REAL_REAL_ARG_REAL_RET(fmax));
515 PASS_REAL_REAL_ARG_REAL_RET(fmin));
518 PASS_REAL_REAL_ARG_REAL_RET(fmod));
521 PASS_REAL_FIXED_ARG_REAL_RET(frexp, &i));
524 PASS_REAL_REAL_ARG_REAL_RET(hypot));
527 PASS_REAL_ARG_FIXED_RET(ilogb, int));
530 PASS_REAL_FIXED_ARG_REAL_RET(ldexp, 1) &&
531 PASS_REAL_FIXED_ARG_REAL_RET(ldexp, ld) &&
532 PASS_REAL_FIXED_ARG_REAL_RET(ldexp, ldc));
535 PASS_REAL_ARG_REAL_RET(lgamma));
538 PASS_REAL_ARG_FIXED_RET(llrint, long long));
541 PASS_REAL_ARG_FIXED_RET(llround, long long));
544 PASS_REAL_ARG_REAL_RET(log10));
547 PASS_REAL_ARG_REAL_RET(log1p));
550 PASS_REAL_ARG_REAL_RET(log2));
553 PASS_REAL_ARG_REAL_RET(logb));
556 PASS_REAL_ARG_FIXED_RET(lrint, long));
559 PASS_REAL_ARG_FIXED_RET(lround, long));
562 PASS_REAL_ARG_REAL_RET(nearbyint));
565 PASS_REAL_REAL_ARG_REAL_RET(nextafter));
568 PASS_REAL_FIXED_ARG_REAL_RET(nexttoward, 1) &&
569 PASS_REAL_FIXED_ARG_REAL_RET(nexttoward, ull) &&
570 PASS_REAL_FIXED_ARG_REAL_RET(nexttoward, d) &&
571 PASS_REAL_FIXED_ARG_REAL_RET(nexttoward, fc));
574 PASS_REAL_REAL_ARG_REAL_RET(remainder));
577 PASS_REAL_REAL_FIXED_ARG_REAL_RET(remquo, &i));
580 PASS_REAL_ARG_REAL_RET(rint));
583 PASS_REAL_ARG_REAL_RET(round));
586 PASS_REAL_FIXED_ARG_REAL_RET(scalbn, 1) &&
587 PASS_REAL_FIXED_ARG_REAL_RET(scalbn, b) &&
588 PASS_REAL_FIXED_ARG_REAL_RET(scalbn, I));
591 PASS_REAL_FIXED_ARG_REAL_RET(scalbln, i) &&
592 PASS_REAL_FIXED_ARG_REAL_RET(scalbln, 1.l) &&
593 PASS_REAL_FIXED_ARG_REAL_RET(scalbln, dc));
596 PASS_REAL_ARG_REAL_RET(tgamma));
599 PASS_REAL_ARG_REAL_RET(trunc));
603 PASS_REAL_ARG_REAL_RET_(carg, _complex) &&
604 PASS_COMPLEX_ARG_REAL_RET(carg));
607 PASS_REAL_ARG_REAL_RET_(cimag, _complex) &&
608 PASS_COMPLEX_ARG_REAL_RET(cimag));
611 PASS_REAL_ARG_COMPLEX_RET(conj) &&
612 PASS_COMPLEX_ARG_COMPLEX_RET(conj));
615 PASS_REAL_ARG_COMPLEX_RET(cproj) &&
616 PASS_COMPLEX_ARG_COMPLEX_RET(cproj));
619 PASS_REAL_ARG_REAL_RET_(creal, _complex) &&
620 PASS_COMPLEX_ARG_REAL_RET(creal));