]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - tools/regression/lib/msun/test-ctrig.c
MFstable/10 r226603,r251119:
[FreeBSD/stable/9.git] / tools / regression / lib / msun / test-ctrig.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 <assert.h>
35 #include <complex.h>
36 #include <fenv.h>
37 #include <float.h>
38 #include <math.h>
39 #include <stdio.h>
40
41 #define ALL_STD_EXCEPT  (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
42                          FE_OVERFLOW | FE_UNDERFLOW)
43 #define OPT_INVALID     (ALL_STD_EXCEPT & ~FE_INVALID)
44 #define OPT_INEXACT     (ALL_STD_EXCEPT & ~FE_INEXACT)
45 #define FLT_ULP()       ldexpl(1.0, 1 - FLT_MANT_DIG)
46 #define DBL_ULP()       ldexpl(1.0, 1 - DBL_MANT_DIG)
47 #define LDBL_ULP()      ldexpl(1.0, 1 - LDBL_MANT_DIG)
48
49 #pragma STDC FENV_ACCESS        ON
50 #pragma STDC CX_LIMITED_RANGE   OFF
51
52 /*
53  * XXX gcc implements complex multiplication incorrectly. In
54  * particular, it implements it as if the CX_LIMITED_RANGE pragma
55  * were ON. Consequently, we need this function to form numbers
56  * such as x + INFINITY * I, since gcc evalutes INFINITY * I as
57  * NaN + INFINITY * I.
58  */
59 static inline long double complex
60 cpackl(long double x, long double y)
61 {
62         long double complex z;
63
64         __real__ z = x;
65         __imag__ z = y;
66         return (z);
67 }
68
69 /* Flags that determine whether to check the signs of the result. */
70 #define CS_REAL 1
71 #define CS_IMAG 2
72 #define CS_BOTH (CS_REAL | CS_IMAG)
73
74 #ifdef  DEBUG
75 #define debug(...)      printf(__VA_ARGS__)
76 #else
77 #define debug(...)      (void)0
78 #endif
79
80 /*
81  * Test that a function returns the correct value and sets the
82  * exception flags correctly. The exceptmask specifies which
83  * exceptions we should check. We need to be lenient for several
84  * reasons, but mainly because on some architectures it's impossible
85  * to raise FE_OVERFLOW without raising FE_INEXACT.
86  *
87  * These are macros instead of functions so that assert provides more
88  * meaningful error messages.
89  *
90  * XXX The volatile here is to avoid gcc's bogus constant folding and work
91  *     around the lack of support for the FENV_ACCESS pragma.
92  */
93 #define test_p(func, z, result, exceptmask, excepts, checksign) do {    \
94         volatile long double complex _d = z;                            \
95         debug("  testing %s(%Lg + %Lg I) == %Lg + %Lg I\n", #func,      \
96             creall(_d), cimagl(_d), creall(result), cimagl(result));    \
97         assert(feclearexcept(FE_ALL_EXCEPT) == 0);                      \
98         assert(cfpequal((func)(_d), (result), (checksign)));            \
99         assert(((func), fetestexcept(exceptmask) == (excepts)));        \
100 } while (0)
101
102 /*
103  * Test within a given tolerance.  The tolerance indicates relative error
104  * in ulps.  If result is 0, however, it measures absolute error in units
105  * of <format>_EPSILON.
106  */
107 #define test_p_tol(func, z, result, tol)                        do {    \
108         volatile long double complex _d = z;                            \
109         debug("  testing %s(%Lg + %Lg I) ~= %Lg + %Lg I\n", #func,      \
110             creall(_d), cimagl(_d), creall(result), cimagl(result));    \
111         assert(cfpequal_tol((func)(_d), (result), (tol)));              \
112 } while (0)
113
114 /* These wrappers apply the identities f(conj(z)) = conj(f(z)). */
115 #define test(func, z, result, exceptmask, excepts, checksign)   do {    \
116         test_p(func, z, result, exceptmask, excepts, checksign);        \
117         test_p(func, conjl(z), conjl(result), exceptmask, excepts, checksign); \
118 } while (0)
119 #define test_tol(func, z, result, tol)                          do {    \
120         test_p_tol(func, z, result, tol);                               \
121         test_p_tol(func, conjl(z), conjl(result), tol);                 \
122 } while (0)
123
124 /* Test the given function in all precisions. */
125 #define testall(func, x, result, exceptmask, excepts, checksign) do {   \
126         test(func, x, result, exceptmask, excepts, checksign);          \
127         test(func##f, x, result, exceptmask, excepts, checksign);       \
128 } while (0)
129 #define testall_odd(func, x, result, exceptmask, excepts, checksign) do { \
130         testall(func, x, result, exceptmask, excepts, checksign);       \
131         testall(func, -x, -result, exceptmask, excepts, checksign);     \
132 } while (0)
133 #define testall_even(func, x, result, exceptmask, excepts, checksign) do { \
134         testall(func, x, result, exceptmask, excepts, checksign);       \
135         testall(func, -x, result, exceptmask, excepts, checksign);      \
136 } while (0)
137
138 /*
139  * Test the given function in all precisions, within a given tolerance.
140  * The tolerance is specified in ulps.
141  */
142 #define testall_tol(func, x, result, tol)                          do { \
143         test_tol(func, x, result, tol * DBL_ULP());                     \
144         test_tol(func##f, x, result, tol * FLT_ULP());                  \
145 } while (0)
146 #define testall_odd_tol(func, x, result, tol)                      do { \
147         test_tol(func, x, result, tol * DBL_ULP());                     \
148         test_tol(func, -x, -result, tol * DBL_ULP());                   \
149 } while (0)
150 #define testall_even_tol(func, x, result, tol)                     do { \
151         test_tol(func, x, result, tol * DBL_ULP());                     \
152         test_tol(func, -x, result, tol * DBL_ULP());                    \
153 } while (0)
154
155 /*
156  * Determine whether x and y are equal, with two special rules:
157  *      +0.0 != -0.0
158  *       NaN == NaN
159  * If checksign is 0, we compare the absolute values instead.
160  */
161 static int
162 fpequal(long double x, long double y, int checksign)
163 {
164         if (isnan(x) && isnan(y))
165                 return (1);
166         if (checksign)
167                 return (x == y && !signbit(x) == !signbit(y));
168         else
169                 return (fabsl(x) == fabsl(y));
170 }
171
172 static int
173 fpequal_tol(long double x, long double y, long double tol)
174 {
175         fenv_t env;
176         int ret;
177
178         if (isnan(x) && isnan(y))
179                 return (1);
180         if (!signbit(x) != !signbit(y) && tol == 0)
181                 return (0);
182         if (x == y)
183                 return (1);
184         if (tol == 0)
185                 return (0);
186
187         /* Hard case: need to check the tolerance. */
188         feholdexcept(&env);
189         /*
190          * For our purposes here, if y=0, we interpret tol as an absolute
191          * tolerance. This is to account for roundoff in the input, e.g.,
192          * cos(Pi/2) ~= 0.
193          */
194         if (y == 0.0)
195                 ret = fabsl(x - y) <= fabsl(tol);
196         else
197                 ret = fabsl(x - y) <= fabsl(y * tol);
198         fesetenv(&env);
199         return (ret);
200 }
201
202 static int
203 cfpequal(long double complex x, long double complex y, int checksign)
204 {
205         return (fpequal(creal(x), creal(y), checksign & CS_REAL)
206                 && fpequal(cimag(x), cimag(y), checksign & CS_IMAG));
207 }
208
209 static int
210 cfpequal_tol(long double complex x, long double complex y, long double tol)
211 {
212         return (fpequal_tol(creal(x), creal(y), tol)
213                 && fpequal_tol(cimag(x), cimag(y), tol));
214 }
215
216
217 /* Tests for 0 */
218 void
219 test_zero(void)
220 {
221         long double complex zero = cpackl(0.0, 0.0);
222
223         /* csinh(0) = ctanh(0) = 0; ccosh(0) = 1 (no exceptions raised) */
224         testall_odd(csinh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
225         testall_odd(csin, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
226         testall_even(ccosh, zero, 1.0, ALL_STD_EXCEPT, 0, CS_BOTH);
227         testall_even(ccos, zero, cpackl(1.0, -0.0), ALL_STD_EXCEPT, 0, CS_BOTH);
228         testall_odd(ctanh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
229         testall_odd(ctan, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
230 }
231
232 /*
233  * Tests for NaN inputs.
234  */
235 void
236 test_nan()
237 {
238         long double complex nan_nan = cpackl(NAN, NAN);
239         long double complex z;
240
241         /*
242          * IN           CSINH           CCOSH           CTANH
243          * NaN,NaN      NaN,NaN         NaN,NaN         NaN,NaN
244          * finite,NaN   NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
245          * NaN,finite   NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
246          * NaN,Inf      NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
247          * Inf,NaN      +-Inf,NaN       Inf,NaN         1,+-0
248          * 0,NaN        +-0,NaN         NaN,+-0         NaN,NaN [inval]
249          * NaN,0        NaN,0           NaN,+-0         NaN,0
250          */
251         z = nan_nan;
252         testall_odd(csinh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
253         testall_even(ccosh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
254         testall_odd(ctanh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
255         testall_odd(csin, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
256         testall_even(ccos, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
257         testall_odd(ctan, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
258
259         z = cpackl(42, NAN);
260         testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
261         testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
262         /* XXX We allow a spurious inexact exception here. */
263         testall_odd(ctanh, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
264         testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
265         testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
266         testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
267
268         z = cpackl(NAN, 42);
269         testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
270         testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
271         testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
272         testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
273         testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
274         /* XXX We allow a spurious inexact exception here. */
275         testall_odd(ctan, z, nan_nan, OPT_INVALID & ~FE_INEXACT, 0, 0);
276
277         z = cpackl(NAN, INFINITY);
278         testall_odd(csinh, z, nan_nan, OPT_INVALID, 0, 0);
279         testall_even(ccosh, z, nan_nan, OPT_INVALID, 0, 0);
280         testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
281         testall_odd(csin, z, cpackl(NAN, INFINITY), ALL_STD_EXCEPT, 0, 0);
282         testall_even(ccos, z, cpackl(INFINITY, NAN), ALL_STD_EXCEPT, 0,
283             CS_IMAG);
284         testall_odd(ctan, z, cpackl(0, 1), ALL_STD_EXCEPT, 0, CS_IMAG);
285
286         z = cpackl(INFINITY, NAN);
287         testall_odd(csinh, z, cpackl(INFINITY, NAN), ALL_STD_EXCEPT, 0, 0);
288         testall_even(ccosh, z, cpackl(INFINITY, NAN), ALL_STD_EXCEPT, 0,
289                      CS_REAL);
290         testall_odd(ctanh, z, cpackl(1, 0), ALL_STD_EXCEPT, 0, CS_REAL);
291         testall_odd(csin, z, nan_nan, OPT_INVALID, 0, 0);
292         testall_even(ccos, z, nan_nan, OPT_INVALID, 0, 0);
293         testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
294
295         z = cpackl(0, NAN);
296         testall_odd(csinh, z, cpackl(0, NAN), ALL_STD_EXCEPT, 0, 0);
297         testall_even(ccosh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
298         testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
299         testall_odd(csin, z, cpackl(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
300         testall_even(ccos, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
301         testall_odd(ctan, z, cpackl(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
302
303         z = cpackl(NAN, 0);
304         testall_odd(csinh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
305         testall_even(ccosh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
306         testall_odd(ctanh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
307         testall_odd(csin, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
308         testall_even(ccos, z, cpackl(NAN, 0), ALL_STD_EXCEPT, 0, 0);
309         testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
310 }
311
312 void
313 test_inf(void)
314 {
315         static const long double finites[] = {
316             0, M_PI / 4, 3 * M_PI / 4, 5 * M_PI / 4,
317         };
318         long double complex z, c, s;
319         int i;
320
321         /*
322          * IN           CSINH           CCOSH           CTANH
323          * Inf,Inf      +-Inf,NaN inval +-Inf,NaN inval 1,+-0
324          * Inf,finite   Inf cis(finite) Inf cis(finite) 1,0 sin(2 finite)
325          * 0,Inf        +-0,NaN inval   NaN,+-0 inval   NaN,NaN inval
326          * finite,Inf   NaN,NaN inval   NaN,NaN inval   NaN,NaN inval
327          */
328         z = cpackl(INFINITY, INFINITY);
329         testall_odd(csinh, z, cpackl(INFINITY, NAN),
330                     ALL_STD_EXCEPT, FE_INVALID, 0);
331         testall_even(ccosh, z, cpackl(INFINITY, NAN),
332                      ALL_STD_EXCEPT, FE_INVALID, 0);
333         testall_odd(ctanh, z, cpackl(1, 0), ALL_STD_EXCEPT, 0, CS_REAL);
334         testall_odd(csin, z, cpackl(NAN, INFINITY),
335                     ALL_STD_EXCEPT, FE_INVALID, 0);
336         testall_even(ccos, z, cpackl(INFINITY, NAN),
337                      ALL_STD_EXCEPT, FE_INVALID, 0);
338         testall_odd(ctan, z, cpackl(0, 1), ALL_STD_EXCEPT, 0, CS_REAL);
339
340         /* XXX We allow spurious inexact exceptions here (hard to avoid). */
341         for (i = 0; i < sizeof(finites) / sizeof(finites[0]); i++) {
342                 z = cpackl(INFINITY, finites[i]);
343                 c = INFINITY * cosl(finites[i]);
344                 s = finites[i] == 0 ? finites[i] : INFINITY * sinl(finites[i]);
345                 testall_odd(csinh, z, cpackl(c, s), OPT_INEXACT, 0, CS_BOTH);
346                 testall_even(ccosh, z, cpackl(c, s), OPT_INEXACT, 0, CS_BOTH);
347                 testall_odd(ctanh, z, cpackl(1, 0 * sin(finites[i] * 2)),
348                             OPT_INEXACT, 0, CS_BOTH);
349                 z = cpackl(finites[i], INFINITY);
350                 testall_odd(csin, z, cpackl(s, c), OPT_INEXACT, 0, CS_BOTH);
351                 testall_even(ccos, z, cpackl(c, -s), OPT_INEXACT, 0, CS_BOTH);
352                 testall_odd(ctan, z, cpackl(0 * sin(finites[i] * 2), 1),
353                             OPT_INEXACT, 0, CS_BOTH);
354         }
355
356         z = cpackl(0, INFINITY);
357         testall_odd(csinh, z, cpackl(0, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
358         testall_even(ccosh, z, cpackl(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
359         testall_odd(ctanh, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
360         z = cpackl(INFINITY, 0);
361         testall_odd(csin, z, cpackl(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
362         testall_even(ccos, z, cpackl(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
363         testall_odd(ctan, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
364
365         z = cpackl(42, INFINITY);
366         testall_odd(csinh, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
367         testall_even(ccosh, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
368         /* XXX We allow a spurious inexact exception here. */
369         testall_odd(ctanh, z, cpackl(NAN, NAN), OPT_INEXACT, FE_INVALID, 0);
370         z = cpackl(INFINITY, 42);
371         testall_odd(csin, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
372         testall_even(ccos, z, cpackl(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
373         /* XXX We allow a spurious inexact exception here. */
374         testall_odd(ctan, z, cpackl(NAN, NAN), OPT_INEXACT, FE_INVALID, 0);
375 }
376
377 /* Tests along the real and imaginary axes. */
378 void
379 test_axes(void)
380 {
381         static const long double nums[] = {
382             M_PI / 4, M_PI / 2, 3 * M_PI / 4,
383             5 * M_PI / 4, 3 * M_PI / 2, 7 * M_PI / 4,
384         };
385         long double complex z;
386         int i;
387
388         for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) {
389                 /* Real axis */
390                 z = cpackl(nums[i], 0.0);
391                 testall_odd_tol(csinh, z, cpackl(sinh(nums[i]), 0), 0);
392                 testall_even_tol(ccosh, z, cpackl(cosh(nums[i]), 0), 0);
393                 testall_odd_tol(ctanh, z, cpackl(tanh(nums[i]), 0), 1);
394                 testall_odd_tol(csin, z, cpackl(sin(nums[i]),
395                                             copysign(0, cos(nums[i]))), 0);
396                 testall_even_tol(ccos, z, cpackl(cos(nums[i]),
397                     -copysign(0, sin(nums[i]))), 0);
398                 testall_odd_tol(ctan, z, cpackl(tan(nums[i]), 0), 1);
399
400                 /* Imaginary axis */
401                 z = cpackl(0.0, nums[i]);
402                 testall_odd_tol(csinh, z, cpackl(copysign(0, cos(nums[i])),
403                                                  sin(nums[i])), 0);
404                 testall_even_tol(ccosh, z, cpackl(cos(nums[i]),
405                     copysign(0, sin(nums[i]))), 0);
406                 testall_odd_tol(ctanh, z, cpackl(0, tan(nums[i])), 1);
407                 testall_odd_tol(csin, z, cpackl(0, sinh(nums[i])), 0);
408                 testall_even_tol(ccos, z, cpackl(cosh(nums[i]), -0.0), 0);
409                 testall_odd_tol(ctan, z, cpackl(0, tanh(nums[i])), 1);
410         }
411 }
412
413 void
414 test_small(void)
415 {
416         /*
417          * z =  0.5 + i Pi/4
418          *     sinh(z) = (sinh(0.5) + i cosh(0.5)) * sqrt(2)/2
419          *     cosh(z) = (cosh(0.5) + i sinh(0.5)) * sqrt(2)/2
420          *     tanh(z) = (2cosh(0.5)sinh(0.5) + i) / (2 cosh(0.5)**2 - 1)
421          * z = -0.5 + i Pi/2
422          *     sinh(z) = cosh(0.5)
423          *     cosh(z) = -i sinh(0.5)
424          *     tanh(z) = -coth(0.5)
425          * z =  1.0 + i 3Pi/4
426          *     sinh(z) = (-sinh(1) + i cosh(1)) * sqrt(2)/2
427          *     cosh(z) = (-cosh(1) + i sinh(1)) * sqrt(2)/2
428          *     tanh(z) = (2cosh(1)sinh(1) - i) / (2cosh(1)**2 - 1)
429          */
430         static const struct {
431                 long double a, b;
432                 long double sinh_a, sinh_b;
433                 long double cosh_a, cosh_b;
434                 long double tanh_a, tanh_b;
435         } tests[] = {
436                 {  0.5L,
437                    0.78539816339744830961566084581987572L,
438                    0.36847002415910435172083660522240710L,
439                    0.79735196663945774996093142586179334L,
440                    0.79735196663945774996093142586179334L,
441                    0.36847002415910435172083660522240710L,
442                    0.76159415595576488811945828260479359L,
443                    0.64805427366388539957497735322615032L },
444                 { -0.5L,
445                    1.57079632679489661923132169163975144L,
446                    0.0L,
447                    1.12762596520638078522622516140267201L,
448                    0.0L,
449                   -0.52109530549374736162242562641149156L,
450                   -2.16395341373865284877000401021802312L,
451                    0.0L },
452                 {  1.0L,
453                    2.35619449019234492884698253745962716L,
454                   -0.83099273328405698212637979852748608L,
455                    1.09112278079550143030545602018565236L,
456                   -1.09112278079550143030545602018565236L,
457                    0.83099273328405698212637979852748609L,
458                    0.96402758007581688394641372410092315L,
459                   -0.26580222883407969212086273981988897L }
460         };
461         long double complex z;
462         int i;
463
464         for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
465                 z = cpackl(tests[i].a, tests[i].b);
466                 testall_odd_tol(csinh, z,
467                     cpackl(tests[i].sinh_a, tests[i].sinh_b), 1.1);
468                 testall_even_tol(ccosh, z,
469                     cpackl(tests[i].cosh_a, tests[i].cosh_b), 1.1);
470                 testall_odd_tol(ctanh, z,
471                     cpackl(tests[i].tanh_a, tests[i].tanh_b), 1.1);
472         }
473 }
474
475 /* Test inputs that might cause overflow in a sloppy implementation. */
476 void
477 test_large(void)
478 {
479         long double complex z;
480
481         /* tanh() uses a threshold around x=22, so check both sides. */
482         z = cpackl(21, 0.78539816339744830961566084581987572L);
483         testall_odd_tol(ctanh, z,
484             cpackl(1.0, 1.14990445285871196133287617611468468e-18L), 1);
485         z++;
486         testall_odd_tol(ctanh, z,
487             cpackl(1.0, 1.55622644822675930314266334585597964e-19L), 1);
488
489         z = cpackl(355, 0.78539816339744830961566084581987572L);
490         testall_odd_tol(ctanh, z,
491             cpackl(1.0, 8.95257245135025991216632140458264468e-309L), 1);
492         z = cpackl(30, 0x1p1023L);
493         testall_odd_tol(ctanh, z,
494             cpackl(1.0, -1.62994325413993477997492170229268382e-26L), 1);
495         z = cpackl(1, 0x1p1023L);
496         testall_odd_tol(ctanh, z,
497             cpackl(0.878606311888306869546254022621986509L,
498                    -0.225462792499754505792678258169527424L), 1);
499
500         z = cpackl(710.6, 0.78539816339744830961566084581987572L);
501         testall_odd_tol(csinh, z,
502             cpackl(1.43917579766621073533185387499658944e308L,
503                    1.43917579766621073533185387499658944e308L), 1);
504         testall_even_tol(ccosh, z,
505             cpackl(1.43917579766621073533185387499658944e308L,
506                    1.43917579766621073533185387499658944e308L), 1);
507
508         z = cpackl(1500, 0.78539816339744830961566084581987572L);
509         testall_odd(csinh, z, cpackl(INFINITY, INFINITY), OPT_INEXACT,
510             FE_OVERFLOW, CS_BOTH);
511         testall_even(ccosh, z, cpackl(INFINITY, INFINITY), OPT_INEXACT,
512             FE_OVERFLOW, CS_BOTH);
513 }
514
515 int
516 main(int argc, char *argv[])
517 {
518
519         printf("1..6\n");
520
521         test_zero();
522         printf("ok 1 - ctrig zero\n");
523
524         test_nan();
525         printf("ok 2 - ctrig nan\n");
526
527         test_inf();
528         printf("ok 3 - ctrig inf\n");
529
530         test_axes();
531         printf("ok 4 - ctrig axes\n");
532
533         test_small();
534         printf("ok 5 - ctrig small\n");
535
536         test_large();
537         printf("ok 6 - ctrig large\n");
538
539         return (0);
540 }