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