]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/msun/tests/ctrig_test.c
Merge lld trunk r321414 to contrib/llvm/tools/lld.
[FreeBSD/FreeBSD.git] / lib / msun / tests / ctrig_test.c
1 /*-
2  * Copyright (c) 2008-2011 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 csin[h](), ccos[h](), and ctan[h]().
29  */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include <sys/param.h>
35 #include <complex.h>
36 #include <fenv.h>
37 #include <float.h>
38 #include <math.h>
39 #include <stdio.h>
40
41 #include <atf-c.h>
42
43 #include "test-utils.h"
44
45 #pragma STDC FENV_ACCESS        ON
46 #pragma STDC CX_LIMITED_RANGE   OFF
47
48 /*
49  * Test that a function returns the correct value and sets the
50  * exception flags correctly. The exceptmask specifies which
51  * exceptions we should check. We need to be lenient for several
52  * reasons, but mainly because on some architectures it's impossible
53  * to raise FE_OVERFLOW without raising FE_INEXACT.
54  *
55  * These are macros instead of functions so that assert provides more
56  * meaningful error messages.
57  *
58  * XXX The volatile here is to avoid gcc's bogus constant folding and work
59  *     around the lack of support for the FENV_ACCESS pragma.
60  */
61 #define test_p(func, z, result, exceptmask, excepts, checksign) do {    \
62         volatile long double complex _d = z;                            \
63         debug("  testing %s(%Lg + %Lg I) == %Lg + %Lg I\n", #func,      \
64             creall(_d), cimagl(_d), creall(result), cimagl(result));    \
65         ATF_CHECK(feclearexcept(FE_ALL_EXCEPT) == 0);                   \
66         ATF_CHECK(cfpequal_cs((func)(_d), (result), (checksign)));              \
67         ATF_CHECK(((void)(func), fetestexcept(exceptmask) == (excepts)));       \
68 } while (0)
69
70 /*
71  * Test within a given tolerance.  The tolerance indicates relative error
72  * in ulps.  If result is 0, however, it measures absolute error in units
73  * of <format>_EPSILON.
74  */
75 #define test_p_tol(func, z, result, tol)                        do {    \
76         volatile long double complex _d = z;                            \
77         debug("  testing %s(%Lg + %Lg I) ~= %Lg + %Lg I\n", #func,      \
78             creall(_d), cimagl(_d), creall(result), cimagl(result));    \
79         ATF_CHECK(cfpequal_tol((func)(_d), (result), (tol), FPE_ABS_ZERO)); \
80 } while (0)
81
82 /* These wrappers apply the identities f(conj(z)) = conj(f(z)). */
83 #define test(func, z, result, exceptmask, excepts, checksign)   do {    \
84         test_p(func, z, result, exceptmask, excepts, checksign);        \
85         test_p(func, conjl(z), conjl(result), exceptmask, excepts, checksign); \
86 } while (0)
87 #define test_tol(func, z, result, tol)                          do {    \
88         test_p_tol(func, z, result, tol);                               \
89         test_p_tol(func, conjl(z), conjl(result), tol);                 \
90 } while (0)
91 #define test_odd_tol(func, z, result, tol)                      do {    \
92         test_tol(func, z, result, tol);                                 \
93         test_tol(func, -(z), -(result), tol);                           \
94 } while (0)
95 #define test_even_tol(func, z, result, tol)                     do {    \
96         test_tol(func, z, result, tol);                                 \
97         test_tol(func, -(z), result, tol);                              \
98 } while (0)
99
100 /* Test the given function in all precisions. */
101 #define testall(func, x, result, exceptmask, excepts, checksign) do {   \
102         test(func, x, result, exceptmask, excepts, checksign);          \
103         test(func##f, x, result, exceptmask, excepts, checksign);       \
104 } while (0)
105 #define testall_odd(func, x, result, exceptmask, excepts, checksign) do { \
106         testall(func, x, result, exceptmask, excepts, checksign);       \
107         testall(func, -x, -result, exceptmask, excepts, checksign);     \
108 } while (0)
109 #define testall_even(func, x, result, exceptmask, excepts, checksign) do { \
110         testall(func, x, result, exceptmask, excepts, checksign);       \
111         testall(func, -x, result, exceptmask, excepts, checksign);      \
112 } while (0)
113
114 /*
115  * Test the given function in all precisions, within a given tolerance.
116  * The tolerance is specified in ulps.
117  */
118 #define testall_tol(func, x, result, tol)                          do { \
119         test_tol(func, x, result, tol * DBL_ULP());                     \
120         test_tol(func##f, x, result, tol * FLT_ULP());                  \
121 } while (0)
122 #define testall_odd_tol(func, x, result, tol)                      do { \
123         test_odd_tol(func, x, result, tol * DBL_ULP());                 \
124         test_odd_tol(func##f, x, result, tol * FLT_ULP());              \
125 } while (0)
126 #define testall_even_tol(func, x, result, tol)                     do { \
127         test_even_tol(func, x, result, tol * DBL_ULP());                \
128         test_even_tol(func##f, x, result, tol * FLT_ULP());             \
129 } while (0)
130
131
132 ATF_TC(test_zero_input);
133 ATF_TC_HEAD(test_zero_input, tc)
134 {
135         atf_tc_set_md_var(tc, "descr", "test 0 input");
136 }
137 ATF_TC_BODY(test_zero_input, tc)
138 {
139         long double complex zero = CMPLXL(0.0, 0.0);
140
141 #if defined(__amd64__)
142 #if defined(__clang__) && \
143         ((__clang_major__ >= 4))
144         atf_tc_expect_fail("test fails with clang 4.x+ - bug 217528");
145 #endif
146 #endif
147
148         /* csinh(0) = ctanh(0) = 0; ccosh(0) = 1 (no exceptions raised) */
149         testall_odd(csinh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
150         testall_odd(csin, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
151         testall_even(ccosh, zero, 1.0, ALL_STD_EXCEPT, 0, CS_BOTH);
152         testall_even(ccos, zero, CMPLXL(1.0, -0.0), ALL_STD_EXCEPT, 0, CS_BOTH);
153         testall_odd(ctanh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
154         testall_odd(ctan, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
155 }
156
157 ATF_TC(test_nan_inputs);
158 ATF_TC_HEAD(test_nan_inputs, tc)
159 {
160         atf_tc_set_md_var(tc, "descr", "test NaN inputs");
161 }
162 ATF_TC_BODY(test_nan_inputs, tc)
163 {
164         long double complex nan_nan = CMPLXL(NAN, NAN);
165         long double complex z;
166
167         /*
168          * IN           CSINH           CCOSH           CTANH
169          * NaN,NaN      NaN,NaN         NaN,NaN         NaN,NaN
170          * finite,NaN   NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
171          * NaN,finite   NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
172          * NaN,Inf      NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
173          * Inf,NaN      +-Inf,NaN       Inf,NaN         1,+-0
174          * 0,NaN        +-0,NaN         NaN,+-0         NaN,NaN [inval]
175          * NaN,0        NaN,0           NaN,+-0         NaN,0
176          */
177         z = nan_nan;
178         testall_odd(csinh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
179         testall_even(ccosh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
180         testall_odd(ctanh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
181         testall_odd(csin, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
182         testall_even(ccos, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
183         testall_odd(ctan, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
184
185         z = CMPLXL(42, NAN);
186         testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
187         testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
188         /* XXX We allow a spurious inexact exception here. */
189         testall_odd(ctanh, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
190         testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
191         testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
192         testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
193
194         z = CMPLXL(NAN, 42);
195         testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
196         testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
197         testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
198         testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
199         testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
200         /* XXX We allow a spurious inexact exception here. */
201         testall_odd(ctan, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
202
203         z = CMPLXL(NAN, INFINITY);
204         testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
205         testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
206         testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
207         testall_odd(csin, z, CMPLXL(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
208         testall_even(ccos, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0,
209             CS_IMAG);
210         testall_odd(ctan, z, CMPLXL(0, 1), ALL_STD_EXCEPT, 0, CS_IMAG);
211
212         z = CMPLXL(INFINITY, NAN);
213         testall_odd(csinh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0, 0);
214         testall_even(ccosh, z, CMPLXL(INFINITY, NAN), ALL_STD_EXCEPT, 0,
215                      CS_REAL);
216         testall_odd(ctanh, z, CMPLXL(1, 0), ALL_STD_EXCEPT, 0, CS_REAL);
217         testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
218         testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
219         testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
220
221         z = CMPLXL(0, NAN);
222         testall_odd(csinh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, 0);
223         testall_even(ccosh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
224         testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
225         testall_odd(csin, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
226         testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
227         testall_odd(ctan, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
228
229         z = CMPLXL(NAN, 0);
230         testall_odd(csinh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
231         testall_even(ccosh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
232         testall_odd(ctanh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
233         testall_odd(csin, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
234         testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
235         testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
236 }
237
238 ATF_TC(test_inf_inputs);
239 ATF_TC_HEAD(test_inf_inputs, tc)
240 {
241         atf_tc_set_md_var(tc, "descr", "test infinity inputs");
242 }
243 ATF_TC_BODY(test_inf_inputs, tc)
244 {
245         static const long double finites[] = {
246             0, M_PI / 4, 3 * M_PI / 4, 5 * M_PI / 4,
247         };
248         long double complex z, c, s;
249         unsigned i;
250
251         /*
252          * IN           CSINH           CCOSH           CTANH
253          * Inf,Inf      +-Inf,NaN inval +-Inf,NaN inval 1,+-0
254          * Inf,finite   Inf cis(finite) Inf cis(finite) 1,0 sin(2 finite)
255          * 0,Inf        +-0,NaN inval   NaN,+-0 inval   NaN,NaN inval
256          * finite,Inf   NaN,NaN inval   NaN,NaN inval   NaN,NaN inval
257          */
258         z = CMPLXL(INFINITY, INFINITY);
259         testall_odd(csinh, z, CMPLXL(INFINITY, NAN),
260                     ALL_STD_EXCEPT, FE_INVALID, 0);
261         testall_even(ccosh, z, CMPLXL(INFINITY, NAN),
262                      ALL_STD_EXCEPT, FE_INVALID, 0);
263         testall_odd(ctanh, z, CMPLXL(1, 0), ALL_STD_EXCEPT, 0, CS_REAL);
264         testall_odd(csin, z, CMPLXL(NAN, INFINITY),
265                     ALL_STD_EXCEPT, FE_INVALID, 0);
266         testall_even(ccos, z, CMPLXL(INFINITY, NAN),
267                      ALL_STD_EXCEPT, FE_INVALID, 0);
268         testall_odd(ctan, z, CMPLXL(0, 1), ALL_STD_EXCEPT, 0, CS_REAL);
269
270         /* XXX We allow spurious inexact exceptions here (hard to avoid). */
271         for (i = 0; i < nitems(finites); i++) {
272                 z = CMPLXL(INFINITY, finites[i]);
273                 c = INFINITY * cosl(finites[i]);
274                 s = finites[i] == 0 ? finites[i] : INFINITY * sinl(finites[i]);
275                 testall_odd(csinh, z, CMPLXL(c, s), OPT_INEXACT, 0, CS_BOTH);
276                 testall_even(ccosh, z, CMPLXL(c, s), OPT_INEXACT, 0, CS_BOTH);
277                 testall_odd(ctanh, z, CMPLXL(1, 0 * sin(finites[i] * 2)),
278                             OPT_INEXACT, 0, CS_BOTH);
279                 z = CMPLXL(finites[i], INFINITY);
280                 testall_odd(csin, z, CMPLXL(s, c), OPT_INEXACT, 0, CS_BOTH);
281                 testall_even(ccos, z, CMPLXL(c, -s), OPT_INEXACT, 0, CS_BOTH);
282                 testall_odd(ctan, z, CMPLXL(0 * sin(finites[i] * 2), 1),
283                             OPT_INEXACT, 0, CS_BOTH);
284         }
285
286         z = CMPLXL(0, INFINITY);
287         testall_odd(csinh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
288         testall_even(ccosh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
289         testall_odd(ctanh, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
290         z = CMPLXL(INFINITY, 0);
291         testall_odd(csin, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
292         testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
293         testall_odd(ctan, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
294
295         z = CMPLXL(42, INFINITY);
296         testall_odd(csinh, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
297         testall_even(ccosh, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
298         /* XXX We allow a spurious inexact exception here. */
299         testall_odd(ctanh, z, CMPLXL(NAN, NAN), OPT_INEXACT, FE_INVALID, 0);
300         z = CMPLXL(INFINITY, 42);
301         testall_odd(csin, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
302         testall_even(ccos, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
303         /* XXX We allow a spurious inexact exception here. */
304         testall_odd(ctan, z, CMPLXL(NAN, NAN), OPT_INEXACT, FE_INVALID, 0);
305 }
306
307 ATF_TC(test_axes);
308 ATF_TC_HEAD(test_axes, tc)
309 {
310         atf_tc_set_md_var(tc, "descr", "test along the real/imaginary axes");
311 }
312 ATF_TC_BODY(test_axes, tc)
313 {
314         static const long double nums[] = {
315             M_PI / 4, M_PI / 2, 3 * M_PI / 4,
316             5 * M_PI / 4, 3 * M_PI / 2, 7 * M_PI / 4,
317         };
318         long double complex z;
319         unsigned i;
320
321         for (i = 0; i < nitems(nums); i++) {
322                 /* Real axis */
323                 z = CMPLXL(nums[i], 0.0);
324                 test_odd_tol(csinh, z, CMPLXL(sinh(nums[i]), 0), DBL_ULP());
325                 test_even_tol(ccosh, z, CMPLXL(cosh(nums[i]), 0), DBL_ULP());
326                 test_odd_tol(ctanh, z, CMPLXL(tanh(nums[i]), 0), DBL_ULP());
327                 test_odd_tol(csin, z, CMPLXL(sin(nums[i]),
328                     copysign(0, cos(nums[i]))), DBL_ULP());
329                 test_even_tol(ccos, z, CMPLXL(cos(nums[i]),
330                     -copysign(0, sin(nums[i]))), DBL_ULP());
331                 test_odd_tol(ctan, z, CMPLXL(tan(nums[i]), 0), DBL_ULP());
332
333                 test_odd_tol(csinhf, z, CMPLXL(sinhf(nums[i]), 0), FLT_ULP());
334                 test_even_tol(ccoshf, z, CMPLXL(coshf(nums[i]), 0), FLT_ULP());
335                 printf("%a %a\n", creal(z), cimag(z));
336                 printf("%a %a\n", creal(ctanhf(z)), cimag(ctanhf(z)));
337                 printf("%a\n", nextafterf(tanhf(nums[i]), INFINITY));
338                 test_odd_tol(ctanhf, z, CMPLXL(tanhf(nums[i]), 0),
339                              1.3 * FLT_ULP());
340                 test_odd_tol(csinf, z, CMPLXL(sinf(nums[i]),
341                     copysign(0, cosf(nums[i]))), FLT_ULP());
342                 test_even_tol(ccosf, z, CMPLXL(cosf(nums[i]),
343                     -copysign(0, sinf(nums[i]))), 2 * FLT_ULP());
344                 test_odd_tol(ctanf, z, CMPLXL(tanf(nums[i]), 0), FLT_ULP());
345
346                 /* Imaginary axis */
347                 z = CMPLXL(0.0, nums[i]);
348                 test_odd_tol(csinh, z, CMPLXL(copysign(0, cos(nums[i])),
349                                                  sin(nums[i])), DBL_ULP());
350                 test_even_tol(ccosh, z, CMPLXL(cos(nums[i]),
351                     copysign(0, sin(nums[i]))), DBL_ULP());
352                 test_odd_tol(ctanh, z, CMPLXL(0, tan(nums[i])), DBL_ULP());
353                 test_odd_tol(csin, z, CMPLXL(0, sinh(nums[i])), DBL_ULP());
354                 test_even_tol(ccos, z, CMPLXL(cosh(nums[i]), -0.0), DBL_ULP());
355                 test_odd_tol(ctan, z, CMPLXL(0, tanh(nums[i])), DBL_ULP());
356
357                 test_odd_tol(csinhf, z, CMPLXL(copysign(0, cosf(nums[i])),
358                                                  sinf(nums[i])), FLT_ULP());
359                 test_even_tol(ccoshf, z, CMPLXL(cosf(nums[i]),
360                     copysign(0, sinf(nums[i]))), FLT_ULP());
361                 test_odd_tol(ctanhf, z, CMPLXL(0, tanf(nums[i])), FLT_ULP());
362                 test_odd_tol(csinf, z, CMPLXL(0, sinhf(nums[i])), FLT_ULP());
363                 test_even_tol(ccosf, z, CMPLXL(coshf(nums[i]), -0.0),
364                               FLT_ULP());
365                 test_odd_tol(ctanf, z, CMPLXL(0, tanhf(nums[i])),
366                              1.3 * FLT_ULP());
367         }
368 }
369
370 ATF_TC(test_small_inputs);
371 ATF_TC_HEAD(test_small_inputs, tc)
372 {
373         atf_tc_set_md_var(tc, "descr", "test underflow inputs");
374 }
375 ATF_TC_BODY(test_small_inputs, tc)
376 {
377         /*
378          * z =  0.5 + i Pi/4
379          *     sinh(z) = (sinh(0.5) + i cosh(0.5)) * sqrt(2)/2
380          *     cosh(z) = (cosh(0.5) + i sinh(0.5)) * sqrt(2)/2
381          *     tanh(z) = (2cosh(0.5)sinh(0.5) + i) / (2 cosh(0.5)**2 - 1)
382          * z = -0.5 + i Pi/2
383          *     sinh(z) = cosh(0.5)
384          *     cosh(z) = -i sinh(0.5)
385          *     tanh(z) = -coth(0.5)
386          * z =  1.0 + i 3Pi/4
387          *     sinh(z) = (-sinh(1) + i cosh(1)) * sqrt(2)/2
388          *     cosh(z) = (-cosh(1) + i sinh(1)) * sqrt(2)/2
389          *     tanh(z) = (2cosh(1)sinh(1) - i) / (2cosh(1)**2 - 1)
390          */
391         static const struct {
392                 long double a, b;
393                 long double sinh_a, sinh_b;
394                 long double cosh_a, cosh_b;
395                 long double tanh_a, tanh_b;
396         } tests[] = {
397                 {  0.5L,
398                    0.78539816339744830961566084581987572L,
399                    0.36847002415910435172083660522240710L,
400                    0.79735196663945774996093142586179334L,
401                    0.79735196663945774996093142586179334L,
402                    0.36847002415910435172083660522240710L,
403                    0.76159415595576488811945828260479359L,
404                    0.64805427366388539957497735322615032L },
405                 { -0.5L,
406                    1.57079632679489661923132169163975144L,
407                    0.0L,
408                    1.12762596520638078522622516140267201L,
409                    0.0L,
410                   -0.52109530549374736162242562641149156L,
411                   -2.16395341373865284877000401021802312L,
412                    0.0L },
413                 {  1.0L,
414                    2.35619449019234492884698253745962716L,
415                   -0.83099273328405698212637979852748608L,
416                    1.09112278079550143030545602018565236L,
417                   -1.09112278079550143030545602018565236L,
418                    0.83099273328405698212637979852748609L,
419                    0.96402758007581688394641372410092315L,
420                   -0.26580222883407969212086273981988897L }
421         };
422         long double complex z;
423         unsigned i;
424
425         for (i = 0; i < nitems(tests); i++) {
426                 z = CMPLXL(tests[i].a, tests[i].b);
427                 testall_odd_tol(csinh, z,
428                     CMPLXL(tests[i].sinh_a, tests[i].sinh_b), 1.1);
429                 testall_even_tol(ccosh, z,
430                     CMPLXL(tests[i].cosh_a, tests[i].cosh_b), 1.1);
431                 testall_odd_tol(ctanh, z,
432                     CMPLXL(tests[i].tanh_a, tests[i].tanh_b), 1.4);
433         }
434 }
435
436 ATF_TC(test_large_inputs);
437 ATF_TC_HEAD(test_large_inputs, tc)
438 {
439         atf_tc_set_md_var(tc, "descr",
440             "Test inputs that might cause overflow in a sloppy implementation");
441 }
442 ATF_TC_BODY(test_large_inputs, tc)
443 {
444         long double complex z;
445
446         /* tanh() uses a threshold around x=22, so check both sides. */
447         z = CMPLXL(21, 0.78539816339744830961566084581987572L);
448         testall_odd_tol(ctanh, z,
449             CMPLXL(1.0, 1.14990445285871196133287617611468468e-18L), 1.2);
450         z++;
451         testall_odd_tol(ctanh, z,
452             CMPLXL(1.0, 1.55622644822675930314266334585597964e-19L), 1);
453
454         z = CMPLXL(355, 0.78539816339744830961566084581987572L);
455         test_odd_tol(ctanh, z,
456                      CMPLXL(1.0, 8.95257245135025991216632140458264468e-309L),
457                      DBL_ULP());
458         z = CMPLXL(30, 0x1p1023L);
459         test_odd_tol(ctanh, z,
460                      CMPLXL(1.0, -1.62994325413993477997492170229268382e-26L),
461                      DBL_ULP());
462         z = CMPLXL(1, 0x1p1023L);
463         test_odd_tol(ctanh, z,
464                      CMPLXL(0.878606311888306869546254022621986509L,
465                             -0.225462792499754505792678258169527424L),
466                      DBL_ULP());
467
468         z = CMPLXL(710.6, 0.78539816339744830961566084581987572L);
469         test_odd_tol(csinh, z,
470             CMPLXL(1.43917579766621073533185387499658944e308L,
471                    1.43917579766621073533185387499658944e308L), DBL_ULP());
472         test_even_tol(ccosh, z,
473             CMPLXL(1.43917579766621073533185387499658944e308L,
474                    1.43917579766621073533185387499658944e308L), DBL_ULP());
475
476         z = CMPLXL(1500, 0.78539816339744830961566084581987572L);
477         testall_odd(csinh, z, CMPLXL(INFINITY, INFINITY), OPT_INEXACT,
478             FE_OVERFLOW, CS_BOTH);
479         testall_even(ccosh, z, CMPLXL(INFINITY, INFINITY), OPT_INEXACT,
480             FE_OVERFLOW, CS_BOTH);
481 }
482
483 ATF_TP_ADD_TCS(tp)
484 {
485
486         ATF_TP_ADD_TC(tp, test_zero_input);
487         ATF_TP_ADD_TC(tp, test_nan_inputs);
488         ATF_TP_ADD_TC(tp, test_inf_inputs);
489         ATF_TP_ADD_TC(tp, test_axes);
490         ATF_TP_ADD_TC(tp, test_small_inputs);
491         ATF_TP_ADD_TC(tp, test_large_inputs);
492
493         return (atf_no_error());
494 }