1134758Sstefanf/*-
2134758Sstefanf * Copyright (c) 2004 Stefan Farfeleder <stefanf@FreeBSD.org>
3134758Sstefanf * All rights reserved.
4134758Sstefanf *
5134758Sstefanf * Redistribution and use in source and binary forms, with or without
6134758Sstefanf * modification, are permitted provided that the following conditions
7134758Sstefanf * are met:
8134758Sstefanf * 1. Redistributions of source code must retain the above copyright
9134758Sstefanf *    notice, this list of conditions and the following disclaimer.
10134758Sstefanf * 2. Redistributions in binary form must reproduce the above copyright
11134758Sstefanf *    notice, this list of conditions and the following disclaimer in the
12134758Sstefanf *    documentation and/or other materials provided with the distribution.
13134758Sstefanf *
14134758Sstefanf * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15134758Sstefanf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16134758Sstefanf * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17134758Sstefanf * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18134758Sstefanf * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19134758Sstefanf * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20134758Sstefanf * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21134758Sstefanf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22134758Sstefanf * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23134758Sstefanf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24134758Sstefanf * SUCH DAMAGE.
25134758Sstefanf *
26134758Sstefanf * $FreeBSD$
27134758Sstefanf */
28134758Sstefanf
29134758Sstefanf#include <sys/cdefs.h>
30134758Sstefanf/* All of our functions have side effects, __pure2 causes functions calls to
31134758Sstefanf * be optimised away.  Stop that. */
32134758Sstefanf#undef __pure2
33134758Sstefanf#define	__pure2
34134758Sstefanf
35134758Sstefanf#include <assert.h>
36134758Sstefanf#include <stdio.h>
37134758Sstefanf#include <tgmath.h>
38134758Sstefanf
39134758Sstefanfint n_float, n_double, n_long_double;
40134758Sstefanfint n_float_complex, n_double_complex, n_long_double_complex;
41134758Sstefanf
42137587Snikint currtest = 0;
43137587Snik
44134758Sstefanf#define	TGMACRO(FNC)							\
45134758Sstefanf	TGMACRO_REAL(FNC)						\
46134758Sstefanf	TGMACRO_COMPLEX(c ## FNC)
47134758Sstefanf
48134758Sstefanf#define	TGMACRO_REAL(FNC)						\
49134758Sstefanf	float (FNC ## f)(float x) { n_float++; }			\
50134758Sstefanf	double (FNC)(double x) { n_double++; }				\
51134758Sstefanf	long double (FNC ## l)(long double x) { n_long_double++; }
52134758Sstefanf
53134758Sstefanf#define	TGMACRO_REAL_REAL(FNC)						\
54134758Sstefanf	float (FNC ## f)(float x, float y) { n_float++; }		\
55134758Sstefanf	double (FNC)(double x, double y) { n_double++; }		\
56134758Sstefanf	long double							\
57134758Sstefanf	(FNC ## l)(long double x, long double y) { n_long_double++; }
58134758Sstefanf
59134758Sstefanf#define	TGMACRO_REAL_FIXED_RET(FNC, TYPE)				\
60134758Sstefanf	TYPE (FNC ## f)(float x) { n_float++; }				\
61134758Sstefanf	TYPE (FNC)(double x) { n_double++; }				\
62134758Sstefanf	TYPE (FNC ## l)(long double x) { n_long_double++; }
63134758Sstefanf
64134758Sstefanf#define	TGMACRO_COMPLEX(FNC)						\
65134758Sstefanf	float complex (FNC ## f)(float complex x) { n_float_complex++; }\
66134758Sstefanf	double complex (FNC)(double complex x) { n_double_complex++; }	\
67134758Sstefanf	long double complex						\
68134758Sstefanf	(FNC ## l)(long double complex x) { n_long_double_complex++; }
69134758Sstefanf
70134758Sstefanf#define	TGMACRO_COMPLEX_REAL_RET(FNC)					\
71134758Sstefanf	float (FNC ## f)(float complex x) { n_float_complex++; }	\
72134758Sstefanf	double (FNC)(double complex x) { n_double_complex++; }		\
73134758Sstefanf	long double							\
74134758Sstefanf	(FNC ## l)(long double complex x) { n_long_double_complex++; }
75134758Sstefanf
76134758Sstefanf
77134758Sstefanf/* 7.22#4 */
78134758SstefanfTGMACRO(acos)
79134758SstefanfTGMACRO(asin)
80134758SstefanfTGMACRO(atan)
81134758SstefanfTGMACRO(acosh)
82134758SstefanfTGMACRO(asinh)
83134758SstefanfTGMACRO(atanh)
84134758SstefanfTGMACRO(cos)
85134758SstefanfTGMACRO(sin)
86134758SstefanfTGMACRO(tan)
87134758SstefanfTGMACRO(cosh)
88134758SstefanfTGMACRO(sinh)
89134758SstefanfTGMACRO(tanh)
90134758SstefanfTGMACRO(exp)
91134758SstefanfTGMACRO(log)
92134758SstefanfTGMACRO_REAL_REAL(pow)
93134758Sstefanffloat complex (cpowf)(float complex x, float complex y) { n_float_complex++; }
94134758Sstefanfdouble complex
95134758Sstefanf(cpow)(double complex x, double complex y) { n_double_complex++; }
96134758Sstefanflong double complex
97134758Sstefanf(cpowl)(long double complex x, long double complex y)
98134758Sstefanf{ n_long_double_complex++; }
99134758SstefanfTGMACRO(sqrt)
100134758SstefanfTGMACRO_REAL(fabs)
101134758SstefanfTGMACRO_COMPLEX_REAL_RET(cabs)
102134758Sstefanf
103134758Sstefanf/* 7.22#5 */
104134758SstefanfTGMACRO_REAL_REAL(atan2)
105134758SstefanfTGMACRO_REAL(cbrt)
106134758SstefanfTGMACRO_REAL(ceil)
107134758SstefanfTGMACRO_REAL_REAL(copysign)
108134758SstefanfTGMACRO_REAL(erf)
109134758SstefanfTGMACRO_REAL(erfc)
110134758SstefanfTGMACRO_REAL(exp2)
111134758SstefanfTGMACRO_REAL(expm1)
112134758SstefanfTGMACRO_REAL_REAL(fdim)
113134758SstefanfTGMACRO_REAL(floor)
114134758Sstefanffloat (fmaf)(float x, float y, float z) { n_float++; }
115134758Sstefanfdouble (fma)(double x, double y, double z) { n_double++; }
116134758Sstefanflong double
117134758Sstefanf(fmal)(long double x, long double y, long double z) { n_long_double++; }
118134758SstefanfTGMACRO_REAL_REAL(fmax)
119134758SstefanfTGMACRO_REAL_REAL(fmin)
120134758SstefanfTGMACRO_REAL_REAL(fmod)
121134758Sstefanffloat (frexpf)(float x, int *e) { n_float++; }
122134758Sstefanfdouble (frexp)(double x, int *e) { n_double++; }
123134758Sstefanflong double (frexpl)(long double x, int *e) { n_long_double++; }
124134758SstefanfTGMACRO_REAL_REAL(hypot)
125134758SstefanfTGMACRO_REAL_FIXED_RET(ilogb, int)
126134758Sstefanffloat (ldexpf)(float x, int e) { n_float++; }
127134758Sstefanfdouble (ldexp)(double x, int e) { n_double++; }
128134758Sstefanflong double (ldexpl)(long double x, int e) { n_long_double++; }
129134758SstefanfTGMACRO_REAL(lgamma)
130134758SstefanfTGMACRO_REAL_FIXED_RET(llrint, long long)
131134758SstefanfTGMACRO_REAL_FIXED_RET(llround, long long)
132134758SstefanfTGMACRO_REAL(log10)
133134758SstefanfTGMACRO_REAL(log1p)
134134758SstefanfTGMACRO_REAL(log2)
135134758SstefanfTGMACRO_REAL(logb)
136134758SstefanfTGMACRO_REAL_FIXED_RET(lrint, long)
137134758SstefanfTGMACRO_REAL_FIXED_RET(lround, long)
138134758SstefanfTGMACRO_REAL(nearbyint)
139134758SstefanfTGMACRO_REAL_REAL(nextafter)
140134758Sstefanffloat (nexttowardf)(float x, long double y) { n_float++; }
141134758Sstefanfdouble (nexttoward)(double x, long double y) { n_double++; }
142134758Sstefanflong double (nexttowardl)(long double x, long double y) { n_long_double++; }
143134758SstefanfTGMACRO_REAL_REAL(remainder)
144134758Sstefanffloat (remquof)(float x, float y, int *q) { n_float++; }
145134758Sstefanfdouble (remquo)(double x, double y, int *q) { n_double++; }
146134758Sstefanflong double (remquol)(long double x, long double y, int *q) { n_long_double++; }
147134758SstefanfTGMACRO_REAL(rint)
148134758SstefanfTGMACRO_REAL(round)
149134758Sstefanffloat (scalbnf)(float x, int n) { n_float++; }
150134758Sstefanfdouble (scalbn)(double x, int n) { n_double++; }
151134758Sstefanflong double (scalbnl)(long double x, int n) { n_long_double++; }
152134758Sstefanffloat (scalblnf)(float x, long n) { n_float++; }
153134758Sstefanfdouble (scalbln)(double x, long n) { n_double++; }
154134758Sstefanflong double (scalblnl)(long double x, long n) { n_long_double++; }
155134758SstefanfTGMACRO_REAL(tgamma)
156134758SstefanfTGMACRO_REAL(trunc)
157134758Sstefanf
158134758Sstefanf/* 7.22#6 */
159134758SstefanfTGMACRO_COMPLEX_REAL_RET(carg)
160134758SstefanfTGMACRO_COMPLEX_REAL_RET(cimag)
161134758SstefanfTGMACRO_COMPLEX(conj)
162134758SstefanfTGMACRO_COMPLEX(cproj)
163134758SstefanfTGMACRO_COMPLEX_REAL_RET(creal)
164134758Sstefanf
165134758Sstefanf
166134758Sstefanflong double ld;
167134758Sstefanfdouble d;
168134758Sstefanffloat f;
169134758Sstefanflong double complex ldc;
170134758Sstefanfdouble complex dc;
171134758Sstefanffloat complex fc;
172134758Sstefanfunsigned long long ull;
173134758Sstefanfint i;
174134758Sstefanf_Bool b;
175134758Sstefanf
176134758Sstefanf#define	SAMETYPE(EXP, TYPE)						\
177134758Sstefanf	__builtin_types_compatible_p(__typeof__(EXP), TYPE)
178134758Sstefanf
179134758Sstefanf#define	CLEAR_COUNTERS							\
180134758Sstefanf	(n_float = n_double = n_long_double = 0,			\
181134758Sstefanf	    n_float_complex = n_double_complex = n_long_double_complex = 0, 1)
182134758Sstefanf
183134758Sstefanf#define	RUN_TEST(EXP, TYPE)	(EXP, SAMETYPE(EXP, TYPE))
184134758Sstefanf
185134758Sstefanf#define	PASS_REAL_ARG_REAL_RET(FNC) PASS_REAL_ARG_REAL_RET_(FNC,)
186134758Sstefanf
187134758Sstefanf#define	PASS_REAL_ARG_REAL_RET_(FNC, SUFFIX)				\
188134758Sstefanf	CLEAR_COUNTERS &&						\
189134758Sstefanf	RUN_TEST(FNC(1.l), long double) &&				\
190134758Sstefanf	RUN_TEST(FNC(ld), long double) &&				\
191134758Sstefanf	n_long_double ## SUFFIX == 2 &&					\
192134758Sstefanf	RUN_TEST(FNC(1.), double) &&					\
193134758Sstefanf	RUN_TEST(FNC(d), double) &&					\
194134758Sstefanf	RUN_TEST(FNC(1ull), double) &&					\
195134758Sstefanf	RUN_TEST(FNC(ull), double) &&					\
196134758Sstefanf	RUN_TEST(FNC(1), double) &&					\
197134758Sstefanf	RUN_TEST(FNC(i), double) &&					\
198134758Sstefanf	RUN_TEST(FNC((_Bool)0), double) &&				\
199134758Sstefanf	RUN_TEST(FNC(b), double) &&					\
200134758Sstefanf	n_double ## SUFFIX == 8 &&					\
201134758Sstefanf	RUN_TEST(FNC(1.f), float) &&					\
202134758Sstefanf	RUN_TEST(FNC(f), float) &&					\
203134758Sstefanf	n_float ## SUFFIX == 2
204134758Sstefanf
205134758Sstefanf#define	PASS_REAL_ARG_FIXED_RET(FNC, RET)				\
206134758Sstefanf	CLEAR_COUNTERS &&						\
207134758Sstefanf	RUN_TEST(FNC(1.l), RET) &&					\
208134758Sstefanf	RUN_TEST(FNC(ld), RET) &&					\
209134758Sstefanf	n_long_double == 2 &&						\
210134758Sstefanf	RUN_TEST(FNC(1.), RET) &&					\
211134758Sstefanf	RUN_TEST(FNC(d), RET) &&					\
212134758Sstefanf	RUN_TEST(FNC(1ull), RET) &&					\
213134758Sstefanf	RUN_TEST(FNC(ull), RET) &&					\
214134758Sstefanf	RUN_TEST(FNC(1), RET) &&					\
215134758Sstefanf	RUN_TEST(FNC(i), RET) &&					\
216134758Sstefanf	RUN_TEST(FNC((_Bool)0), RET) &&					\
217134758Sstefanf	RUN_TEST(FNC(b), RET) &&					\
218134758Sstefanf	n_double == 8 &&						\
219134758Sstefanf	RUN_TEST(FNC(1.f), RET) &&					\
220134758Sstefanf	RUN_TEST(FNC(f), RET) &&					\
221134758Sstefanf	n_float == 2
222134758Sstefanf
223134758Sstefanf#define	PASS_REAL_FIXED_ARG_REAL_RET(FNC, ARG2)				\
224134758Sstefanf	CLEAR_COUNTERS &&						\
225134758Sstefanf	RUN_TEST(FNC(1.l, ARG2), long double) &&			\
226134758Sstefanf	RUN_TEST(FNC(ld, ARG2), long double) &&				\
227134758Sstefanf	n_long_double == 2 &&						\
228134758Sstefanf	RUN_TEST(FNC(1., ARG2), double) &&				\
229134758Sstefanf	RUN_TEST(FNC(d, ARG2), double) &&				\
230134758Sstefanf	RUN_TEST(FNC(1ull, ARG2), double) &&				\
231134758Sstefanf	RUN_TEST(FNC(ull, ARG2), double) &&				\
232134758Sstefanf	RUN_TEST(FNC(1, ARG2), double) &&				\
233134758Sstefanf	RUN_TEST(FNC(i, ARG2), double) &&				\
234134758Sstefanf	RUN_TEST(FNC((_Bool)0, ARG2), double) &&			\
235134758Sstefanf	RUN_TEST(FNC(b, ARG2), double) &&				\
236134758Sstefanf	n_double == 8 &&						\
237134758Sstefanf	RUN_TEST(FNC(1.f, ARG2), float) &&				\
238134758Sstefanf	RUN_TEST(FNC(f, ARG2), float) &&				\
239134758Sstefanf	n_float == 2
240134758Sstefanf
241134758Sstefanf#define	PASS_REAL_REAL_ARG_REAL_RET(FNC)				\
242134758Sstefanf	CLEAR_COUNTERS &&						\
243134758Sstefanf	RUN_TEST(FNC(1.l, 1.l), long double) &&				\
244134758Sstefanf	RUN_TEST(FNC(1.l, 1.), long double) &&				\
245134758Sstefanf	RUN_TEST(FNC(1.l, 1.f), long double) &&				\
246134758Sstefanf	RUN_TEST(FNC(1.l, 1), long double) &&				\
247134758Sstefanf	RUN_TEST(FNC(1.l, (_Bool)0), long double) &&			\
248134758Sstefanf	RUN_TEST(FNC(1.l, ld), long double) &&				\
249134758Sstefanf	RUN_TEST(FNC(1., ld), long double) &&				\
250134758Sstefanf	RUN_TEST(FNC(1.f, ld), long double) &&				\
251134758Sstefanf	RUN_TEST(FNC(1, ld), long double) &&				\
252134758Sstefanf	RUN_TEST(FNC((_Bool)0, ld), long double) &&			\
253134758Sstefanf	n_long_double == 10 &&						\
254134758Sstefanf	RUN_TEST(FNC(d, 1.), double) &&					\
255134758Sstefanf	RUN_TEST(FNC(d, 1.f), double) &&				\
256134758Sstefanf	RUN_TEST(FNC(d, 1l), double) &&					\
257134758Sstefanf	RUN_TEST(FNC(d, (_Bool)0), double) &&				\
258134758Sstefanf	RUN_TEST(FNC(1., 1.), double) &&				\
259134758Sstefanf	RUN_TEST(FNC(1.f, 1.), double) &&				\
260134758Sstefanf	RUN_TEST(FNC(1l, 1.), double) &&				\
261134758Sstefanf	RUN_TEST(FNC((_Bool)0, 1.), double) &&				\
262134758Sstefanf	RUN_TEST(FNC(1ull, f), double) &&				\
263134758Sstefanf	RUN_TEST(FNC(1.f, ull), double) &&				\
264134758Sstefanf	RUN_TEST(FNC(1, 1l), double) &&					\
265134758Sstefanf	RUN_TEST(FNC(1u, i), double) &&					\
266134758Sstefanf	RUN_TEST(FNC((_Bool)0, 1.f), double) &&				\
267134758Sstefanf	RUN_TEST(FNC(1.f, b), double) &&				\
268134758Sstefanf	n_double == 14 &&						\
269134758Sstefanf	RUN_TEST(FNC(1.f, 1.f), float) &&				\
270134758Sstefanf	RUN_TEST(FNC(1.f, 1.f), float) &&				\
271134758Sstefanf	RUN_TEST(FNC(f, 1.f), float) &&					\
272134758Sstefanf	RUN_TEST(FNC(f, f), float) &&					\
273134758Sstefanf	n_float == 4
274134758Sstefanf
275134758Sstefanf#define	PASS_REAL_REAL_FIXED_ARG_REAL_RET(FNC, ARG3)			\
276134758Sstefanf	CLEAR_COUNTERS &&						\
277134758Sstefanf	RUN_TEST(FNC(1.l, 1.l, ARG3), long double) &&			\
278134758Sstefanf	RUN_TEST(FNC(1.l, 1., ARG3), long double) &&			\
279134758Sstefanf	RUN_TEST(FNC(1.l, 1.f, ARG3), long double) &&			\
280134758Sstefanf	RUN_TEST(FNC(1.l, 1, ARG3), long double) &&			\
281134758Sstefanf	RUN_TEST(FNC(1.l, (_Bool)0, ARG3), long double) &&		\
282134758Sstefanf	RUN_TEST(FNC(1.l, ld, ARG3), long double) &&			\
283134758Sstefanf	RUN_TEST(FNC(1., ld, ARG3), long double) &&			\
284134758Sstefanf	RUN_TEST(FNC(1.f, ld, ARG3), long double) &&			\
285134758Sstefanf	RUN_TEST(FNC(1, ld, ARG3), long double) &&			\
286134758Sstefanf	RUN_TEST(FNC((_Bool)0, ld, ARG3), long double) &&		\
287134758Sstefanf	n_long_double == 10 &&						\
288134758Sstefanf	RUN_TEST(FNC(d, 1., ARG3), double) &&				\
289134758Sstefanf	RUN_TEST(FNC(d, 1.f, ARG3), double) &&				\
290134758Sstefanf	RUN_TEST(FNC(d, 1l, ARG3), double) &&				\
291134758Sstefanf	RUN_TEST(FNC(d, (_Bool)0, ARG3), double) &&			\
292134758Sstefanf	RUN_TEST(FNC(1., 1., ARG3), double) &&				\
293134758Sstefanf	RUN_TEST(FNC(1.f, 1., ARG3), double) &&				\
294134758Sstefanf	RUN_TEST(FNC(1l, 1., ARG3), double) &&				\
295134758Sstefanf	RUN_TEST(FNC((_Bool)0, 1., ARG3), double) &&			\
296134758Sstefanf	RUN_TEST(FNC(1ull, f, ARG3), double) &&				\
297134758Sstefanf	RUN_TEST(FNC(1.f, ull, ARG3), double) &&			\
298134758Sstefanf	RUN_TEST(FNC(1, 1l, ARG3), double) &&				\
299134758Sstefanf	RUN_TEST(FNC(1u, i, ARG3), double) &&				\
300134758Sstefanf	RUN_TEST(FNC((_Bool)0, 1.f, ARG3), double) &&			\
301134758Sstefanf	RUN_TEST(FNC(1.f, b, ARG3), double) &&				\
302134758Sstefanf	n_double == 14 &&						\
303134758Sstefanf	RUN_TEST(FNC(1.f, 1.f, ARG3), float) &&				\
304134758Sstefanf	RUN_TEST(FNC(1.f, 1.f, ARG3), float) &&				\
305134758Sstefanf	RUN_TEST(FNC(f, 1.f, ARG3), float) &&				\
306134758Sstefanf	RUN_TEST(FNC(f, f, ARG3), float) &&				\
307134758Sstefanf	n_float == 4
308134758Sstefanf
309134758Sstefanf#define	PASS_REAL_REAL_REAL_ARG_REAL_RET(FNC)				\
310134758Sstefanf	CLEAR_COUNTERS &&						\
311134758Sstefanf	RUN_TEST(FNC(ld, d, f), long double) &&				\
312134758Sstefanf	RUN_TEST(FNC(1, ld, ld), long double) &&			\
313134758Sstefanf	RUN_TEST(FNC(1, d, ld), long double) &&				\
314134758Sstefanf	n_long_double == 3 &&						\
315134758Sstefanf	RUN_TEST(FNC(1, f, 1.f), double) &&				\
316134758Sstefanf	RUN_TEST(FNC(f, d, 1.f), double) &&				\
317134758Sstefanf	RUN_TEST(FNC(f, 1.f, 1.), double) &&				\
318134758Sstefanf	n_double == 3 &&						\
319134758Sstefanf	RUN_TEST(FNC(f, 1.f, f), float) &&				\
320134758Sstefanf	n_float == 1
321134758Sstefanf
322134758Sstefanf#define	PASS_REAL_ARG_COMPLEX_RET(FNC)					\
323134758Sstefanf	CLEAR_COUNTERS &&						\
324134758Sstefanf	RUN_TEST(FNC(1.l), long double complex) &&			\
325134758Sstefanf	RUN_TEST(FNC(ld), long double complex) &&			\
326134758Sstefanf	n_long_double_complex == 2 &&					\
327134758Sstefanf	RUN_TEST(FNC(1.), double complex) &&				\
328134758Sstefanf	RUN_TEST(FNC(d), double complex) &&				\
329134758Sstefanf	RUN_TEST(FNC(1l), double complex) &&				\
330134758Sstefanf	RUN_TEST(FNC(i), double complex) &&				\
331134758Sstefanf	RUN_TEST(FNC(b), double complex) &&				\
332134758Sstefanf	n_double_complex == 5 &&					\
333134758Sstefanf	RUN_TEST(FNC(1.f), float complex) &&				\
334134758Sstefanf	RUN_TEST(FNC(f), float complex) &&				\
335134758Sstefanf	n_float_complex == 2
336134758Sstefanf
337134758Sstefanf#define	PASS_COMPLEX_ARG_COMPLEX_RET(FNC)				\
338134758Sstefanf	CLEAR_COUNTERS &&						\
339134758Sstefanf	RUN_TEST(FNC(ldc), long double complex) &&			\
340134758Sstefanf	n_long_double_complex == 1 &&					\
341134758Sstefanf	RUN_TEST(FNC(dc), double complex) &&				\
342134758Sstefanf	n_double_complex == 1 &&					\
343134758Sstefanf	RUN_TEST(FNC(fc), float complex) &&				\
344134758Sstefanf	RUN_TEST(FNC(I), float complex) &&				\
345134758Sstefanf	n_float_complex == 2
346134758Sstefanf
347134758Sstefanf#define	PASS_COMPLEX_ARG_REAL_RET(FNC)					\
348134758Sstefanf	CLEAR_COUNTERS &&						\
349134758Sstefanf	RUN_TEST(FNC(ldc), long double) &&				\
350134758Sstefanf	n_long_double_complex == 1 &&					\
351134758Sstefanf	RUN_TEST(FNC(dc), double) &&					\
352134758Sstefanf	n_double_complex == 1 &&					\
353134758Sstefanf	RUN_TEST(FNC(fc), float) &&					\
354134758Sstefanf	RUN_TEST(FNC(I), float) &&					\
355134758Sstefanf	n_float_complex == 2
356134758Sstefanf
357134758Sstefanf#define	PASS_COMPLEX_COMPLEX_ARG_COMPLEX_RET(FNC)			\
358134758Sstefanf	CLEAR_COUNTERS &&						\
359134758Sstefanf	RUN_TEST(FNC(ldc, ldc), long double complex) &&			\
360134758Sstefanf	RUN_TEST(FNC(ldc, dc), long double complex) &&			\
361134758Sstefanf	RUN_TEST(FNC(ldc, fc), long double complex) &&			\
362134758Sstefanf	RUN_TEST(FNC(ldc, ld), long double complex) &&			\
363134758Sstefanf	RUN_TEST(FNC(ldc, d), long double complex) &&			\
364134758Sstefanf	RUN_TEST(FNC(ldc, f), long double complex) &&			\
365134758Sstefanf	RUN_TEST(FNC(ldc, i), long double complex) &&			\
366134758Sstefanf	RUN_TEST(FNC(dc, ldc), long double complex) &&			\
367134758Sstefanf	RUN_TEST(FNC(I, ldc), long double complex) &&			\
368134758Sstefanf	RUN_TEST(FNC(1.l, ldc), long double complex) &&			\
369134758Sstefanf	RUN_TEST(FNC(1., ldc), long double complex) &&			\
370134758Sstefanf	RUN_TEST(FNC(1.f, ldc), long double complex) &&			\
371134758Sstefanf	RUN_TEST(FNC(1, ldc), long double complex) &&			\
372134758Sstefanf	RUN_TEST(FNC(ld, dc), long double complex) &&			\
373134758Sstefanf	RUN_TEST(FNC(ld, fc), long double complex) &&			\
374134758Sstefanf	RUN_TEST(FNC(I, 1.l), long double complex) &&			\
375134758Sstefanf	RUN_TEST(FNC(dc, 1.l), long double complex) &&			\
376134758Sstefanf	n_long_double_complex == 17 &&					\
377134758Sstefanf	RUN_TEST(FNC(dc, dc), double complex) &&			\
378134758Sstefanf	RUN_TEST(FNC(dc, fc), double complex) &&			\
379134758Sstefanf	RUN_TEST(FNC(dc, d), double complex) &&				\
380134758Sstefanf	RUN_TEST(FNC(dc, f), double complex) &&				\
381134758Sstefanf	RUN_TEST(FNC(dc, ull), double complex) &&			\
382134758Sstefanf	RUN_TEST(FNC(I, dc), double complex) &&				\
383134758Sstefanf	RUN_TEST(FNC(1., dc), double complex) &&			\
384134758Sstefanf	RUN_TEST(FNC(1, dc), double complex) &&				\
385134758Sstefanf	RUN_TEST(FNC(fc, d), double complex) &&				\
386134758Sstefanf	RUN_TEST(FNC(1, I), double complex) &&				\
387134758Sstefanf	n_double_complex == 10 &&					\
388134758Sstefanf	RUN_TEST(FNC(fc, fc), float complex) &&				\
389134758Sstefanf	RUN_TEST(FNC(fc, I), float complex) &&				\
390134758Sstefanf	RUN_TEST(FNC(1.f, fc), float complex) &&			\
391134758Sstefanf	n_float_complex == 3
392134758Sstefanf
393134758Sstefanfint failed = 0;
394134758Sstefanf#define	PRINT(STR, X) do {						\
395137587Snik	currtest++;							\
396134758Sstefanf	int result = (X);						\
397134758Sstefanf	if (!result)							\
398134758Sstefanf		failed = 1;						\
399137587Snik	printf("%s %d - %s\n", result ? "ok" : "not ok", currtest, (STR));		\
400137587Snik	fflush(stdout);							\
401134758Sstefanf} while (0)
402134758Sstefanf
403134758Sstefanfint
404134758Sstefanfmain(void)
405134758Sstefanf{
406137587Snik	printf("1..60\n");
407137587Snik
408134758Sstefanf	/* 7.22#4 */
409134758Sstefanf	PRINT("acos",
410134758Sstefanf	    PASS_REAL_ARG_REAL_RET(acos) &&
411134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(acos));
412134758Sstefanf
413134758Sstefanf	PRINT("asin",
414134758Sstefanf	    PASS_REAL_ARG_REAL_RET(asin) &&
415134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(asin));
416134758Sstefanf
417134758Sstefanf	PRINT("atan",
418134758Sstefanf	    PASS_REAL_ARG_REAL_RET(atan) &&
419134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(atan));
420134758Sstefanf
421134758Sstefanf	PRINT("acosh",
422134758Sstefanf	    PASS_REAL_ARG_REAL_RET(acosh) &&
423134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(acosh));
424134758Sstefanf
425134758Sstefanf	PRINT("asinh",
426134758Sstefanf	    PASS_REAL_ARG_REAL_RET(asinh) &&
427134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(asinh));
428134758Sstefanf
429134758Sstefanf	PRINT("atanh",
430134758Sstefanf	    PASS_REAL_ARG_REAL_RET(atanh) &&
431134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(atanh));
432134758Sstefanf
433134758Sstefanf	PRINT("cos",
434134758Sstefanf	    PASS_REAL_ARG_REAL_RET(cos) &&
435134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(cos));
436134758Sstefanf
437134758Sstefanf	PRINT("sin",
438134758Sstefanf	    PASS_REAL_ARG_REAL_RET(sin) &&
439134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(sin));
440134758Sstefanf
441134758Sstefanf	PRINT("tan",
442134758Sstefanf	    PASS_REAL_ARG_REAL_RET(tan) &&
443134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(tan));
444134758Sstefanf
445134758Sstefanf	PRINT("cosh",
446134758Sstefanf	    PASS_REAL_ARG_REAL_RET(cosh) &&
447134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(cosh));
448134758Sstefanf
449134758Sstefanf	PRINT("sinh",
450134758Sstefanf	    PASS_REAL_ARG_REAL_RET(sinh) &&
451134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(sinh));
452134758Sstefanf
453134758Sstefanf	PRINT("tanh",
454134758Sstefanf	    PASS_REAL_ARG_REAL_RET(tanh) &&
455134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(tanh));
456134758Sstefanf
457134758Sstefanf	PRINT("exp",
458134758Sstefanf	    PASS_REAL_ARG_REAL_RET(exp) &&
459134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(exp));
460134758Sstefanf
461134758Sstefanf	PRINT("log",
462134758Sstefanf	    PASS_REAL_ARG_REAL_RET(log) &&
463134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(log));
464134758Sstefanf
465134758Sstefanf	PRINT("pow",
466134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(pow) &&
467134758Sstefanf	    PASS_COMPLEX_COMPLEX_ARG_COMPLEX_RET(pow));
468134758Sstefanf
469134758Sstefanf	PRINT("sqrt",
470134758Sstefanf	    PASS_REAL_ARG_REAL_RET(sqrt) &&
471134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(sqrt));
472134758Sstefanf
473134758Sstefanf	PRINT("fabs",
474134758Sstefanf	    PASS_REAL_ARG_REAL_RET(fabs) &&
475134758Sstefanf	    PASS_COMPLEX_ARG_REAL_RET(fabs));
476134758Sstefanf
477134758Sstefanf	/* 7.22#5 */
478134758Sstefanf	PRINT("atan2",
479134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(atan2));
480134758Sstefanf
481134758Sstefanf	PRINT("cbrt",
482134758Sstefanf	    PASS_REAL_ARG_REAL_RET(cbrt));
483134758Sstefanf
484134758Sstefanf	PRINT("ceil",
485134758Sstefanf	    PASS_REAL_ARG_REAL_RET(ceil));
486134758Sstefanf
487134758Sstefanf	PRINT("copysign",
488134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(copysign));
489134758Sstefanf
490134758Sstefanf	PRINT("erf",
491134758Sstefanf	    PASS_REAL_ARG_REAL_RET(erf));
492134758Sstefanf
493134758Sstefanf	PRINT("erfc",
494134758Sstefanf	    PASS_REAL_ARG_REAL_RET(erfc));
495134758Sstefanf
496134758Sstefanf	PRINT("exp2",
497134758Sstefanf	    PASS_REAL_ARG_REAL_RET(exp2));
498134758Sstefanf
499134758Sstefanf	PRINT("expm1",
500134758Sstefanf	    PASS_REAL_ARG_REAL_RET(expm1));
501134758Sstefanf
502134758Sstefanf	PRINT("fdim",
503134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(fdim));
504134758Sstefanf
505134758Sstefanf	PRINT("floor",
506134758Sstefanf	    PASS_REAL_ARG_REAL_RET(floor));
507134758Sstefanf
508134758Sstefanf	PRINT("fma",
509134758Sstefanf	    PASS_REAL_REAL_REAL_ARG_REAL_RET(fma));
510134758Sstefanf
511134758Sstefanf	PRINT("fmax",
512134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(fmax));
513134758Sstefanf
514134758Sstefanf	PRINT("fmin",
515134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(fmin));
516134758Sstefanf
517134758Sstefanf	PRINT("fmod",
518134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(fmod));
519134758Sstefanf
520134758Sstefanf	PRINT("frexp",
521134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(frexp, &i));
522134758Sstefanf
523134758Sstefanf	PRINT("hypot",
524134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(hypot));
525134758Sstefanf
526134758Sstefanf	PRINT("ilogb",
527134758Sstefanf	    PASS_REAL_ARG_FIXED_RET(ilogb, int));
528134758Sstefanf
529134758Sstefanf	PRINT("ldexp",
530134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(ldexp, 1) &&
531134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(ldexp, ld) &&
532134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(ldexp, ldc));
533134758Sstefanf
534134758Sstefanf	PRINT("lgamma",
535134758Sstefanf	    PASS_REAL_ARG_REAL_RET(lgamma));
536134758Sstefanf
537134758Sstefanf	PRINT("llrint",
538134758Sstefanf	    PASS_REAL_ARG_FIXED_RET(llrint, long long));
539134758Sstefanf
540134758Sstefanf	PRINT("llround",
541134758Sstefanf	    PASS_REAL_ARG_FIXED_RET(llround, long long));
542134758Sstefanf
543134758Sstefanf	PRINT("log10",
544134758Sstefanf	    PASS_REAL_ARG_REAL_RET(log10));
545134758Sstefanf
546134758Sstefanf	PRINT("log1p",
547134758Sstefanf	    PASS_REAL_ARG_REAL_RET(log1p));
548134758Sstefanf
549134758Sstefanf	PRINT("log2",
550134758Sstefanf	    PASS_REAL_ARG_REAL_RET(log2));
551134758Sstefanf
552134758Sstefanf	PRINT("logb",
553134758Sstefanf	    PASS_REAL_ARG_REAL_RET(logb));
554134758Sstefanf
555134758Sstefanf	PRINT("lrint",
556134758Sstefanf	    PASS_REAL_ARG_FIXED_RET(lrint, long));
557134758Sstefanf
558134758Sstefanf	PRINT("lround",
559134758Sstefanf	    PASS_REAL_ARG_FIXED_RET(lround, long));
560134758Sstefanf
561134758Sstefanf	PRINT("nearbyint",
562134758Sstefanf	    PASS_REAL_ARG_REAL_RET(nearbyint));
563134758Sstefanf
564134758Sstefanf	PRINT("nextafter",
565134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(nextafter));
566134758Sstefanf
567134758Sstefanf	PRINT("nexttoward",
568134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(nexttoward, 1) &&
569134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(nexttoward, ull) &&
570134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(nexttoward, d) &&
571134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(nexttoward, fc));
572134758Sstefanf
573134758Sstefanf	PRINT("remainder",
574134758Sstefanf	    PASS_REAL_REAL_ARG_REAL_RET(remainder));
575134758Sstefanf
576134758Sstefanf	PRINT("remquo",
577134758Sstefanf	    PASS_REAL_REAL_FIXED_ARG_REAL_RET(remquo, &i));
578134758Sstefanf
579134758Sstefanf	PRINT("rint",
580134758Sstefanf	    PASS_REAL_ARG_REAL_RET(rint));
581134758Sstefanf
582134758Sstefanf	PRINT("round",
583134758Sstefanf	    PASS_REAL_ARG_REAL_RET(round));
584134758Sstefanf
585134758Sstefanf	PRINT("scalbn",
586134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(scalbn, 1) &&
587134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(scalbn, b) &&
588134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(scalbn, I));
589134758Sstefanf
590134758Sstefanf	PRINT("scalbln",
591134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(scalbln, i) &&
592134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(scalbln, 1.l) &&
593134758Sstefanf	    PASS_REAL_FIXED_ARG_REAL_RET(scalbln, dc));
594134758Sstefanf
595134758Sstefanf	PRINT("tgamma",
596134758Sstefanf	    PASS_REAL_ARG_REAL_RET(tgamma));
597134758Sstefanf
598134758Sstefanf	PRINT("trunc",
599134758Sstefanf	    PASS_REAL_ARG_REAL_RET(trunc));
600134758Sstefanf
601134758Sstefanf	/* 7.22#6 */
602134758Sstefanf	PRINT("carg",
603134758Sstefanf	    PASS_REAL_ARG_REAL_RET_(carg, _complex) &&
604134758Sstefanf	    PASS_COMPLEX_ARG_REAL_RET(carg));
605134758Sstefanf
606134758Sstefanf	PRINT("cimag",
607134758Sstefanf	    PASS_REAL_ARG_REAL_RET_(cimag, _complex) &&
608134758Sstefanf	    PASS_COMPLEX_ARG_REAL_RET(cimag));
609134758Sstefanf
610134758Sstefanf	PRINT("conj",
611134758Sstefanf	    PASS_REAL_ARG_COMPLEX_RET(conj) &&
612134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(conj));
613134758Sstefanf
614134758Sstefanf	PRINT("cproj",
615134758Sstefanf	    PASS_REAL_ARG_COMPLEX_RET(cproj) &&
616134758Sstefanf	    PASS_COMPLEX_ARG_COMPLEX_RET(cproj));
617134758Sstefanf
618134758Sstefanf	PRINT("creal",
619134758Sstefanf	    PASS_REAL_ARG_REAL_RET_(creal, _complex) &&
620134758Sstefanf	    PASS_COMPLEX_ARG_REAL_RET(creal));
621134758Sstefanf}
622