]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - tools/regression/lib/msun/test-invtrig.c
MFstable/10 r292795:
[FreeBSD/stable/9.git] / tools / regression / lib / msun / test-invtrig.c
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 __FBSDID("$FreeBSD$");
35
36 #include <assert.h>
37 #include <fenv.h>
38 #include <float.h>
39 #include <math.h>
40 #include <stdio.h>
41
42 #define ALL_STD_EXCEPT  (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
43                          FE_OVERFLOW | FE_UNDERFLOW)
44
45 #define LEN(a)          (sizeof(a) / sizeof((a)[0]))
46
47 #pragma STDC FENV_ACCESS ON
48
49 /*
50  * Test that a function returns the correct value and sets the
51  * exception flags correctly. A tolerance specifying the maximum
52  * relative error allowed may be specified. For the 'testall'
53  * functions, the tolerance is specified in ulps.
54  *
55  * These are macros instead of functions so that assert provides more
56  * meaningful error messages.
57  */
58 #define test_tol(func, x, result, tol, excepts) do {                    \
59         volatile long double _in = (x), _out = (result);                \
60         assert(feclearexcept(FE_ALL_EXCEPT) == 0);                      \
61         assert(fpequal(func(_in), _out, (tol)));                        \
62         assert((func, fetestexcept(ALL_STD_EXCEPT) == (excepts)));      \
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         assert(feclearexcept(FE_ALL_EXCEPT) == 0);                      \
90         assert(fpequal(func(_iny, _inx), _out, (tol)));                 \
91         assert((func, fetestexcept(ALL_STD_EXCEPT) == (excepts)));      \
92 } while (0)
93 #define test2(func, y, x, result, excepts)                              \
94         test2_tol(func, (y), (x), (result), 0, (excepts))
95
96 #define _testall2_tol(prefix, y, x, result, tol, excepts) do {          \
97         test2_tol(prefix, (double)(y), (double)(x), (double)(result),   \
98                   (tol) * ldexp(1.0, 1 - DBL_MANT_DIG), (excepts));     \
99         test2_tol(prefix##f, (float)(y), (float)(x), (float)(result),   \
100                   (tol) * ldexpf(1.0, 1 - FLT_MANT_DIG), (excepts));    \
101 } while (0)
102
103 #if LDBL_PREC == 53
104 #define testall2_tol    _testall2_tol
105 #else
106 #define testall2_tol(prefix, y, x, result, tol, excepts) do {           \
107         _testall2_tol(prefix, y, x, result, tol, excepts);              \
108         test2_tol(prefix##l, (y), (x), (result),                        \
109                   (tol) * ldexpl(1.0, 1 - LDBL_MANT_DIG), (excepts));   \
110 } while (0)
111 #endif
112
113 #define testall2(prefix, y, x, result, excepts)                         \
114         testall2_tol(prefix, (y), (x), (result), 0, (excepts))
115
116 long double
117 pi =   3.14159265358979323846264338327950280e+00L,
118 pio3 = 1.04719755119659774615421446109316766e+00L,
119 c3pi = 9.42477796076937971538793014983850839e+00L,
120 c5pi = 1.57079632679489661923132169163975140e+01L,
121 c7pi = 2.19911485751285526692385036829565196e+01L,
122 c5pio3 = 5.23598775598298873077107230546583851e+00L,
123 sqrt2m1 = 4.14213562373095048801688724209698081e-01L;
124
125 /*
126  * Determine whether x and y are equal to within a relative error of tol,
127  * with two special rules:
128  *      +0.0 != -0.0
129  *       NaN == NaN
130  */
131 int
132 fpequal(long double x, long double y, long double tol)
133 {
134         fenv_t env;
135         int ret;
136
137         if (isnan(x) && isnan(y))
138                 return (1);
139         if (!signbit(x) != !signbit(y))
140                 return (0);
141         if (x == y)
142                 return (1);
143         if (tol == 0)
144                 return (0);
145
146         /* Hard case: need to check the tolerance. */
147         feholdexcept(&env);
148         ret = fabsl(x - y) <= fabsl(y * tol);
149         fesetenv(&env);
150         return (ret);
151 }
152
153 /*
154  * Test special case inputs in asin(), acos() and atan(): signed
155  * zeroes, infinities, and NaNs.
156  */
157 static void
158 test_special(void)
159 {
160
161         testall(asin, 0.0, 0.0, 0);
162         testall(acos, 0.0, pi / 2, FE_INEXACT);
163         testall(atan, 0.0, 0.0, 0);
164         testall(asin, -0.0, -0.0, 0);
165         testall(acos, -0.0, pi / 2, FE_INEXACT);
166         testall(atan, -0.0, -0.0, 0);
167
168         testall(asin, INFINITY, NAN, FE_INVALID);
169         testall(acos, INFINITY, NAN, FE_INVALID);
170         testall(atan, INFINITY, pi / 2, FE_INEXACT);
171         testall(asin, -INFINITY, NAN, FE_INVALID);
172         testall(acos, -INFINITY, NAN, FE_INVALID);
173         testall(atan, -INFINITY, -pi / 2, FE_INEXACT);
174
175         testall(asin, NAN, NAN, 0);
176         testall(acos, NAN, NAN, 0);
177         testall(atan, NAN, NAN, 0);
178 }
179
180 /*
181  * Test special case inputs in atan2(), where the exact value of y/x is
182  * zero or non-finite.
183  */
184 static void
185 test_special_atan2(void)
186 {
187         long double z;
188         int e;
189
190         testall2(atan2, 0.0, -0.0, pi, FE_INEXACT);
191         testall2(atan2, -0.0, -0.0, -pi, FE_INEXACT);
192         testall2(atan2, 0.0, 0.0, 0.0, 0);
193         testall2(atan2, -0.0, 0.0, -0.0, 0);
194
195         testall2(atan2, INFINITY, -INFINITY, c3pi / 4, FE_INEXACT);
196         testall2(atan2, -INFINITY, -INFINITY, -c3pi / 4, FE_INEXACT);
197         testall2(atan2, INFINITY, INFINITY, pi / 4, FE_INEXACT);
198         testall2(atan2, -INFINITY, INFINITY, -pi / 4, FE_INEXACT);
199
200         /* Tests with one input in the range (0, Inf]. */
201         z = 1.23456789L;
202         for (e = FLT_MIN_EXP - FLT_MANT_DIG; e <= FLT_MAX_EXP; e++) {
203                 test2(atan2f, 0.0, ldexpf(z, e), 0.0, 0);
204                 test2(atan2f, -0.0, ldexpf(z, e), -0.0, 0);
205                 test2(atan2f, 0.0, ldexpf(-z, e), (float)pi, FE_INEXACT);
206                 test2(atan2f, -0.0, ldexpf(-z, e), (float)-pi, FE_INEXACT);
207                 test2(atan2f, ldexpf(z, e), 0.0, (float)pi / 2, FE_INEXACT);
208                 test2(atan2f, ldexpf(z, e), -0.0, (float)pi / 2, FE_INEXACT);
209                 test2(atan2f, ldexpf(-z, e), 0.0, (float)-pi / 2, FE_INEXACT);
210                 test2(atan2f, ldexpf(-z, e), -0.0, (float)-pi / 2, FE_INEXACT);
211         }
212         for (e = DBL_MIN_EXP - DBL_MANT_DIG; e <= DBL_MAX_EXP; e++) {
213                 test2(atan2, 0.0, ldexp(z, e), 0.0, 0);
214                 test2(atan2, -0.0, ldexp(z, e), -0.0, 0);
215                 test2(atan2, 0.0, ldexp(-z, e), (double)pi, FE_INEXACT);
216                 test2(atan2, -0.0, ldexp(-z, e), (double)-pi, FE_INEXACT);
217                 test2(atan2, ldexp(z, e), 0.0, (double)pi / 2, FE_INEXACT);
218                 test2(atan2, ldexp(z, e), -0.0, (double)pi / 2, FE_INEXACT);
219                 test2(atan2, ldexp(-z, e), 0.0, (double)-pi / 2, FE_INEXACT);
220                 test2(atan2, ldexp(-z, e), -0.0, (double)-pi / 2, FE_INEXACT);
221         }
222         for (e = LDBL_MIN_EXP - LDBL_MANT_DIG; e <= LDBL_MAX_EXP; e++) {
223                 test2(atan2l, 0.0, ldexpl(z, e), 0.0, 0);
224                 test2(atan2l, -0.0, ldexpl(z, e), -0.0, 0);
225                 test2(atan2l, 0.0, ldexpl(-z, e), pi, FE_INEXACT);
226                 test2(atan2l, -0.0, ldexpl(-z, e), -pi, FE_INEXACT);
227                 test2(atan2l, ldexpl(z, e), 0.0, pi / 2, FE_INEXACT);
228                 test2(atan2l, ldexpl(z, e), -0.0, pi / 2, FE_INEXACT);
229                 test2(atan2l, ldexpl(-z, e), 0.0, -pi / 2, FE_INEXACT);
230                 test2(atan2l, ldexpl(-z, e), -0.0, -pi / 2, FE_INEXACT);
231         }
232
233         /* Tests with one input in the range (0, Inf). */
234         for (e = FLT_MIN_EXP - FLT_MANT_DIG; e <= FLT_MAX_EXP - 1; e++) {
235                 test2(atan2f, ldexpf(z, e), INFINITY, 0.0, 0);
236                 test2(atan2f, ldexpf(-z,e), INFINITY, -0.0, 0);
237                 test2(atan2f, ldexpf(z, e), -INFINITY, (float)pi, FE_INEXACT);
238                 test2(atan2f, ldexpf(-z,e), -INFINITY, (float)-pi, FE_INEXACT);
239                 test2(atan2f, INFINITY, ldexpf(z,e), (float)pi/2, FE_INEXACT);
240                 test2(atan2f, INFINITY, ldexpf(-z,e), (float)pi/2, FE_INEXACT);
241                 test2(atan2f, -INFINITY, ldexpf(z,e), (float)-pi/2,FE_INEXACT);
242                 test2(atan2f, -INFINITY, ldexpf(-z,e),(float)-pi/2,FE_INEXACT);
243         }
244         for (e = DBL_MIN_EXP - DBL_MANT_DIG; e <= DBL_MAX_EXP - 1; e++) {
245                 test2(atan2, ldexp(z, e), INFINITY, 0.0, 0);
246                 test2(atan2, ldexp(-z,e), INFINITY, -0.0, 0);
247                 test2(atan2, ldexp(z, e), -INFINITY, (double)pi, FE_INEXACT);
248                 test2(atan2, ldexp(-z,e), -INFINITY, (double)-pi, FE_INEXACT);
249                 test2(atan2, INFINITY, ldexp(z,e), (double)pi/2, FE_INEXACT);
250                 test2(atan2, INFINITY, ldexp(-z,e), (double)pi/2, FE_INEXACT);
251                 test2(atan2, -INFINITY, ldexp(z,e), (double)-pi/2,FE_INEXACT);
252                 test2(atan2, -INFINITY, ldexp(-z,e),(double)-pi/2,FE_INEXACT);
253         }
254         for (e = LDBL_MIN_EXP - LDBL_MANT_DIG; e <= LDBL_MAX_EXP - 1; e++) {
255                 test2(atan2l, ldexpl(z, e), INFINITY, 0.0, 0);
256                 test2(atan2l, ldexpl(-z,e), INFINITY, -0.0, 0);
257                 test2(atan2l, ldexpl(z, e), -INFINITY, pi, FE_INEXACT);
258                 test2(atan2l, ldexpl(-z,e), -INFINITY, -pi, FE_INEXACT);
259                 test2(atan2l, INFINITY, ldexpl(z, e), pi / 2, FE_INEXACT);
260                 test2(atan2l, INFINITY, ldexpl(-z, e), pi / 2, FE_INEXACT);
261                 test2(atan2l, -INFINITY, ldexpl(z, e), -pi / 2, FE_INEXACT);
262                 test2(atan2l, -INFINITY, ldexpl(-z, e), -pi / 2, FE_INEXACT);
263         }
264 }
265
266 /*
267  * Test various inputs to asin(), acos() and atan() and verify that the
268  * results are accurate to within 1 ulp.
269  */
270 static void
271 test_accuracy(void)
272 {
273
274         /* We expect correctly rounded results for these basic cases. */
275         testall(asin, 1.0, pi / 2, FE_INEXACT);
276         testall(acos, 1.0, 0, 0);
277         testall(atan, 1.0, pi / 4, FE_INEXACT);
278         testall(asin, -1.0, -pi / 2, FE_INEXACT);
279         testall(acos, -1.0, pi, FE_INEXACT);
280         testall(atan, -1.0, -pi / 4, FE_INEXACT);
281
282         /*
283          * Here we expect answers to be within 1 ulp, although inexactness
284          * in the input, combined with double rounding, could cause larger
285          * errors.
286          */
287
288         testall_tol(asin, sqrtl(2) / 2, pi / 4, 1, FE_INEXACT);
289         testall_tol(acos, sqrtl(2) / 2, pi / 4, 1, FE_INEXACT);
290         testall_tol(asin, -sqrtl(2) / 2, -pi / 4, 1, FE_INEXACT);
291         testall_tol(acos, -sqrtl(2) / 2, c3pi / 4, 1, FE_INEXACT);
292
293         testall_tol(asin, sqrtl(3) / 2, pio3, 1, FE_INEXACT);
294         testall_tol(acos, sqrtl(3) / 2, pio3 / 2, 1, FE_INEXACT);
295         testall_tol(atan, sqrtl(3), pio3, 1, FE_INEXACT);
296         testall_tol(asin, -sqrtl(3) / 2, -pio3, 1, FE_INEXACT);
297         testall_tol(acos, -sqrtl(3) / 2, c5pio3 / 2, 1, FE_INEXACT);
298         testall_tol(atan, -sqrtl(3), -pio3, 1, FE_INEXACT);
299
300         testall_tol(atan, sqrt2m1, pi / 8, 1, FE_INEXACT);
301         testall_tol(atan, -sqrt2m1, -pi / 8, 1, FE_INEXACT);
302 }
303
304 /*
305  * Test inputs to atan2() where x is a power of 2. These are easy cases
306  * because y/x is exact.
307  */
308 static void
309 test_p2x_atan2(void)
310 {
311
312         testall2(atan2, 1.0, 1.0, pi / 4, FE_INEXACT);
313         testall2(atan2, 1.0, -1.0, c3pi / 4, FE_INEXACT);
314         testall2(atan2, -1.0, 1.0, -pi / 4, FE_INEXACT);
315         testall2(atan2, -1.0, -1.0, -c3pi / 4, FE_INEXACT);
316
317         testall2_tol(atan2, sqrt2m1 * 2, 2.0, pi / 8, 1, FE_INEXACT);
318         testall2_tol(atan2, sqrt2m1 * 2, -2.0, c7pi / 8, 1, FE_INEXACT);
319         testall2_tol(atan2, -sqrt2m1 * 2, 2.0, -pi / 8, 1, FE_INEXACT);
320         testall2_tol(atan2, -sqrt2m1 * 2, -2.0, -c7pi / 8, 1, FE_INEXACT);
321
322         testall2_tol(atan2, sqrtl(3) * 0.5, 0.5, pio3, 1, FE_INEXACT);
323         testall2_tol(atan2, sqrtl(3) * 0.5, -0.5, pio3 * 2, 1, FE_INEXACT);
324         testall2_tol(atan2, -sqrtl(3) * 0.5, 0.5, -pio3, 1, FE_INEXACT);
325         testall2_tol(atan2, -sqrtl(3) * 0.5, -0.5, -pio3 * 2, 1, FE_INEXACT);
326 }
327
328 /*
329  * Test inputs very close to 0.
330  */
331 static void
332 test_tiny(void)
333 {
334         float tiny = 0x1.23456p-120f;
335
336         testall(asin, tiny, tiny, FE_INEXACT);
337         testall(acos, tiny, pi / 2, FE_INEXACT);
338         testall(atan, tiny, tiny, FE_INEXACT);
339
340         testall(asin, -tiny, -tiny, FE_INEXACT);
341         testall(acos, -tiny, pi / 2, FE_INEXACT);
342         testall(atan, -tiny, -tiny, FE_INEXACT);
343
344         /* Test inputs to atan2() that would cause y/x to underflow. */
345         test2(atan2f, 0x1.0p-100, 0x1.0p100, 0.0, FE_INEXACT | FE_UNDERFLOW);
346         test2(atan2, 0x1.0p-1000, 0x1.0p1000, 0.0, FE_INEXACT | FE_UNDERFLOW);
347         test2(atan2l, ldexpl(1.0, 100 - LDBL_MAX_EXP),
348               ldexpl(1.0, LDBL_MAX_EXP - 100), 0.0, FE_INEXACT | FE_UNDERFLOW);
349         test2(atan2f, -0x1.0p-100, 0x1.0p100, -0.0, FE_INEXACT | FE_UNDERFLOW);
350         test2(atan2, -0x1.0p-1000, 0x1.0p1000, -0.0, FE_INEXACT | FE_UNDERFLOW);
351         test2(atan2l, -ldexpl(1.0, 100 - LDBL_MAX_EXP),
352               ldexpl(1.0, LDBL_MAX_EXP - 100), -0.0, FE_INEXACT | FE_UNDERFLOW);
353         test2(atan2f, 0x1.0p-100, -0x1.0p100, (float)pi, FE_INEXACT);
354         test2(atan2, 0x1.0p-1000, -0x1.0p1000, (double)pi, FE_INEXACT);
355         test2(atan2l, ldexpl(1.0, 100 - LDBL_MAX_EXP),
356               -ldexpl(1.0, LDBL_MAX_EXP - 100), pi, FE_INEXACT);
357         test2(atan2f, -0x1.0p-100, -0x1.0p100, (float)-pi, FE_INEXACT);
358         test2(atan2, -0x1.0p-1000, -0x1.0p1000, (double)-pi, FE_INEXACT);
359         test2(atan2l, -ldexpl(1.0, 100 - LDBL_MAX_EXP),
360               -ldexpl(1.0, LDBL_MAX_EXP - 100), -pi, FE_INEXACT);
361 }
362
363 /*
364  * Test very large inputs to atan().
365  */
366 static void
367 test_atan_huge(void)
368 {
369         float huge = 0x1.23456p120;
370
371         testall(atan, huge, pi / 2, FE_INEXACT);
372         testall(atan, -huge, -pi / 2, FE_INEXACT);
373
374         /* Test inputs to atan2() that would cause y/x to overflow. */
375         test2(atan2f, 0x1.0p100, 0x1.0p-100, (float)pi / 2, FE_INEXACT);
376         test2(atan2, 0x1.0p1000, 0x1.0p-1000, (double)pi / 2, FE_INEXACT);
377         test2(atan2l, ldexpl(1.0, LDBL_MAX_EXP - 100),
378               ldexpl(1.0, 100 - LDBL_MAX_EXP), pi / 2, FE_INEXACT);
379         test2(atan2f, -0x1.0p100, 0x1.0p-100, (float)-pi / 2, FE_INEXACT);
380         test2(atan2, -0x1.0p1000, 0x1.0p-1000, (double)-pi / 2, FE_INEXACT);
381         test2(atan2l, -ldexpl(1.0, LDBL_MAX_EXP - 100),
382               ldexpl(1.0, 100 - LDBL_MAX_EXP), -pi / 2, FE_INEXACT);
383
384         test2(atan2f, 0x1.0p100, -0x1.0p-100, (float)pi / 2, FE_INEXACT);
385         test2(atan2, 0x1.0p1000, -0x1.0p-1000, (double)pi / 2, FE_INEXACT);
386         test2(atan2l, ldexpl(1.0, LDBL_MAX_EXP - 100),
387               -ldexpl(1.0, 100 - LDBL_MAX_EXP), pi / 2, FE_INEXACT);
388         test2(atan2f, -0x1.0p100, -0x1.0p-100, (float)-pi / 2, FE_INEXACT);
389         test2(atan2, -0x1.0p1000, -0x1.0p-1000, (double)-pi / 2, FE_INEXACT);
390         test2(atan2l, -ldexpl(1.0, LDBL_MAX_EXP - 100),
391               -ldexpl(1.0, 100 - LDBL_MAX_EXP), -pi / 2, FE_INEXACT);
392 }
393
394 /*
395  * Test that sin(asin(x)) == x, and similarly for acos() and atan().
396  * You need to have a working sinl(), cosl(), and tanl() for these
397  * tests to pass.
398  */
399 static long double
400 sinasinf(float x)
401 {
402
403         return (sinl(asinf(x)));
404 }
405
406 static long double
407 sinasin(double x)
408 {
409
410         return (sinl(asin(x)));
411 }
412
413 static long double
414 sinasinl(long double x)
415 {
416
417         return (sinl(asinl(x)));
418 }
419
420 static long double
421 cosacosf(float x)
422 {
423
424         return (cosl(acosf(x)));
425 }
426
427 static long double
428 cosacos(double x)
429 {
430
431         return (cosl(acos(x)));
432 }
433
434 static long double
435 cosacosl(long double x)
436 {
437
438         return (cosl(acosl(x)));
439 }
440
441 static long double
442 tanatanf(float x)
443 {
444
445         return (tanl(atanf(x)));
446 }
447
448 static long double
449 tanatan(double x)
450 {
451
452         return (tanl(atan(x)));
453 }
454
455 static long double
456 tanatanl(long double x)
457 {
458
459         return (tanl(atanl(x)));
460 }
461
462 static void
463 test_inverse(void)
464 {
465         float i;
466
467         for (i = -1; i <= 1; i += 0x1.0p-12f) {
468                 testall_tol(sinasin, i, i, 2, i == 0 ? 0 : FE_INEXACT);
469                 /* The relative error for cosacos is very large near x=0. */
470                 if (fabsf(i) > 0x1.0p-4f)
471                         testall_tol(cosacos, i, i, 16, i == 1 ? 0 : FE_INEXACT);
472                 testall_tol(tanatan, i, i, 2, i == 0 ? 0 : FE_INEXACT);
473         }
474 }
475
476 int
477 main(int argc, char *argv[])
478 {
479
480 #if defined(__i386__)
481         printf("1..0 # SKIP fails all assertions on i386\n");
482         return (0);
483 #endif
484
485         printf("1..7\n");
486
487         test_special();
488         printf("ok 1 - special\n");
489
490         test_special_atan2();
491         printf("ok 2 - atan2 special\n");
492
493         test_accuracy();
494         printf("ok 3 - accuracy\n");
495
496         test_p2x_atan2();
497         printf("ok 4 - atan2 p2x\n");
498
499         test_tiny();
500         printf("ok 5 - tiny inputs\n");
501
502         test_atan_huge();
503         printf("ok 6 - atan huge inputs\n");
504
505         test_inverse();
506         printf("ok 7 - inverse\n");
507
508         return (0);
509 }