xref: /openbsd-src/regress/lib/libm/msun/invtrig_test.c (revision c36e572ec6e4c7a6aca6564610c2c45de467ead4)
1 /*	$OpenBSD: invtrig_test.c,v 1.1 2021/10/22 18:00:22 mbuhl Exp $	*/
2 /*-
3  * Copyright (c) 2008 David Schultz <das@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include "macros.h"
29 
30 /*
31  * Tests for corner cases in the inverse trigonometric functions. Some
32  * accuracy tests are included as well, but these are very basic
33  * sanity checks, not intended to be comprehensive.
34  */
35 
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
38 
39 #include <fenv.h>
40 #include <float.h>
41 #include <math.h>
42 #include <stdio.h>
43 
44 #include "test-utils.h"
45 
46 #pragma STDC FENV_ACCESS ON
47 
48 /*
49  * Test that a function returns the correct value and sets the
50  * exception flags correctly. A tolerance specifying the maximum
51  * relative error allowed may be specified. For the 'testall'
52  * functions, the tolerance is specified in ulps.
53  *
54  * These are macros instead of functions so that assert provides more
55  * meaningful error messages.
56  */
57 #define	test_tol(func, x, result, tol, excepts) do {			\
58 	volatile long double _in = (x), _out = (result);		\
59 	ATF_REQUIRE_EQ(0, feclearexcept(FE_ALL_EXCEPT));		\
60 	CHECK_FPEQUAL_TOL(func(_in), _out, (tol), CS_BOTH);		\
61 	CHECK_FP_EXCEPTIONS_MSG(excepts, ALL_STD_EXCEPT, "for %s(%s)",	\
62 	    #func, #x);							\
63 } while (0)
64 #define test(func, x, result, excepts)					\
65 	test_tol(func, (x), (result), 0, (excepts))
66 
67 #define	_testall_tol(prefix, x, result, tol, excepts) do {		\
68 	test_tol(prefix, (double)(x), (double)(result),			\
69 		 (tol) * ldexp(1.0, 1 - DBL_MANT_DIG), (excepts));	\
70 	test_tol(prefix##f, (float)(x), (float)(result),		\
71 		 (tol) * ldexpf(1.0, 1 - FLT_MANT_DIG), (excepts));	\
72 } while (0)
73 
74 #if LDBL_PREC == 53
75 #define	testall_tol	_testall_tol
76 #else
77 #define	testall_tol(prefix, x, result, tol, excepts) do {		\
78 	_testall_tol(prefix, x, result, tol, excepts);			\
79 	test_tol(prefix##l, (x), (result),				\
80 		 (tol) * ldexpl(1.0, 1 - LDBL_MANT_DIG), (excepts));	\
81 } while (0)
82 #endif
83 
84 #define testall(prefix, x, result, excepts)				\
85 	testall_tol(prefix, (x), (result), 0, (excepts))
86 
87 #define	test2_tol(func, y, x, result, tol, excepts) do {		\
88 	volatile long double _iny = (y), _inx = (x), _out = (result);	\
89 	ATF_REQUIRE_EQ(0, feclearexcept(FE_ALL_EXCEPT));		\
90 	CHECK_FPEQUAL_TOL(func(_iny, _inx), _out, (tol), CS_BOTH);	\
91 	CHECK_FP_EXCEPTIONS_MSG(excepts, ALL_STD_EXCEPT, "for %s(%s)",	\
92 	    #func, #x);							\
93 } while (0)
94 #define test2(func, y, x, result, excepts)				\
95 	test2_tol(func, (y), (x), (result), 0, (excepts))
96 
97 #define	_testall2_tol(prefix, y, x, result, tol, excepts) do {		\
98 	test2_tol(prefix, (double)(y), (double)(x), (double)(result),	\
99 		  (tol) * ldexp(1.0, 1 - DBL_MANT_DIG), (excepts));	\
100 	test2_tol(prefix##f, (float)(y), (float)(x), (float)(result),	\
101 		  (tol) * ldexpf(1.0, 1 - FLT_MANT_DIG), (excepts));	\
102 } while (0)
103 
104 #if LDBL_PREC == 53
105 #define	testall2_tol	_testall2_tol
106 #else
107 #define	testall2_tol(prefix, y, x, result, tol, excepts) do {		\
108 	_testall2_tol(prefix, y, x, result, tol, excepts);		\
109 	test2_tol(prefix##l, (y), (x), (result),			\
110 		  (tol) * ldexpl(1.0, 1 - LDBL_MANT_DIG), (excepts));	\
111 } while (0)
112 #endif
113 
114 #define testall2(prefix, y, x, result, excepts)				\
115 	testall2_tol(prefix, (y), (x), (result), 0, (excepts))
116 
117 static long double
118 pi =   3.14159265358979323846264338327950280e+00L,
119 pio3 = 1.04719755119659774615421446109316766e+00L,
120 c3pi = 9.42477796076937971538793014983850839e+00L,
121 c7pi = 2.19911485751285526692385036829565196e+01L,
122 c5pio3 = 5.23598775598298873077107230546583851e+00L,
123 sqrt2m1 = 4.14213562373095048801688724209698081e-01L;
124 
125 
126 /*
127  * Test special case inputs in asin(), acos() and atan(): signed
128  * zeroes, infinities, and NaNs.
129  */
130 ATF_TC_WITHOUT_HEAD(special);
131 ATF_TC_BODY(special, tc)
132 {
133 
134 	testall(asin, 0.0, 0.0, 0);
135 	testall(acos, 0.0, pi / 2, FE_INEXACT);
136 	testall(atan, 0.0, 0.0, 0);
137 	testall(asin, -0.0, -0.0, 0);
138 	testall(acos, -0.0, pi / 2, FE_INEXACT);
139 	testall(atan, -0.0, -0.0, 0);
140 
141 	testall(asin, INFINITY, NAN, FE_INVALID);
142 	testall(acos, INFINITY, NAN, FE_INVALID);
143 	testall(atan, INFINITY, pi / 2, FE_INEXACT);
144 	testall(asin, -INFINITY, NAN, FE_INVALID);
145 	testall(acos, -INFINITY, NAN, FE_INVALID);
146 	testall(atan, -INFINITY, -pi / 2, FE_INEXACT);
147 
148 	testall(asin, NAN, NAN, 0);
149 	testall(acos, NAN, NAN, 0);
150 	testall(atan, NAN, NAN, 0);
151 }
152 
153 /*
154  * Test special case inputs in atan2(), where the exact value of y/x is
155  * zero or non-finite.
156  */
157 ATF_TC_WITHOUT_HEAD(special_atan2);
158 ATF_TC_BODY(special_atan2, tc)
159 {
160 	long double z;
161 	int e;
162 
163 	testall2(atan2, 0.0, -0.0, pi, FE_INEXACT);
164 	testall2(atan2, -0.0, -0.0, -pi, FE_INEXACT);
165 	testall2(atan2, 0.0, 0.0, 0.0, 0);
166 	testall2(atan2, -0.0, 0.0, -0.0, 0);
167 
168 	testall2(atan2, INFINITY, -INFINITY, c3pi / 4, FE_INEXACT);
169 	testall2(atan2, -INFINITY, -INFINITY, -c3pi / 4, FE_INEXACT);
170 	testall2(atan2, INFINITY, INFINITY, pi / 4, FE_INEXACT);
171 	testall2(atan2, -INFINITY, INFINITY, -pi / 4, FE_INEXACT);
172 
173 	/* Tests with one input in the range (0, Inf]. */
174 	z = 1.23456789L;
175 	for (e = FLT_MIN_EXP - FLT_MANT_DIG; e <= FLT_MAX_EXP; e++) {
176 		test2(atan2f, 0.0, ldexpf(z, e), 0.0, 0);
177 		test2(atan2f, -0.0, ldexpf(z, e), -0.0, 0);
178 		test2(atan2f, 0.0, ldexpf(-z, e), (float)pi, FE_INEXACT);
179 		test2(atan2f, -0.0, ldexpf(-z, e), (float)-pi, FE_INEXACT);
180 		test2(atan2f, ldexpf(z, e), 0.0, (float)pi / 2, FE_INEXACT);
181 		test2(atan2f, ldexpf(z, e), -0.0, (float)pi / 2, FE_INEXACT);
182 		test2(atan2f, ldexpf(-z, e), 0.0, (float)-pi / 2, FE_INEXACT);
183 		test2(atan2f, ldexpf(-z, e), -0.0, (float)-pi / 2, FE_INEXACT);
184 	}
185 	for (e = DBL_MIN_EXP - DBL_MANT_DIG; e <= DBL_MAX_EXP; e++) {
186 		test2(atan2, 0.0, ldexp(z, e), 0.0, 0);
187 		test2(atan2, -0.0, ldexp(z, e), -0.0, 0);
188 		test2(atan2, 0.0, ldexp(-z, e), (double)pi, FE_INEXACT);
189 		test2(atan2, -0.0, ldexp(-z, e), (double)-pi, FE_INEXACT);
190 		test2(atan2, ldexp(z, e), 0.0, (double)pi / 2, FE_INEXACT);
191 		test2(atan2, ldexp(z, e), -0.0, (double)pi / 2, FE_INEXACT);
192 		test2(atan2, ldexp(-z, e), 0.0, (double)-pi / 2, FE_INEXACT);
193 		test2(atan2, ldexp(-z, e), -0.0, (double)-pi / 2, FE_INEXACT);
194 	}
195 	for (e = LDBL_MIN_EXP - LDBL_MANT_DIG; e <= LDBL_MAX_EXP; e++) {
196 		test2(atan2l, 0.0, ldexpl(z, e), 0.0, 0);
197 		test2(atan2l, -0.0, ldexpl(z, e), -0.0, 0);
198 		test2(atan2l, 0.0, ldexpl(-z, e), pi, FE_INEXACT);
199 		test2(atan2l, -0.0, ldexpl(-z, e), -pi, FE_INEXACT);
200 		test2(atan2l, ldexpl(z, e), 0.0, pi / 2, FE_INEXACT);
201 		test2(atan2l, ldexpl(z, e), -0.0, pi / 2, FE_INEXACT);
202 		test2(atan2l, ldexpl(-z, e), 0.0, -pi / 2, FE_INEXACT);
203 		test2(atan2l, ldexpl(-z, e), -0.0, -pi / 2, FE_INEXACT);
204 	}
205 
206 	/* Tests with one input in the range (0, Inf). */
207 	for (e = FLT_MIN_EXP - FLT_MANT_DIG; e <= FLT_MAX_EXP - 1; e++) {
208 		test2(atan2f, ldexpf(z, e), INFINITY, 0.0, 0);
209 		test2(atan2f, ldexpf(-z,e), INFINITY, -0.0, 0);
210 		test2(atan2f, ldexpf(z, e), -INFINITY, (float)pi, FE_INEXACT);
211 		test2(atan2f, ldexpf(-z,e), -INFINITY, (float)-pi, FE_INEXACT);
212 		test2(atan2f, INFINITY, ldexpf(z,e), (float)pi/2, FE_INEXACT);
213 		test2(atan2f, INFINITY, ldexpf(-z,e), (float)pi/2, FE_INEXACT);
214 		test2(atan2f, -INFINITY, ldexpf(z,e), (float)-pi/2,FE_INEXACT);
215 		test2(atan2f, -INFINITY, ldexpf(-z,e),(float)-pi/2,FE_INEXACT);
216 	}
217 	for (e = DBL_MIN_EXP - DBL_MANT_DIG; e <= DBL_MAX_EXP - 1; e++) {
218 		test2(atan2, ldexp(z, e), INFINITY, 0.0, 0);
219 		test2(atan2, ldexp(-z,e), INFINITY, -0.0, 0);
220 		test2(atan2, ldexp(z, e), -INFINITY, (double)pi, FE_INEXACT);
221 		test2(atan2, ldexp(-z,e), -INFINITY, (double)-pi, FE_INEXACT);
222 		test2(atan2, INFINITY, ldexp(z,e), (double)pi/2, FE_INEXACT);
223 		test2(atan2, INFINITY, ldexp(-z,e), (double)pi/2, FE_INEXACT);
224 		test2(atan2, -INFINITY, ldexp(z,e), (double)-pi/2,FE_INEXACT);
225 		test2(atan2, -INFINITY, ldexp(-z,e),(double)-pi/2,FE_INEXACT);
226 	}
227 	for (e = LDBL_MIN_EXP - LDBL_MANT_DIG; e <= LDBL_MAX_EXP - 1; e++) {
228 		test2(atan2l, ldexpl(z, e), INFINITY, 0.0, 0);
229 		test2(atan2l, ldexpl(-z,e), INFINITY, -0.0, 0);
230 		test2(atan2l, ldexpl(z, e), -INFINITY, pi, FE_INEXACT);
231 		test2(atan2l, ldexpl(-z,e), -INFINITY, -pi, FE_INEXACT);
232 		test2(atan2l, INFINITY, ldexpl(z, e), pi / 2, FE_INEXACT);
233 		test2(atan2l, INFINITY, ldexpl(-z, e), pi / 2, FE_INEXACT);
234 		test2(atan2l, -INFINITY, ldexpl(z, e), -pi / 2, FE_INEXACT);
235 		test2(atan2l, -INFINITY, ldexpl(-z, e), -pi / 2, FE_INEXACT);
236 	}
237 }
238 
239 /*
240  * Test various inputs to asin(), acos() and atan() and verify that the
241  * results are accurate to within 1 ulp.
242  */
243 ATF_TC_WITHOUT_HEAD(accuracy);
244 ATF_TC_BODY(accuracy, tc)
245 {
246 
247 	/* We expect correctly rounded results for these basic cases. */
248 	testall(asin, 1.0, pi / 2, FE_INEXACT);
249 	testall(acos, 1.0, 0, 0);
250 	testall(atan, 1.0, pi / 4, FE_INEXACT);
251 	testall(asin, -1.0, -pi / 2, FE_INEXACT);
252 	testall(acos, -1.0, pi, FE_INEXACT);
253 	testall(atan, -1.0, -pi / 4, FE_INEXACT);
254 
255 	/*
256 	 * Here we expect answers to be within 1 ulp, although inexactness
257 	 * in the input, combined with double rounding, could cause larger
258 	 * errors.
259 	 */
260 
261 	testall_tol(asin, sqrtl(2) / 2, pi / 4, 1, FE_INEXACT);
262 	testall_tol(acos, sqrtl(2) / 2, pi / 4, 1, FE_INEXACT);
263 	testall_tol(asin, -sqrtl(2) / 2, -pi / 4, 1, FE_INEXACT);
264 	testall_tol(acos, -sqrtl(2) / 2, c3pi / 4, 1, FE_INEXACT);
265 
266 	testall_tol(asin, sqrtl(3) / 2, pio3, 1, FE_INEXACT);
267 	testall_tol(acos, sqrtl(3) / 2, pio3 / 2, 1, FE_INEXACT);
268 	testall_tol(atan, sqrtl(3), pio3, 1, FE_INEXACT);
269 	testall_tol(asin, -sqrtl(3) / 2, -pio3, 1, FE_INEXACT);
270 	testall_tol(acos, -sqrtl(3) / 2, c5pio3 / 2, 1, FE_INEXACT);
271 	testall_tol(atan, -sqrtl(3), -pio3, 1, FE_INEXACT);
272 
273 	testall_tol(atan, sqrt2m1, pi / 8, 1, FE_INEXACT);
274 	testall_tol(atan, -sqrt2m1, -pi / 8, 1, FE_INEXACT);
275 }
276 
277 /*
278  * Test inputs to atan2() where x is a power of 2. These are easy cases
279  * because y/x is exact.
280  */
281 ATF_TC_WITHOUT_HEAD(p2x_atan2);
282 ATF_TC_BODY(p2x_atan2, tc)
283 {
284 
285 	testall2(atan2, 1.0, 1.0, pi / 4, FE_INEXACT);
286 	testall2(atan2, 1.0, -1.0, c3pi / 4, FE_INEXACT);
287 	testall2(atan2, -1.0, 1.0, -pi / 4, FE_INEXACT);
288 	testall2(atan2, -1.0, -1.0, -c3pi / 4, FE_INEXACT);
289 
290 	testall2_tol(atan2, sqrt2m1 * 2, 2.0, pi / 8, 1, FE_INEXACT);
291 	testall2_tol(atan2, sqrt2m1 * 2, -2.0, c7pi / 8, 1, FE_INEXACT);
292 	testall2_tol(atan2, -sqrt2m1 * 2, 2.0, -pi / 8, 1, FE_INEXACT);
293 	testall2_tol(atan2, -sqrt2m1 * 2, -2.0, -c7pi / 8, 1, FE_INEXACT);
294 
295 	testall2_tol(atan2, sqrtl(3) * 0.5, 0.5, pio3, 1, FE_INEXACT);
296 	testall2_tol(atan2, sqrtl(3) * 0.5, -0.5, pio3 * 2, 1, FE_INEXACT);
297 	testall2_tol(atan2, -sqrtl(3) * 0.5, 0.5, -pio3, 1, FE_INEXACT);
298 	testall2_tol(atan2, -sqrtl(3) * 0.5, -0.5, -pio3 * 2, 1, FE_INEXACT);
299 }
300 
301 /*
302  * Test inputs very close to 0.
303  */
304 ATF_TC_WITHOUT_HEAD(tiny);
305 ATF_TC_BODY(tiny, tc)
306 {
307 	float tiny = 0x1.23456p-120f;
308 
309 	testall(asin, tiny, tiny, FE_INEXACT);
310 	testall(acos, tiny, pi / 2, FE_INEXACT);
311 	testall(atan, tiny, tiny, FE_INEXACT);
312 
313 	testall(asin, -tiny, -tiny, FE_INEXACT);
314 	testall(acos, -tiny, pi / 2, FE_INEXACT);
315 	testall(atan, -tiny, -tiny, FE_INEXACT);
316 
317 	/* Test inputs to atan2() that would cause y/x to underflow. */
318 	test2(atan2f, 0x1.0p-100, 0x1.0p100, 0.0, FE_INEXACT | FE_UNDERFLOW);
319 	test2(atan2, 0x1.0p-1000, 0x1.0p1000, 0.0, FE_INEXACT | FE_UNDERFLOW);
320 	test2(atan2l, ldexpl(1.0, 100 - LDBL_MAX_EXP),
321 	      ldexpl(1.0, LDBL_MAX_EXP - 100), 0.0, FE_INEXACT | FE_UNDERFLOW);
322 	test2(atan2f, -0x1.0p-100, 0x1.0p100, -0.0, FE_INEXACT | FE_UNDERFLOW);
323 	test2(atan2, -0x1.0p-1000, 0x1.0p1000, -0.0, FE_INEXACT | FE_UNDERFLOW);
324 	test2(atan2l, -ldexpl(1.0, 100 - LDBL_MAX_EXP),
325 	      ldexpl(1.0, LDBL_MAX_EXP - 100), -0.0, FE_INEXACT | FE_UNDERFLOW);
326 	test2(atan2f, 0x1.0p-100, -0x1.0p100, (float)pi, FE_INEXACT);
327 	test2(atan2, 0x1.0p-1000, -0x1.0p1000, (double)pi, FE_INEXACT);
328 	test2(atan2l, ldexpl(1.0, 100 - LDBL_MAX_EXP),
329 	      -ldexpl(1.0, LDBL_MAX_EXP - 100), pi, FE_INEXACT);
330 	test2(atan2f, -0x1.0p-100, -0x1.0p100, (float)-pi, FE_INEXACT);
331 	test2(atan2, -0x1.0p-1000, -0x1.0p1000, (double)-pi, FE_INEXACT);
332 	test2(atan2l, -ldexpl(1.0, 100 - LDBL_MAX_EXP),
333 	      -ldexpl(1.0, LDBL_MAX_EXP - 100), -pi, FE_INEXACT);
334 }
335 
336 /*
337  * Test very large inputs to atan().
338  */
339 ATF_TC_WITHOUT_HEAD(atan_huge);
340 ATF_TC_BODY(atan_huge, tc)
341 {
342 	float huge = 0x1.23456p120;
343 
344 	testall(atan, huge, pi / 2, FE_INEXACT);
345 	testall(atan, -huge, -pi / 2, FE_INEXACT);
346 
347 	/* Test inputs to atan2() that would cause y/x to overflow. */
348 	test2(atan2f, 0x1.0p100, 0x1.0p-100, (float)pi / 2, FE_INEXACT);
349 	test2(atan2, 0x1.0p1000, 0x1.0p-1000, (double)pi / 2, FE_INEXACT);
350 	test2(atan2l, ldexpl(1.0, LDBL_MAX_EXP - 100),
351 	      ldexpl(1.0, 100 - LDBL_MAX_EXP), pi / 2, FE_INEXACT);
352 	test2(atan2f, -0x1.0p100, 0x1.0p-100, (float)-pi / 2, FE_INEXACT);
353 	test2(atan2, -0x1.0p1000, 0x1.0p-1000, (double)-pi / 2, FE_INEXACT);
354 	test2(atan2l, -ldexpl(1.0, LDBL_MAX_EXP - 100),
355 	      ldexpl(1.0, 100 - LDBL_MAX_EXP), -pi / 2, FE_INEXACT);
356 
357 	test2(atan2f, 0x1.0p100, -0x1.0p-100, (float)pi / 2, FE_INEXACT);
358 	test2(atan2, 0x1.0p1000, -0x1.0p-1000, (double)pi / 2, FE_INEXACT);
359 	test2(atan2l, ldexpl(1.0, LDBL_MAX_EXP - 100),
360 	      -ldexpl(1.0, 100 - LDBL_MAX_EXP), pi / 2, FE_INEXACT);
361 	test2(atan2f, -0x1.0p100, -0x1.0p-100, (float)-pi / 2, FE_INEXACT);
362 	test2(atan2, -0x1.0p1000, -0x1.0p-1000, (double)-pi / 2, FE_INEXACT);
363 	test2(atan2l, -ldexpl(1.0, LDBL_MAX_EXP - 100),
364 	      -ldexpl(1.0, 100 - LDBL_MAX_EXP), -pi / 2, FE_INEXACT);
365 }
366 
367 /*
368  * Test that sin(asin(x)) == x, and similarly for acos() and atan().
369  * You need to have a working sinl(), cosl(), and tanl() for these
370  * tests to pass.
371  */
372 static long double
373 sinasinf(float x)
374 {
375 
376 	return (sinl(asinf(x)));
377 }
378 
379 static long double
380 sinasin(double x)
381 {
382 
383 	return (sinl(asin(x)));
384 }
385 
386 static long double
387 sinasinl(long double x)
388 {
389 
390 	return (sinl(asinl(x)));
391 }
392 
393 static long double
394 cosacosf(float x)
395 {
396 
397 	return (cosl(acosf(x)));
398 }
399 
400 static long double
401 cosacos(double x)
402 {
403 
404 	return (cosl(acos(x)));
405 }
406 
407 static long double
408 cosacosl(long double x)
409 {
410 
411 	return (cosl(acosl(x)));
412 }
413 
414 static long double
415 tanatanf(float x)
416 {
417 
418 	return (tanl(atanf(x)));
419 }
420 
421 static long double
422 tanatan(double x)
423 {
424 
425 	return (tanl(atan(x)));
426 }
427 
428 static long double
429 tanatanl(long double x)
430 {
431 
432 	return (tanl(atanl(x)));
433 }
434 
435 ATF_TC_WITHOUT_HEAD(inverse);
436 ATF_TC_BODY(inverse, tc)
437 {
438 	float i;
439 
440 	for (i = -1; i <= 1; i += 0x1.0p-12f) {
441 		testall_tol(sinasin, i, i, 2, i == 0 ? 0 : FE_INEXACT);
442 		/* The relative error for cosacos is very large near x=0. */
443 		if (fabsf(i) > 0x1.0p-4f)
444 			testall_tol(cosacos, i, i, 16, i == 1 ? 0 : FE_INEXACT);
445 		testall_tol(tanatan, i, i, 2, i == 0 ? 0 : FE_INEXACT);
446 	}
447 }
448 
449 ATF_TP_ADD_TCS(tp)
450 {
451 	ATF_TP_ADD_TC(tp, special);
452 	ATF_TP_ADD_TC(tp, special_atan2);
453 	ATF_TP_ADD_TC(tp, accuracy);
454 	ATF_TP_ADD_TC(tp, p2x_atan2);
455 	ATF_TP_ADD_TC(tp, tiny);
456 	ATF_TP_ADD_TC(tp, atan_huge);
457 	ATF_TP_ADD_TC(tp, inverse);
458 
459 	return (atf_no_error());
460 }
461