xref: /openbsd-src/regress/lib/libm/msun/invctrig_test.c (revision 498c7b5e98c82ca5a0055f676f2a6e4214e2d9a8)
1*498c7b5eSderaadt /*	$OpenBSD: invctrig_test.c,v 1.3 2021/12/13 18:04:28 deraadt Exp $	*/
2c36e572eSmbuhl /*-
3c36e572eSmbuhl  * Copyright (c) 2008-2013 David Schultz <das@FreeBSD.org>
4c36e572eSmbuhl  * All rights reserved.
5c36e572eSmbuhl  *
6c36e572eSmbuhl  * Redistribution and use in source and binary forms, with or without
7c36e572eSmbuhl  * modification, are permitted provided that the following conditions
8c36e572eSmbuhl  * are met:
9c36e572eSmbuhl  * 1. Redistributions of source code must retain the above copyright
10c36e572eSmbuhl  *    notice, this list of conditions and the following disclaimer.
11c36e572eSmbuhl  * 2. Redistributions in binary form must reproduce the above copyright
12c36e572eSmbuhl  *    notice, this list of conditions and the following disclaimer in the
13c36e572eSmbuhl  *    documentation and/or other materials provided with the distribution.
14c36e572eSmbuhl  *
15c36e572eSmbuhl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16c36e572eSmbuhl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17c36e572eSmbuhl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18c36e572eSmbuhl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19c36e572eSmbuhl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20c36e572eSmbuhl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21c36e572eSmbuhl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22c36e572eSmbuhl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23c36e572eSmbuhl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24c36e572eSmbuhl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25c36e572eSmbuhl  * SUCH DAMAGE.
26c36e572eSmbuhl  */
27c36e572eSmbuhl 
28c36e572eSmbuhl #include "macros.h"
29c36e572eSmbuhl 
30c36e572eSmbuhl /*
31c36e572eSmbuhl  * Tests for casin[h](), cacos[h](), and catan[h]().
32c36e572eSmbuhl  */
33c36e572eSmbuhl 
3449a6e16fSderaadt #include <sys/types.h>
35c36e572eSmbuhl #include <complex.h>
36c36e572eSmbuhl #include <fenv.h>
37c36e572eSmbuhl #include <float.h>
38c36e572eSmbuhl #include <math.h>
39c36e572eSmbuhl #include <stdio.h>
40c36e572eSmbuhl 
41c36e572eSmbuhl #include "test-utils.h"
42c36e572eSmbuhl 
43c36e572eSmbuhl #pragma	STDC FENV_ACCESS	ON
44c36e572eSmbuhl #pragma	STDC CX_LIMITED_RANGE	OFF
45c36e572eSmbuhl 
46c36e572eSmbuhl /*
47c36e572eSmbuhl  * Test that a function returns the correct value and sets the
48c36e572eSmbuhl  * exception flags correctly. The exceptmask specifies which
49c36e572eSmbuhl  * exceptions we should check. We need to be lenient for several
50c36e572eSmbuhl  * reasons, but mainly because on some architectures it's impossible
51c36e572eSmbuhl  * to raise FE_OVERFLOW without raising FE_INEXACT.
52c36e572eSmbuhl  *
53c36e572eSmbuhl  * These are macros instead of functions so that assert provides more
54c36e572eSmbuhl  * meaningful error messages.
55c36e572eSmbuhl  *
56c36e572eSmbuhl  * XXX The volatile here is to avoid gcc's bogus constant folding and work
57c36e572eSmbuhl  *     around the lack of support for the FENV_ACCESS pragma.
58c36e572eSmbuhl  */
59c36e572eSmbuhl #define	test_p(func, z, result, exceptmask, excepts, checksign)	do {	\
60c36e572eSmbuhl 	volatile long double complex _d = z;				\
61c36e572eSmbuhl 	debug("  testing %s(%Lg + %Lg I) == %Lg + %Lg I\n", #func,	\
62c36e572eSmbuhl 	    creall(_d), cimagl(_d), creall(result), cimagl(result));	\
63c36e572eSmbuhl 	ATF_REQUIRE_EQ(0, feclearexcept(FE_ALL_EXCEPT));		\
64c36e572eSmbuhl 	CHECK_CFPEQUAL_CS((func)(_d), (result), (checksign));		\
65c36e572eSmbuhl 	CHECK_FP_EXCEPTIONS_MSG(excepts, exceptmask, "for %s(%s)",	\
66c36e572eSmbuhl 	    #func, #z);							\
67c36e572eSmbuhl } while (0)
68c36e572eSmbuhl 
69c36e572eSmbuhl /*
70c36e572eSmbuhl  * Test within a given tolerance.  The tolerance indicates relative error
71c36e572eSmbuhl  * in ulps.
72c36e572eSmbuhl  */
73c36e572eSmbuhl #define	test_p_tol(func, z, result, tol)			do {	\
74c36e572eSmbuhl 	debug("  testing %s(%Lg + %Lg I) ~= %Lg + %Lg I\n", #func,	\
75c36e572eSmbuhl 	    creall(z), cimagl(z), creall(result), cimagl(result));	\
76c36e572eSmbuhl 	CHECK_CFPEQUAL_TOL((func)(z), (result), (tol), CS_BOTH);	\
77c36e572eSmbuhl } while (0)
78c36e572eSmbuhl 
79c36e572eSmbuhl /* These wrappers apply the identities f(conj(z)) = conj(f(z)). */
80c36e572eSmbuhl #define	test(func, z, result, exceptmask, excepts, checksign)	do {	\
81c36e572eSmbuhl 	test_p(func, z, result, exceptmask, excepts, checksign);	\
82c36e572eSmbuhl 	test_p(func, conjl(z), conjl(result), exceptmask, excepts, checksign); \
83c36e572eSmbuhl } while (0)
84c36e572eSmbuhl #define	test_tol(func, z, result, tol)				do {	\
85c36e572eSmbuhl 	test_p_tol(func, z, result, tol);				\
86c36e572eSmbuhl 	test_p_tol(func, conjl(z), conjl(result), tol);			\
87c36e572eSmbuhl } while (0)
88c36e572eSmbuhl 
89c36e572eSmbuhl /* Test the given function in all precisions. */
90c36e572eSmbuhl #define	testall(func, x, result, exceptmask, excepts, checksign) do {	\
91c36e572eSmbuhl 	test(func, x, result, exceptmask, excepts, checksign);		\
92c36e572eSmbuhl 	test(func##f, x, result, exceptmask, excepts, checksign);	\
93c36e572eSmbuhl } while (0)
94c36e572eSmbuhl #define	testall_odd(func, x, result, exceptmask, excepts, checksign) do { \
95c36e572eSmbuhl 	testall(func, x, result, exceptmask, excepts, checksign);	\
96c36e572eSmbuhl 	testall(func, -(x), -result, exceptmask, excepts, checksign);	\
97c36e572eSmbuhl } while (0)
98c36e572eSmbuhl #define	testall_even(func, x, result, exceptmask, excepts, checksign) do { \
99c36e572eSmbuhl 	testall(func, x, result, exceptmask, excepts, checksign);	\
100c36e572eSmbuhl 	testall(func, -(x), result, exceptmask, excepts, checksign);	\
101c36e572eSmbuhl } while (0)
102c36e572eSmbuhl 
103c36e572eSmbuhl /*
104c36e572eSmbuhl  * Test the given function in all precisions, within a given tolerance.
105c36e572eSmbuhl  * The tolerance is specified in ulps.
106c36e572eSmbuhl  */
107c36e572eSmbuhl #define	testall_tol(func, x, result, tol)	       		   do { \
108c36e572eSmbuhl 	test_tol(func, x, result, (tol) * DBL_ULP());			\
109c36e572eSmbuhl 	test_tol(func##f, x, result, (tol) * FLT_ULP());		\
110c36e572eSmbuhl } while (0)
111c36e572eSmbuhl #define	testall_odd_tol(func, x, result, tol)	       		   do { \
112c36e572eSmbuhl 	testall_tol(func, x, result, tol);				\
113c36e572eSmbuhl 	testall_tol(func, -(x), -result, tol);				\
114c36e572eSmbuhl } while (0)
115c36e572eSmbuhl #define	testall_even_tol(func, x, result, tol)	       		   do { \
116c36e572eSmbuhl 	testall_tol(func, x, result, tol);				\
117c36e572eSmbuhl 	testall_tol(func, -(x), result, tol);				\
118c36e572eSmbuhl } while (0)
119c36e572eSmbuhl 
120c36e572eSmbuhl static const long double
121c36e572eSmbuhl pi = 3.14159265358979323846264338327950280L,
122c36e572eSmbuhl c3pi = 9.42477796076937971538793014983850839L;
123c36e572eSmbuhl 
124c36e572eSmbuhl 
125c36e572eSmbuhl /* Tests for 0 */
126c36e572eSmbuhl ATF_TC_WITHOUT_HEAD(zero);
ATF_TC_BODY(zero,tc)127c36e572eSmbuhl ATF_TC_BODY(zero, tc)
128c36e572eSmbuhl {
129c36e572eSmbuhl 	long double complex zero = CMPLXL(0.0, 0.0);
130c36e572eSmbuhl 
131c36e572eSmbuhl 	testall_tol(cacosh, zero, CMPLXL(0.0, pi / 2), 1);
132c36e572eSmbuhl 	testall_tol(cacosh, -zero, CMPLXL(0.0, -pi / 2), 1);
133c36e572eSmbuhl 	testall_tol(cacos, zero, CMPLXL(pi / 2, -0.0), 1);
134c36e572eSmbuhl 	testall_tol(cacos, -zero, CMPLXL(pi / 2, 0.0), 1);
135c36e572eSmbuhl 
136c36e572eSmbuhl 	testall_odd(casinh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
137c36e572eSmbuhl 	testall_odd(casin, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
138c36e572eSmbuhl 
139c36e572eSmbuhl 	testall_odd(catanh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
140c36e572eSmbuhl 	testall_odd(catan, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
141c36e572eSmbuhl }
142c36e572eSmbuhl 
143c36e572eSmbuhl /*
144c36e572eSmbuhl  * Tests for NaN inputs.
145c36e572eSmbuhl  */
146c36e572eSmbuhl ATF_TC_WITHOUT_HEAD(nan);
ATF_TC_BODY(nan,tc)147c36e572eSmbuhl ATF_TC_BODY(nan, tc)
148c36e572eSmbuhl {
149c36e572eSmbuhl 	long double complex nan_nan = CMPLXL(NAN, NAN);
150c36e572eSmbuhl 	long double complex z;
151c36e572eSmbuhl 
152c36e572eSmbuhl 	/*
153c36e572eSmbuhl 	 * IN		CACOSH	    CACOS	CASINH	    CATANH
154c36e572eSmbuhl 	 * NaN,NaN	NaN,NaN	    NaN,NaN	NaN,NaN	    NaN,NaN
155c36e572eSmbuhl 	 * finite,NaN	NaN,NaN*    NaN,NaN*	NaN,NaN*    NaN,NaN*
156c36e572eSmbuhl 	 * NaN,finite   NaN,NaN*    NaN,NaN*	NaN,NaN*    NaN,NaN*
157c36e572eSmbuhl 	 * NaN,Inf	Inf,NaN     NaN,-Inf	?Inf,NaN    ?0,pi/2
158c36e572eSmbuhl 	 * +-Inf,NaN	Inf,NaN     NaN,?Inf	+-Inf,NaN   +-0,NaN
159c36e572eSmbuhl 	 * +-0,NaN	NaN,NaN*    pi/2,NaN	NaN,NaN*    +-0,NaN
160c36e572eSmbuhl 	 * NaN,0	NaN,NaN*    NaN,NaN*	NaN,0	    NaN,NaN*
161c36e572eSmbuhl 	 *
162c36e572eSmbuhl 	 *  * = raise invalid
163c36e572eSmbuhl 	 */
164c36e572eSmbuhl 	z = nan_nan;
165c36e572eSmbuhl 	testall(cacosh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
166c36e572eSmbuhl 	testall(cacos, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
167c36e572eSmbuhl 	testall(casinh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
168c36e572eSmbuhl 	testall(casin, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
169c36e572eSmbuhl 	testall(catanh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
170c36e572eSmbuhl 	testall(catan, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
171c36e572eSmbuhl 
172c36e572eSmbuhl 	z = CMPLXL(0.5, NAN);
173c36e572eSmbuhl 	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
174c36e572eSmbuhl 	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
175c36e572eSmbuhl 	testall(casinh, z, nan_nan, OPT_INVALID, 0, 0);
176c36e572eSmbuhl 	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
177c36e572eSmbuhl 	testall(catanh, z, nan_nan, OPT_INVALID, 0, 0);
178c36e572eSmbuhl 	testall(catan, z, nan_nan, OPT_INVALID, 0, 0);
179c36e572eSmbuhl 
180c36e572eSmbuhl 	z = CMPLXL(NAN, 0.5);
181c36e572eSmbuhl 	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
182c36e572eSmbuhl 	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
183c36e572eSmbuhl 	testall(casinh, z, nan_nan, OPT_INVALID, 0, 0);
184c36e572eSmbuhl 	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
185c36e572eSmbuhl 	testall(catanh, z, nan_nan, OPT_INVALID, 0, 0);
186c36e572eSmbuhl 	testall(catan, z, nan_nan, OPT_INVALID, 0, 0);
187c36e572eSmbuhl 
188c36e572eSmbuhl 	z = CMPLXL(NAN, INFINITY);
189c36e572eSmbuhl 	testall(cacosh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
190c36e572eSmbuhl 	testall(cacosh, -z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
191c36e572eSmbuhl 	testall(cacos, z, CMPLXL(NAN, -INFINITY), ALL_STD_EXCEPT, 0, CS_IMAG);
192c36e572eSmbuhl 	testall(casinh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, 0);
193c36e572eSmbuhl 	testall(casin, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, CS_IMAG);
194c36e572eSmbuhl 	testall_tol(catanh, z, CMPLXL(0.0, pi / 2), 1);
195c36e572eSmbuhl 	testall(catan, z, CMPLXL(NAN, 0.0), ALL_STD_EXCEPT, 0, CS_IMAG);
196c36e572eSmbuhl 
197c36e572eSmbuhl 	z = CMPLXL(INFINITY, NAN);
198c36e572eSmbuhl 	testall_even(cacosh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0,
199c36e572eSmbuhl 		     CS_REAL);
200c36e572eSmbuhl 	testall_even(cacos, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
201c36e572eSmbuhl 	testall_odd(casinh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0,
202c36e572eSmbuhl 		    CS_REAL);
203c36e572eSmbuhl 	testall_odd(casin, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
204c36e572eSmbuhl 	testall_odd(catanh, z, CMPLXL(0.0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
205c36e572eSmbuhl 	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0.0), 1);
206c36e572eSmbuhl 
207c36e572eSmbuhl 	z = CMPLXL(0.0, NAN);
208c36e572eSmbuhl         /* XXX We allow a spurious inexact exception here. */
209c36e572eSmbuhl 	testall_even(cacosh, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
210c36e572eSmbuhl 	testall_even_tol(cacos, z, CMPLXL(pi / 2, NAN), 1);
211c36e572eSmbuhl 	testall_odd(casinh, z, nan_nan, OPT_INVALID, 0, 0);
212c36e572eSmbuhl 	testall_odd(casin, z, CMPLXL(0.0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
213c36e572eSmbuhl 	testall_odd(catanh, z, CMPLXL(0.0, NAN), OPT_INVALID, 0, CS_REAL);
214c36e572eSmbuhl 	testall_odd(catan, z, nan_nan, OPT_INVALID, 0, 0);
215c36e572eSmbuhl 
216c36e572eSmbuhl 	z = CMPLXL(NAN, 0.0);
217c36e572eSmbuhl 	testall(cacosh, z, nan_nan, OPT_INVALID, 0, 0);
218c36e572eSmbuhl 	testall(cacos, z, nan_nan, OPT_INVALID, 0, 0);
219c36e572eSmbuhl 	testall(casinh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
220c36e572eSmbuhl 	testall(casin, z, nan_nan, OPT_INVALID, 0, 0);
221c36e572eSmbuhl 	testall(catanh, z, nan_nan, OPT_INVALID, 0, CS_IMAG);
222c36e572eSmbuhl 	testall(catan, z, CMPLXL(NAN, 0.0), ALL_STD_EXCEPT, 0, 0);
223c36e572eSmbuhl }
224c36e572eSmbuhl 
225c36e572eSmbuhl ATF_TC_WITHOUT_HEAD(inf);
ATF_TC_BODY(inf,tc)226c36e572eSmbuhl ATF_TC_BODY(inf, tc)
227c36e572eSmbuhl {
228c36e572eSmbuhl 	long double complex z;
229c36e572eSmbuhl 
230c36e572eSmbuhl 	/*
231c36e572eSmbuhl 	 * IN		CACOSH	    CACOS	CASINH	    CATANH
232c36e572eSmbuhl 	 * Inf,Inf	Inf,pi/4    pi/4,-Inf	Inf,pi/4    0,pi/2
233c36e572eSmbuhl 	 * -Inf,Inf	Inf,3pi/4   3pi/4,-Inf	---	    ---
234c36e572eSmbuhl 	 * Inf,finite	Inf,0	    0,-Inf	Inf,0	    0,pi/2
235c36e572eSmbuhl 	 * -Inf,finite	Inf,pi      pi,-Inf	---	    ---
236c36e572eSmbuhl 	 * finite,Inf	Inf,pi/2    pi/2,-Inf	Inf,pi/2    0,pi/2
237c36e572eSmbuhl 	 */
238c36e572eSmbuhl 	z = CMPLXL(INFINITY, INFINITY);
239c36e572eSmbuhl 	testall_tol(cacosh, z, CMPLXL(INFINITY, pi / 4), 1);
240c36e572eSmbuhl 	testall_tol(cacosh, -z, CMPLXL(INFINITY, -c3pi / 4), 1);
241c36e572eSmbuhl 	testall_tol(cacos, z, CMPLXL(pi / 4, -INFINITY), 1);
242c36e572eSmbuhl 	testall_tol(cacos, -z, CMPLXL(c3pi / 4, INFINITY), 1);
243c36e572eSmbuhl 	testall_odd_tol(casinh, z, CMPLXL(INFINITY, pi / 4), 1);
244c36e572eSmbuhl 	testall_odd_tol(casin, z, CMPLXL(pi / 4, INFINITY), 1);
245c36e572eSmbuhl 	testall_odd_tol(catanh, z, CMPLXL(0, pi / 2), 1);
246c36e572eSmbuhl 	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0), 1);
247c36e572eSmbuhl 
248c36e572eSmbuhl 	z = CMPLXL(INFINITY, 0.5);
249c36e572eSmbuhl 	/* XXX We allow a spurious inexact exception here. */
250c36e572eSmbuhl 	testall(cacosh, z, CMPLXL(INFINITY, 0), OPT_INEXACT, 0, CS_BOTH);
251c36e572eSmbuhl 	testall_tol(cacosh, -z, CMPLXL(INFINITY, -pi), 1);
252c36e572eSmbuhl 	testall(cacos, z, CMPLXL(0, -INFINITY), OPT_INEXACT, 0, CS_BOTH);
253c36e572eSmbuhl 	testall_tol(cacos, -z, CMPLXL(pi, INFINITY), 1);
254c36e572eSmbuhl 	testall_odd(casinh, z, CMPLXL(INFINITY, 0), OPT_INEXACT, 0, CS_BOTH);
255c36e572eSmbuhl 	testall_odd_tol(casin, z, CMPLXL(pi / 2, INFINITY), 1);
256c36e572eSmbuhl 	testall_odd_tol(catanh, z, CMPLXL(0, pi / 2), 1);
257c36e572eSmbuhl 	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0), 1);
258c36e572eSmbuhl 
259c36e572eSmbuhl 	z = CMPLXL(0.5, INFINITY);
260c36e572eSmbuhl 	testall_tol(cacosh, z, CMPLXL(INFINITY, pi / 2), 1);
261c36e572eSmbuhl 	testall_tol(cacosh, -z, CMPLXL(INFINITY, -pi / 2), 1);
262c36e572eSmbuhl 	testall_tol(cacos, z, CMPLXL(pi / 2, -INFINITY), 1);
263c36e572eSmbuhl 	testall_tol(cacos, -z, CMPLXL(pi / 2, INFINITY), 1);
264c36e572eSmbuhl 	testall_odd_tol(casinh, z, CMPLXL(INFINITY, pi / 2), 1);
265c36e572eSmbuhl 	/* XXX We allow a spurious inexact exception here. */
266c36e572eSmbuhl 	testall_odd(casin, z, CMPLXL(0.0, INFINITY), OPT_INEXACT, 0, CS_BOTH);
267c36e572eSmbuhl 	testall_odd_tol(catanh, z, CMPLXL(0, pi / 2), 1);
268c36e572eSmbuhl 	testall_odd_tol(catan, z, CMPLXL(pi / 2, 0), 1);
269c36e572eSmbuhl }
270c36e572eSmbuhl 
271c36e572eSmbuhl /* Tests along the real and imaginary axes. */
272c36e572eSmbuhl ATF_TC_WITHOUT_HEAD(axes);
ATF_TC_BODY(axes,tc)273c36e572eSmbuhl ATF_TC_BODY(axes, tc)
274c36e572eSmbuhl {
275c36e572eSmbuhl 	static const long double nums[] = {
276c36e572eSmbuhl 		-2, -1, -0.5, 0.5, 1, 2
277c36e572eSmbuhl 	};
278c36e572eSmbuhl 	long double complex z;
279c36e572eSmbuhl 	unsigned i;
280c36e572eSmbuhl 
281c36e572eSmbuhl 	for (i = 0; i < nitems(nums); i++) {
282c36e572eSmbuhl 		/* Real axis */
283c36e572eSmbuhl 		z = CMPLXL(nums[i], 0.0);
284c36e572eSmbuhl 		if (fabsl(nums[i]) <= 1) {
285c36e572eSmbuhl 			testall_tol(cacosh, z, CMPLXL(0.0, acos(nums[i])), 1);
286c36e572eSmbuhl 			testall_tol(cacos, z, CMPLXL(acosl(nums[i]), -0.0), 1);
287c36e572eSmbuhl 			testall_tol(casin, z, CMPLXL(asinl(nums[i]), 0.0), 1);
288c36e572eSmbuhl 			testall_tol(catanh, z, CMPLXL(atanh(nums[i]), 0.0), 1);
289c36e572eSmbuhl 		} else {
290c36e572eSmbuhl 			testall_tol(cacosh, z,
291c36e572eSmbuhl 				    CMPLXL(acosh(fabsl(nums[i])),
292c36e572eSmbuhl 					   (nums[i] < 0) ? pi : 0), 1);
293c36e572eSmbuhl 			testall_tol(cacos, z,
294c36e572eSmbuhl 				    CMPLXL((nums[i] < 0) ? pi : 0,
295c36e572eSmbuhl 					   -acosh(fabsl(nums[i]))), 1);
296c36e572eSmbuhl 			testall_tol(casin, z,
297c36e572eSmbuhl 				    CMPLXL(copysign(pi / 2, nums[i]),
298c36e572eSmbuhl 					   acosh(fabsl(nums[i]))), 1);
299c36e572eSmbuhl 			testall_tol(catanh, z,
300c36e572eSmbuhl 				    CMPLXL(atanh(1 / nums[i]), pi / 2), 1);
301c36e572eSmbuhl 		}
302c36e572eSmbuhl 		testall_tol(casinh, z, CMPLXL(asinh(nums[i]), 0.0), 1);
303c36e572eSmbuhl 		testall_tol(catan, z, CMPLXL(atan(nums[i]), 0), 1);
304c36e572eSmbuhl 
305c36e572eSmbuhl 		/* TODO: Test the imaginary axis. */
306c36e572eSmbuhl 	}
307c36e572eSmbuhl }
308c36e572eSmbuhl 
309c36e572eSmbuhl ATF_TC_WITHOUT_HEAD(small);
ATF_TC_BODY(small,tc)310c36e572eSmbuhl ATF_TC_BODY(small, tc)
311c36e572eSmbuhl {
312c36e572eSmbuhl 	/*
313c36e572eSmbuhl 	 * z =  0.75 + i 0.25
314c36e572eSmbuhl 	 *     acos(z) = Pi/4 - i ln(2)/2
315c36e572eSmbuhl 	 *     asin(z) = Pi/4 + i ln(2)/2
316c36e572eSmbuhl 	 *     atan(z) = atan(4)/2 + i ln(17/9)/4
317c36e572eSmbuhl 	 */
318c36e572eSmbuhl 	complex long double z;
319c36e572eSmbuhl 	complex long double acos_z;
320c36e572eSmbuhl 	complex long double asin_z;
321c36e572eSmbuhl 	complex long double atan_z;
322c36e572eSmbuhl 
323c36e572eSmbuhl 	z = CMPLXL(0.75L, 0.25L);
324c36e572eSmbuhl 	acos_z = CMPLXL(pi / 4, -0.34657359027997265470861606072908828L);
325c36e572eSmbuhl 	asin_z = CMPLXL(pi / 4, 0.34657359027997265470861606072908828L);
326c36e572eSmbuhl 	atan_z = CMPLXL(0.66290883183401623252961960521423782L,
327c36e572eSmbuhl 			 0.15899719167999917436476103600701878L);
328c36e572eSmbuhl 
329c36e572eSmbuhl 	testall_tol(cacos, z, acos_z, 2);
330c36e572eSmbuhl 	testall_odd_tol(casin, z, asin_z, 2);
331c36e572eSmbuhl 	testall_odd_tol(catan, z, atan_z, 2);
332c36e572eSmbuhl }
333c36e572eSmbuhl 
334c36e572eSmbuhl /* Test inputs that might cause overflow in a sloppy implementation. */
335c36e572eSmbuhl ATF_TC_WITHOUT_HEAD(large);
ATF_TC_BODY(large,tc)336c36e572eSmbuhl ATF_TC_BODY(large, tc)
337c36e572eSmbuhl {
338c36e572eSmbuhl 	/* TODO: Write these tests */
339c36e572eSmbuhl }
340c36e572eSmbuhl 
ATF_TP_ADD_TCS(tp)341c36e572eSmbuhl ATF_TP_ADD_TCS(tp)
342c36e572eSmbuhl {
343c36e572eSmbuhl 	ATF_TP_ADD_TC(tp, zero);
344c36e572eSmbuhl 	ATF_TP_ADD_TC(tp, nan);
345c36e572eSmbuhl 	ATF_TP_ADD_TC(tp, inf);
346c36e572eSmbuhl 	ATF_TP_ADD_TC(tp, axes);
347c36e572eSmbuhl 	ATF_TP_ADD_TC(tp, small);
348c36e572eSmbuhl 	ATF_TP_ADD_TC(tp, large);
349c36e572eSmbuhl 
350c36e572eSmbuhl 	return (atf_no_error());
351c36e572eSmbuhl }
352