Update.
[jlayton/glibc.git] / math / libm-test.c
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Andreas Jaeger <aj@arthur.pfalz.de>, 1997.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
19
20
21 /*
22    Part of testsuite for libm.
23
24    This file has to be included by a master file that defines:
25
26    Makros:
27    FUNC(function): converts general function name (like cos) to
28    name with correct suffix (e.g. cosl or cosf)
29    MATHCONST(x):   like FUNC but for constants (e.g convert 0.0 to 0.0L)
30    MATHTYPE:       floating point type to test
31    TEST_MSG:       informal message to be displayed
32    CHOOSE(Clongdouble,Cdouble,Cfloat):
33    chooses one of the parameters as epsilon for testing
34    equality
35    PRINTF_EXPR     Floating point conversion specification to print a variable
36    of type MATHTYPE with printf. PRINTF_EXPR just contains
37    the specifier, not the percent and width arguments,
38    e.g. "f"
39  */
40
41 /* This program isn't finished yet.
42    It has tests for acos, acosh, asin, asinh, atan, atan2, atanh,
43    cbrt, ceil, copysign, cos, cosh, exp, exp2, expm1,
44    fabs, fdim, floor, fmin, fmax, fpclassify,
45    frexp, hypot, ilogb, ldexp,
46    log, log10, log1p, log2, logb, modf, nextafter,
47    pow, scalb, scalbn, sin, sinh, sqrt, tan, tanh, trunc.
48    Tests for the other libm-functions will come later.
49
50    The routines using random variables are still under construction. I don't
51    like it the way it's working now and will change it.
52
53    Exception handling has not been implemented so far so don't get fooled
54    that these tests pass.
55
56    Parameter handling is primitive in the moment:
57    --verbose=[0..3] for different levels of output:
58    0: only error count
59    1: basic report on failed tests
60    2: full report on failed tests
61    3: full report on failed and passed tests (default)
62    -v for full output (equals --verbose=3)
63    -s,--silent outputs only the error count (equals --verbose=0)
64  */
65
66 #ifndef _GNU_SOURCE
67 # define _GNU_SOURCE
68 #endif
69
70 #include <complex.h>
71 #include <math.h>
72 #include <float.h>
73 #include <fenv.h>
74
75 #include <errno.h>
76 #include <stdlib.h>
77 #include <stdio.h>
78 #include <time.h>
79 #include <getopt.h>
80
81 /* TEST_EXCEPTION: tests if an exception as occured */
82 /* for the moment: does nothing */
83 /* Possible exceptions */
84 #define NO_EXCEPTION             0x0
85 #define INVALID_EXCEPTION        0x1
86 #define DIVIDE_BY_ZERO_EXCEPTION 0x2
87
88 #define PRINT 1
89 #define NO_PRINT 0
90
91
92 static int noErrors;
93
94 static int verbose = 3;
95 static MATHTYPE minus_zero, plus_zero;
96 static MATHTYPE plus_infty, minus_infty, nan_value;
97
98 typedef MATHTYPE (*mathfunc) (MATHTYPE);
99
100 #define BUILD_COMPLEX(real, imag) \
101   ({ __complex__ MATHTYPE __retval;                                           \
102      __real__ __retval = (real);                                              \
103      __imag__ __retval = (imag);                                              \
104      __retval; })
105
106
107 #define ISINF(x) \
108 (sizeof (x) == sizeof (float) ?                                               \
109  isinff (x)                                                                   \
110  : sizeof (x) == sizeof (double) ?                                            \
111  isinf (x) : isinfl (x))
112
113
114      /*
115         Test if Floating-Point stack hasn't changed
116       */
117 static void
118 fpstack_test (const char *test_name)
119 {
120 #ifdef i386
121   static int old_stack;
122   int sw;
123 asm ("fnstsw":"=a" (sw));
124   sw >>= 11;
125   sw &= 7;
126   if (sw != old_stack)
127     {
128       printf ("FP-Stack wrong after test %s\n", test_name);
129       if (verbose > 2)
130         printf ("=======> stack = %d\n", sw);
131       ++noErrors;
132       old_stack = sw;
133     }
134 #endif
135 }
136
137
138 /*
139    Get a random value x with min_value < x < max_value
140    and min_value, max_value finite,
141    max_value and min_value shouldn't be too close together
142  */
143 static MATHTYPE
144 random_value (MATHTYPE min_value, MATHTYPE max_value)
145 {
146   int r;
147   MATHTYPE x;
148
149   r = rand ();
150
151   x = (max_value - min_value) / RAND_MAX * (MATHTYPE) r + min_value;
152
153   if ((x <= min_value) || (x >= max_value) || !isfinite (x))
154     x = (max_value - min_value) / 2 + min_value;
155
156   /* Make sure the RNG has no influence on the exceptions.  */
157   feclearexcept (FE_ALL_EXCEPT);
158
159   return x;
160 }
161
162 /* Get a random value x with x > min_value.  */
163 static MATHTYPE
164 random_greater (MATHTYPE min_value)
165 {
166   return random_value (min_value, 1e6);         /* CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX) */
167 }
168
169 /* Get a random value x with x < max_value.  */
170 static MATHTYPE
171 random_less (MATHTYPE max_value)
172 {
173   return random_value (-1e6, max_value);
174 }
175
176
177 /* Test whether a given exception was raised.  */
178 static void
179 test_single_exception (const char *test_name,
180                        short int exception,
181                        short int exc_flag,
182                        fexcept_t fe_flag,
183                        const char *flag_name)
184 {
185   if (exception & exc_flag)
186     {
187       if (fetestexcept (fe_flag))
188         {
189           if (verbose > 2)
190             printf ("Pass: %s:\nException \"%s\" set\n", test_name, flag_name);
191         }
192       else
193         {
194           if (verbose)
195             printf ("Fail: %s:\nException \"%s\" not set\n",
196                     test_name, flag_name);
197           ++noErrors;
198         }
199     }
200   else
201     {
202       if (fetestexcept (fe_flag))
203         {
204           if (verbose)
205             printf ("Fail: %s:\nException \"%s\" set\n",
206                     test_name, flag_name);
207           ++noErrors;
208         }
209       else
210         {
211           if (verbose > 2)
212             printf ("Pass: %s:\nException \"%s\" not set\n",
213                     test_name, flag_name);
214         }
215     }
216 }
217
218
219 /* Test whether exception given by EXCEPTION are raised.  */
220 static void
221 test_not_exception (const char *test_name, short int exception)
222 {
223 #ifdef FE_DIVBYZERO
224   if ((exception & FE_DIVBYZERO) == 0)
225     test_single_exception (test_name, exception,
226                            DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
227                            "Divide by zero");
228 #endif
229 #ifdef FE_INVALID
230   if ((exception & FE_INVALID) == 0)
231     test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
232                            "Invalid operation");
233 #endif
234   feclearexcept (FE_ALL_EXCEPT);
235 }
236
237
238 /* Test whether exceptions given by EXCEPTION are raised.  */
239 static void
240 test_exceptions (const char *test_name, short int exception)
241 {
242 #ifdef FE_DIVBYZERO
243   test_single_exception (test_name, exception,
244                          DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
245                          "Divide by zero");
246 #endif
247 #ifdef FE_INVALID
248   test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
249                          "Invalid operation");
250 #endif
251   feclearexcept (FE_ALL_EXCEPT);
252 }
253
254
255 /* Test if two floating point numbers are equal.  */
256 static int
257 check_equal (MATHTYPE computed, MATHTYPE supplied, MATHTYPE eps, MATHTYPE * diff)
258 {
259   /* Both plus Infinity or both minus infinity.  */
260   if (ISINF (computed) && (ISINF (computed) == ISINF (supplied)))
261     return 1;
262
263   if (isnan (computed) && isnan (supplied))     /* isnan works for all types */
264     return 1;
265
266   *diff = FUNC(fabs) (computed - supplied);
267
268   if (*diff <= eps && (signbit (computed) == signbit (supplied) || eps != 0.0))
269     return 1;
270
271   return 0;
272 }
273
274
275 static void
276 output_result_bool (const char *test_name, int result)
277 {
278   if (result)
279     {
280       if (verbose > 2)
281         printf ("Pass: %s\n", test_name);
282     }
283   else
284     {
285       if (verbose)
286         printf ("Fail: %s\n", test_name);
287       ++noErrors;
288     }
289
290   fpstack_test (test_name);
291 }
292
293
294 static void
295 output_isvalue (const char *test_name, int result,
296                 MATHTYPE value)
297 {
298   if (result)
299     {
300       if (verbose > 2)
301         printf ("Pass: %s\n", test_name);
302     }
303   else
304     {
305       if (verbose)
306         printf ("Fail: %s\n", test_name);
307       if (verbose > 1)
308         printf (" Value: %.20" PRINTF_EXPR "\n", value);
309       noErrors++;
310     }
311
312   fpstack_test (test_name);
313 }
314
315
316 static void
317 output_isvalue_ext (const char *test_name, int result,
318                     MATHTYPE value, MATHTYPE parameter)
319 {
320   if (result)
321     {
322       if (verbose > 2)
323         printf ("Pass: %s\n", test_name);
324     }
325   else
326     {
327       if (verbose)
328         printf ("Fail: %s\n", test_name);
329       if (verbose > 1)
330         {
331           printf (" Value:     %.20" PRINTF_EXPR "\n", value);
332           printf (" Parameter: %.20" PRINTF_EXPR "\n", parameter);
333         }
334       noErrors++;
335     }
336
337   fpstack_test (test_name);
338 }
339
340
341 static void
342 output_result (const char *test_name, int result,
343                MATHTYPE computed, MATHTYPE expected,
344                MATHTYPE difference,
345                int print_values, int print_diff)
346 {
347   if (result)
348     {
349       if (verbose > 2)
350         printf ("Pass: %s\n", test_name);
351     }
352   else
353     {
354       if (verbose)
355         printf ("Fail: %s\n", test_name);
356       if (verbose > 1 && print_values)
357         {
358           printf ("Result:\n");
359           printf (" is:         %.20" PRINTF_EXPR "\n", computed);
360           printf (" should be:  %.20" PRINTF_EXPR "\n", expected);
361           if (print_diff)
362             printf (" difference: %.20" PRINTF_EXPR "\n", difference);
363         }
364       noErrors++;
365     }
366
367   fpstack_test (test_name);
368 }
369
370
371 static void
372 output_result_ext (const char *test_name, int result,
373                    MATHTYPE computed, MATHTYPE expected,
374                    MATHTYPE difference,
375                    MATHTYPE parameter,
376                    int print_values, int print_diff)
377 {
378   if (result)
379     {
380       if (verbose > 2)
381         printf ("Pass: %s\n", test_name);
382     }
383   else
384     {
385       if (verbose)
386         printf ("Fail: %s\n", test_name);
387       if (verbose > 1 && print_values)
388         {
389           printf ("Result:\n");
390           printf (" is:         %.20" PRINTF_EXPR "\n", computed);
391           printf (" should be:  %.20" PRINTF_EXPR "\n", expected);
392           if (print_diff)
393             printf (" difference: %.20" PRINTF_EXPR "\n", difference);
394           printf ("Parameter:   %.20" PRINTF_EXPR "\n", parameter);
395         }
396       noErrors++;
397     }
398
399   fpstack_test (test_name);
400 }
401
402
403 static void
404 check (const char *test_name, MATHTYPE computed, MATHTYPE expected)
405 {
406   MATHTYPE diff;
407   int result;
408
409   test_exceptions (test_name, NO_EXCEPTION);
410   result = check_equal (computed, expected, 0, &diff);
411   output_result (test_name, result,
412                  computed, expected, diff, PRINT, PRINT);
413 }
414
415
416 static void
417 check_ext (const char *test_name, MATHTYPE computed, MATHTYPE expected,
418            MATHTYPE parameter)
419 {
420   MATHTYPE diff;
421   int result;
422
423   test_exceptions (test_name, NO_EXCEPTION);
424   result = check_equal (computed, expected, 0, &diff);
425   output_result_ext (test_name, result,
426                      computed, expected, diff, parameter, PRINT, PRINT);
427 }
428
429
430 static void
431 check_exc (const char *test_name, MATHTYPE computed, MATHTYPE expected,
432            short exception)
433 {
434   MATHTYPE diff;
435   int result;
436
437   test_exceptions (test_name, exception);
438   result = check_equal (computed, expected, 0, &diff);
439   output_result (test_name, result,
440                  computed, expected, diff, PRINT, PRINT);
441 }
442
443
444 static void
445 check_eps (const char *test_name, MATHTYPE computed, MATHTYPE expected,
446            MATHTYPE epsilon)
447 {
448   MATHTYPE diff;
449   int result;
450
451   test_exceptions (test_name, NO_EXCEPTION);
452   result = check_equal (computed, expected, epsilon, &diff);
453   output_result (test_name, result,
454                  computed, expected, diff, PRINT, PRINT);
455 }
456
457
458 static void
459 check_bool (const char *test_name, int computed)
460 {
461   test_exceptions (test_name, NO_EXCEPTION);
462   output_result_bool (test_name, computed);
463 }
464
465
466 static void
467 check_long (const char *test_name, long int computed, long int expected)
468 {
469   long int diff = computed - expected;
470   int result = diff == 0;
471
472   test_exceptions (test_name, NO_EXCEPTION);
473
474   if (result)
475     {
476       if (verbose > 2)
477         printf ("Pass: %s\n", test_name);
478     }
479   else
480     {
481       if (verbose)
482         printf ("Fail: %s\n", test_name);
483       if (verbose > 1)
484         {
485           printf ("Result:\n");
486           printf (" is:         %ld\n", computed);
487           printf (" should be:  %ld\n", expected);
488         }
489       noErrors++;
490     }
491
492   fpstack_test (test_name);
493 }
494
495
496 static void
497 check_longlong (const char *test_name, long long int computed,
498                 long long int expected)
499 {
500   long long int diff = computed - expected;
501   int result = diff == 0;
502
503   test_exceptions (test_name, NO_EXCEPTION);
504
505   if (result)
506     {
507       if (verbose > 2)
508         printf ("Pass: %s\n", test_name);
509     }
510   else
511     {
512       if (verbose)
513         printf ("Fail: %s\n", test_name);
514       if (verbose > 1)
515         {
516           printf ("Result:\n");
517           printf (" is:         %lld\n", computed);
518           printf (" should be:  %lld\n", expected);
519         }
520       noErrors++;
521     }
522
523   fpstack_test (test_name);
524 }
525
526
527 static void
528 check_isnan (const char *test_name, MATHTYPE computed)
529 {
530   test_exceptions (test_name, NO_EXCEPTION);
531   output_isvalue (test_name, isnan (computed), computed);
532 }
533
534
535 static void
536 check_isnan_exc (const char *test_name, MATHTYPE computed,
537                  short exception)
538 {
539   test_exceptions (test_name, exception);
540   output_isvalue (test_name, isnan (computed), computed);
541 }
542
543
544 static void
545 check_isnan_maybe_exc (const char *test_name, MATHTYPE computed,
546                        short exception)
547 {
548   test_not_exception (test_name, exception);
549   output_isvalue (test_name, isnan (computed), computed);
550 }
551
552
553 static void
554 check_isnan_ext (const char *test_name, MATHTYPE computed,
555                  MATHTYPE parameter)
556 {
557   test_exceptions (test_name, NO_EXCEPTION);
558   output_isvalue_ext (test_name, isnan (computed), computed, parameter);
559 }
560
561
562 /* Tests if computed is +Inf */
563 static void
564 check_isinfp (const char *test_name, MATHTYPE computed)
565 {
566   test_exceptions (test_name, NO_EXCEPTION);
567   output_isvalue (test_name, (ISINF (computed) == +1), computed);
568 }
569
570
571 static void
572 check_isinfp_ext (const char *test_name, MATHTYPE computed,
573                   MATHTYPE parameter)
574 {
575   test_exceptions (test_name, NO_EXCEPTION);
576   output_isvalue_ext (test_name, (ISINF (computed) == +1), computed, parameter);
577 }
578
579
580 /* Tests if computed is +Inf */
581 static void
582 check_isinfp_exc (const char *test_name, MATHTYPE computed,
583                   int exception)
584 {
585   test_exceptions (test_name, exception);
586   output_isvalue (test_name, (ISINF (computed) == +1), computed);
587 }
588
589 /* Tests if computed is -Inf */
590 static void
591 check_isinfn (const char *test_name, MATHTYPE computed)
592 {
593   test_exceptions (test_name, NO_EXCEPTION);
594   output_isvalue (test_name, (ISINF (computed) == -1), computed);
595 }
596
597
598 static void
599 check_isinfn_ext (const char *test_name, MATHTYPE computed,
600                   MATHTYPE parameter)
601 {
602   test_exceptions (test_name, NO_EXCEPTION);
603   output_isvalue_ext (test_name, (ISINF (computed) == -1), computed, parameter);
604 }
605
606
607 /* Tests if computed is -Inf */
608 static void
609 check_isinfn_exc (const char *test_name, MATHTYPE computed,
610                   int exception)
611 {
612   test_exceptions (test_name, exception);
613   output_isvalue (test_name, (ISINF (computed) == -1), computed);
614 }
615
616
617 /****************************************************************************
618   Test for single functions of libm
619 ****************************************************************************/
620
621 static void
622 acos_test (void)
623 {
624   MATHTYPE x;
625
626   check ("acos (1) == 0", FUNC(acos) (1), 0);
627
628   x = random_greater (1);
629   check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
630                    FUNC(acos) (x),
631                    INVALID_EXCEPTION);
632 }
633
634 static void
635 acosh_test (void)
636 {
637   MATHTYPE x;
638
639   check ("acosh(1) == 0", FUNC(acosh) (1), 0);
640   check_isinfp ("acosh(+inf) == +inf", FUNC(acosh) (plus_infty));
641
642   x = random_less (1);
643   check_isnan_exc ("acosh(x) == NaN plus invalid exception if x < 1",
644                    FUNC(acosh) (x), INVALID_EXCEPTION);
645 }
646
647
648 static void
649 asin_test (void)
650 {
651   MATHTYPE x;
652   check ("asin (0) == 0", FUNC(asin) (0), 0);
653
654   x = random_greater (1);
655   check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
656                    FUNC(asin) (x),
657                    INVALID_EXCEPTION);
658 }
659
660 static void
661 asinh_test (void)
662 {
663
664   check ("asinh(+0) == +0", FUNC(asinh) (0), 0);
665   check ("asinh(-0) == -0", FUNC(asinh) (minus_zero), minus_zero);
666 }
667
668
669 static void
670 atan_test (void)
671 {
672   check ("atan (0) == 0", FUNC(atan) (0), 0);
673   check ("atan (-0) == -0", FUNC(atan) (minus_zero), minus_zero);
674
675   check ("atan (+inf) == pi/2", FUNC(atan) (plus_infty), M_PI_2);
676   check ("atan (-inf) == -pi/2", FUNC(atan) (minus_infty), -M_PI_2);
677
678 }
679
680 static void
681 atan2_test (void)
682 {
683   MATHTYPE x;
684
685   x = random_greater (0);
686   check ("atan2 (0,x) == 0 for x > 0",
687          FUNC(atan2) (0, x), 0);
688   x = random_greater (0);
689   check ("atan2 (-0,x) == -0 for x > 0",
690          FUNC(atan2) (minus_zero, x), minus_zero);
691
692   check ("atan2 (+0,+0) == +0", FUNC(atan2) (0, 0), 0);
693   check ("atan2 (-0,+0) == -0", FUNC(atan2) (minus_zero, 0), minus_zero);
694
695   x = -random_greater (0);
696   check ("atan2 (+0,x) == +pi for x < 0", FUNC(atan2) (0, x), M_PI);
697
698   x = -random_greater (0);
699   check ("atan2 (-0,x) == -pi for x < 0", FUNC(atan2) (minus_zero, x), -M_PI);
700
701   check ("atan2 (+0,-0) == +pi", FUNC(atan2) (0, minus_zero), M_PI);
702   check ("atan2 (-0,-0) == -pi", FUNC(atan2) (minus_zero, minus_zero), -M_PI);
703
704   x = random_greater (0);
705   check ("atan2 (y,+0) == pi/2 for y > 0", FUNC(atan2) (x, 0), M_PI_2);
706
707   x = random_greater (0);
708   check ("atan2 (y,-0) == pi/2 for y > 0", FUNC(atan2) (x, minus_zero), M_PI_2);
709
710   x = random_greater (0);
711   check ("atan2 (y,-inf) == +pi for finite y > 0",
712          FUNC(atan2) (x, minus_infty), M_PI);
713
714   x = -random_greater (0);
715   check ("atan2 (y,-inf) == -pi for finite y < 0",
716          FUNC(atan2) (x, minus_infty), -M_PI);
717
718   check ("atan2 (+inf,+inf) == +pi/4",
719          FUNC(atan2) (plus_infty, plus_infty), M_PI_4);
720
721   check ("atan2 (-inf,+inf) == -pi/4",
722          FUNC(atan2) (minus_infty, plus_infty), -M_PI_4);
723
724   check ("atan2 (+inf,-inf) == +3*pi/4",
725          FUNC(atan2) (plus_infty, minus_infty), 3 * M_PI_4);
726
727   check ("atan2 (-inf,-inf) == -3*pi/4",
728          FUNC(atan2) (minus_infty, minus_infty), -3 * M_PI_4);
729 }
730
731
732 static void
733 atanh_test (void)
734 {
735
736   check ("atanh(+0) == +0", FUNC(atanh) (0), 0);
737   check ("atanh(-0) == -0", FUNC(atanh) (minus_zero), minus_zero);
738   check_isinfp_exc ("atanh(+1) == +inf plus divide-by-zero exception",
739                     FUNC(atanh) (1), DIVIDE_BY_ZERO_EXCEPTION);
740   check_isinfn_exc ("atanh(-1) == -inf plus divide-by-zero exception",
741                     FUNC(atanh) (-1), DIVIDE_BY_ZERO_EXCEPTION);
742 }
743
744
745 static void
746 cbrt_test (void)
747 {
748   check ("cbrt (+0) == +0", FUNC(cbrt) (0.0), 0.0);
749   check ("cbrt (-0) == -0", FUNC(cbrt) (minus_zero), minus_zero);
750
751   check_isinfp ("cbrt (+inf) == +inf", FUNC(cbrt) (plus_infty));
752   check_isinfn ("cbrt (-inf) == -inf", FUNC(cbrt) (minus_infty));
753   check_isnan ("cbrt (NaN) == NaN", FUNC(cbrt) (nan_value));
754
755   check_eps ("cbrt (8) == 2", FUNC(cbrt) (8), 2, CHOOSE (5e-17L, 0, 0));
756   check_eps ("cbrt (-27) == -3", FUNC(cbrt) (-27.0), -3.0,
757              CHOOSE (3e-16L, 0, 0));
758 }
759
760
761 static void
762 ceil_test (void)
763 {
764   check ("ceil (+0) == +0", FUNC(ceil) (0.0), 0.0);
765   check ("ceil (-0) == -0", FUNC(ceil) (minus_zero), minus_zero);
766   check_isinfp ("ceil (+inf) == +inf", FUNC(ceil) (plus_infty));
767   check_isinfn ("ceil (-inf) == -inf", FUNC(ceil) (minus_infty));
768
769   check ("ceil (pi) == 4", FUNC(ceil) (M_PI), 4.0);
770   check ("ceil (-pi) == -3", FUNC(ceil) (-M_PI), -3.0);
771 }
772
773
774 static void
775 cos_test (void)
776 {
777
778   check ("cos (+0) == 1", FUNC(cos) (0), 1);
779   check ("cos (-0) == 1", FUNC(cos) (minus_zero), 1);
780   check_isnan_exc ("cos (+inf) == NaN plus invalid exception",
781                    FUNC(cos) (plus_infty),
782                    INVALID_EXCEPTION);
783   check_isnan_exc ("cos (-inf) == NaN plus invalid exception",
784                    FUNC(cos) (minus_infty),
785                    INVALID_EXCEPTION);
786
787   check_eps ("cos (pi/3) == 0.5", FUNC(cos) (M_PI / 3.0),
788              0.5, CHOOSE (4e-18L, 1e-15L, 1e-7L));
789   check_eps ("cos (pi/2) == 0", FUNC(cos) (M_PI_2),
790              0, CHOOSE (1e-19L, 1e-16L, 1e-7L));
791
792 }
793
794 static void
795 cosh_test (void)
796 {
797   check ("cosh (+0) == 1", FUNC(cosh) (0), 1);
798   check ("cosh (-0) == 1", FUNC(cosh) (minus_zero), 1);
799
800   check_isinfp ("cosh (+inf) == +inf", FUNC(cosh) (plus_infty));
801   check_isinfp ("cosh (-inf) == +inf", FUNC(cosh) (minus_infty));
802 }
803
804
805 static void
806 exp_test (void)
807 {
808   check ("exp (+0) == 1", FUNC(exp) (0), 1);
809   check ("exp (-0) == 1", FUNC(exp) (minus_zero), 1);
810
811   check_isinfp ("exp (+inf) == +inf", FUNC(exp) (plus_infty));
812   check ("exp (-inf) == 0", FUNC(exp) (minus_infty), 0);
813
814   check_eps ("exp (1) == e", FUNC(exp) (1), M_E, CHOOSE (4e-18L, 0, 0));
815 }
816
817
818 static void
819 exp2_test (void)
820 {
821   errno = 0;
822   exp2(0);
823   if (errno == ENOSYS)
824     /* Function not implemented.  */
825     return;
826
827   check ("exp2 (+0) == 1", FUNC(exp2) (0), 1);
828   check ("exp2 (-0) == 1", FUNC(exp2) (minus_zero), 1);
829
830   check_isinfp ("exp2 (+inf) == +inf", FUNC(exp2) (plus_infty));
831   check ("exp2 (-inf) == 0", FUNC(exp2) (minus_infty), 0);
832   check ("exp2 (10) == 1024", FUNC(exp2) (10), 1024);
833 }
834
835
836 static void
837 expm1_test (void)
838 {
839   check ("expm1 (+0) == 0", FUNC(expm1) (0), 0);
840   check ("expm1 (-0) == -0", FUNC(expm1) (minus_zero), minus_zero);
841
842   check_isinfp ("expm1 (+inf) == +inf", FUNC(expm1) (plus_infty));
843   check ("expm1 (-inf) == -1", FUNC(expm1) (minus_infty), -1);
844
845   check_eps ("expm1 (1) == e-1", FUNC(expm1) (1), M_E - 1.0,
846              CHOOSE (4e-18L, 0, 0));
847 }
848
849
850
851
852 static void
853 check_frexp (const char *test_name, MATHTYPE computed, MATHTYPE expected,
854              int comp_int, int exp_int)
855 {
856   MATHTYPE diff;
857   int result;
858
859   result = (check_equal (computed, expected, 0, &diff)
860             && (comp_int == exp_int));
861
862   if (result)
863     {
864       if (verbose > 2)
865         printf ("Pass: %s\n", test_name);
866     }
867   else
868     {
869       if (verbose)
870         printf ("Fail: %s\n", test_name);
871       if (verbose > 1)
872         {
873           printf ("Result:\n");
874           printf (" is:         %.20" PRINTF_EXPR " *2^%d\n", computed, comp_int);
875           printf (" should be:  %.20" PRINTF_EXPR " *2^%d\n", expected, exp_int);
876           printf (" difference: %.20" PRINTF_EXPR "\n", diff);
877         }
878       noErrors++;
879     }
880   fpstack_test (test_name);
881   output_result (test_name, result,
882                  computed, expected, diff, PRINT, PRINT);
883 }
884
885
886 static void
887 frexp_test (void)
888 {
889   int x_int;
890   MATHTYPE result;
891
892   result = FUNC(frexp) (plus_infty, &x_int);
893   check_isinfp ("frexp (+inf, expr) == +inf", result);
894
895   result = FUNC(frexp) (minus_infty, &x_int);
896   check_isinfn ("frexp (-inf, expr) == -inf", result);
897
898   result = FUNC(frexp) (nan_value, &x_int);
899   check_isnan ("frexp (Nan, expr) == NaN", result);
900
901   result = FUNC(frexp) (0, &x_int);
902   check_frexp ("frexp: +0 == 0 * 2^0", result, 0, x_int, 0);
903
904   result = FUNC(frexp) (minus_zero, &x_int);
905   check_frexp ("frexp: -0 == -0 * 2^0", result, minus_zero, x_int, 0);
906
907   result = FUNC(frexp) (12.8L, &x_int);
908   check_frexp ("frexp: 12.8 == 0.8 * 2^4", result, 0.8L, x_int, 4);
909
910   result = FUNC(frexp) (-27.34L, &x_int);
911   check_frexp ("frexp: -27.34 == -0.854375 * 2^5", result, -0.854375L, x_int, 5);
912
913 }
914
915
916 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)
917 /* All floating-point numbers can be put in one of these categories.  */
918 enum
919 {
920   FP_NAN,
921 #define FP_NAN FP_NAN
922   FP_INFINITE,
923 #define FP_INFINITE FP_INFINITE
924   FP_ZERO,
925 #define FP_ZERO FP_ZERO
926   FP_SUBNORMAL,
927 #define FP_SUBNORMAL FP_SUBNORMAL
928   FP_NORMAL
929 #define FP_NORMAL FP_NORMAL
930 };
931 #endif
932
933
934 static void
935 fpclassify_test (void)
936 {
937   MATHTYPE x;
938
939   /* fpclassify is a macro, don't give it constants as parameter */
940   check_bool ("fpclassify (NaN) == FP_NAN", fpclassify (nan_value) == FP_NAN);
941   check_bool ("fpclassify (+inf) == FP_INFINITE",
942               fpclassify (plus_infty) == FP_INFINITE);
943   check_bool ("fpclassify (-inf) == FP_INFINITE",
944               fpclassify (minus_infty) == FP_INFINITE);
945   check_bool ("fpclassify (+0) == FP_ZERO",
946               fpclassify (plus_zero) == FP_ZERO);
947   check_bool ("fpclassify (-0) == FP_ZERO",
948               fpclassify (minus_zero) == FP_ZERO);
949
950   x = 1000.0;
951   check_bool ("fpclassify (1000) == FP_NORMAL",
952               fpclassify (x) == FP_NORMAL);
953 }
954
955
956 static void
957 ilogb_test (void)
958 {
959
960   /* XXX Are these tests correct? I couldn't find any specification */
961 #if 0
962   /* the source suggests that the following calls should fail -
963      but shall we test these special cases or just ignore them? */
964   check_isinfp ("ilogb (+inf) == +inf", FUNC(ilogb) (plus_infty));
965   check_isinfp ("ilogb (-inf) == +inf", FUNC(ilogb) (minus_infty));
966
967   check_isinfn_exc ("ilogb (+0) == -inf plus divide-by-zero exception",
968                     FUNC(ilogb) (0), DIVIDE_BY_ZERO_EXCEPTION);
969
970   check_isinfn_exc ("ilogb (-0) == -inf plus divide-by-zero exception",
971                     FUNC(ilogb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
972 #endif
973   check ("ilogb (1) == 0", FUNC(ilogb) (1), 0);
974   check ("ilogb (e) == 1", FUNC(ilogb) (M_E), 1);
975   check ("ilogb (1024) == 10", FUNC(ilogb) (1024), 10);
976   check ("ilogb (-2000) == 10", FUNC(ilogb) (-2000), 10);
977
978 }
979
980
981 static void
982 ldexp_test (void)
983 {
984   MATHTYPE x;
985
986   check ("ldexp (0, 0) == 0", FUNC(ldexp) (0, 0), 0);
987
988   check_isinfp ("ldexp (+inf, 1) == +inf", FUNC(ldexp) (plus_infty, 1));
989   check_isinfn ("ldexp (-inf, 1) == -inf", FUNC(ldexp) (minus_infty, 1));
990   check_isnan ("ldexp (NaN, 1) == NaN", FUNC(ldexp) (nan_value, 1));
991
992   check ("ldexp (0.8, 4) == 12.8", FUNC(ldexp) (0.8L, 4), 12.8L);
993   check ("ldexp (-0.854375, 5) == -27.34", FUNC(ldexp) (-0.854375L, 5), -27.34L);
994
995   x = random_greater (0.0);
996   check_ext ("ldexp (x, 0) == x", FUNC(ldexp) (x, 0L), x, x);
997
998 }
999
1000
1001 static void
1002 log_test (void)
1003 {
1004   check_isinfn_exc ("log (+0) == -inf plus divide-by-zero exception",
1005                     FUNC(log) (0), DIVIDE_BY_ZERO_EXCEPTION);
1006   check_isinfn_exc ("log (-0) == -inf plus divide-by-zero exception",
1007                     FUNC(log) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1008
1009   check ("log (1) == 0", FUNC(log) (1), 0);
1010
1011   check_isnan_exc ("log (x) == NaN plus invalid exception if x < 0",
1012                    FUNC(log) (-1), INVALID_EXCEPTION);
1013   check_isinfp ("log (+inf) == +inf", FUNC(log) (plus_infty));
1014
1015   check_eps ("log (e) == 1", FUNC(log) (M_E), 1, CHOOSE (1e-18L, 0, 9e-8L));
1016   check_eps ("log (1/e) == -1", FUNC(log) (1.0 / M_E), -1,
1017              CHOOSE (2e-18L, 0, 0));
1018   check ("log (2) == M_LN2", FUNC(log) (2), M_LN2);
1019   check_eps ("log (10) == M_LN10", FUNC(log) (10), M_LN10,
1020              CHOOSE (1e-18L, 0, 0));
1021 }
1022
1023
1024 static void
1025 log10_test (void)
1026 {
1027   check_isinfn_exc ("log10 (+0) == -inf plus divide-by-zero exception",
1028                     FUNC(log10) (0), DIVIDE_BY_ZERO_EXCEPTION);
1029   check_isinfn_exc ("log10 (-0) == -inf plus divide-by-zero exception",
1030                     FUNC(log10) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1031
1032   check ("log10 (1) == +0", FUNC(log10) (1), 0);
1033
1034   check_isnan_exc ("log10 (x) == NaN plus invalid exception if x < 0",
1035                    FUNC(log10) (-1), INVALID_EXCEPTION);
1036
1037   check_isinfp ("log10 (+inf) == +inf", FUNC(log10) (plus_infty));
1038
1039   check_eps ("log10 (0.1) == -1", FUNC(log10) (0.1L), -1,
1040              CHOOSE (1e-18L, 0, 0));
1041   check_eps ("log10 (10) == 1", FUNC(log10) (10.0), 1,
1042              CHOOSE (1e-18L, 0, 0));
1043   check_eps ("log10 (100) == 2", FUNC(log10) (100.0), 2,
1044              CHOOSE (1e-18L, 0, 0));
1045   check ("log10 (10000) == 4", FUNC(log10) (10000.0), 4);
1046   check_eps ("log10 (e) == M_LOG10E", FUNC(log10) (M_E), M_LOG10E,
1047              CHOOSE (1e-18, 0, 9e-8));
1048 }
1049
1050
1051 static void
1052 log1p_test (void)
1053 {
1054   check ("log1p (+0) == +0", FUNC(log1p) (0), 0);
1055   check ("log1p (-0) == -0", FUNC(log1p) (minus_zero), minus_zero);
1056
1057   check_isinfn_exc ("log1p (-1) == -inf plus divide-by-zero exception",
1058                     FUNC(log1p) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1059   check_isnan_exc ("log1p (x) == NaN plus invalid exception if x < -1",
1060                    FUNC(log1p) (-2), INVALID_EXCEPTION);
1061
1062   check_isinfp ("log1p (+inf) == +inf", FUNC(log1p) (plus_infty));
1063
1064   check_eps ("log1p (e-1) == 1", FUNC(log1p) (M_E - 1.0), 1,
1065              CHOOSE (1e-18L, 0, 0));
1066
1067 }
1068
1069
1070 static void
1071 log2_test (void)
1072 {
1073   check_isinfn_exc ("log2 (+0) == -inf plus divide-by-zero exception",
1074                     FUNC(log2) (0), DIVIDE_BY_ZERO_EXCEPTION);
1075   check_isinfn_exc ("log2 (-0) == -inf plus divide-by-zero exception",
1076                     FUNC(log2) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1077
1078   check ("log2 (1) == +0", FUNC(log2) (1), 0);
1079
1080   check_isnan_exc ("log2 (x) == NaN plus invalid exception if x < 0",
1081                    FUNC(log2) (-1), INVALID_EXCEPTION);
1082
1083   check_isinfp ("log2 (+inf) == +inf", FUNC(log2) (plus_infty));
1084
1085   check_eps ("log2 (e) == M_LOG2E", FUNC(log2) (M_E), M_LOG2E,
1086              CHOOSE (1e-18L, 0, 0));
1087   check ("log2 (2) == 1", FUNC(log2) (2.0), 1);
1088   check_eps ("log2 (16) == 4", FUNC(log2) (16.0), 4, CHOOSE (1e-18L, 0, 0));
1089   check ("log2 (256) == 8", FUNC(log2) (256.0), 8);
1090
1091 }
1092
1093
1094 static void
1095 logb_test (void)
1096 {
1097   check_isinfp ("logb (+inf) == +inf", FUNC(logb) (plus_infty));
1098   check_isinfp ("logb (-inf) == +inf", FUNC(logb) (minus_infty));
1099
1100   check_isinfn_exc ("logb (+0) == -inf plus divide-by-zero exception",
1101                     FUNC(logb) (0), DIVIDE_BY_ZERO_EXCEPTION);
1102
1103   check_isinfn_exc ("logb (-0) == -inf plus divide-by-zero exception",
1104                     FUNC(logb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1105
1106   check ("logb (1) == 0", FUNC(logb) (1), 0);
1107   check ("logb (e) == 1", FUNC(logb) (M_E), 1);
1108   check ("logb (1024) == 10", FUNC(logb) (1024), 10);
1109   check ("logb (-2000) == 10", FUNC(logb) (-2000), 10);
1110
1111 }
1112
1113
1114 static void
1115 modf_test (void)
1116 {
1117   MATHTYPE result, intpart;
1118
1119   result = FUNC(modf) (plus_infty, &intpart);
1120   check ("modf (+inf, &x) returns +0", result, 0);
1121   check_isinfp ("modf (+inf, &x) set x to +inf", intpart);
1122
1123   result = FUNC(modf) (minus_infty, &intpart);
1124   check ("modf (-inf, &x) returns -0", result, minus_zero);
1125   check_isinfn ("modf (-inf, &x) sets x to -inf", intpart);
1126
1127   result = FUNC(modf) (nan_value, &intpart);
1128   check_isnan ("modf (NaN, &x) returns NaN", result);
1129   check_isnan ("modf (NaN, &x) sets x to NaN", intpart);
1130
1131   result = FUNC(modf) (0, &intpart);
1132   check ("modf (0, &x) returns 0", result, 0);
1133   check ("modf (0, &x) sets x to 0", intpart, 0);
1134
1135   result = FUNC(modf) (minus_zero, &intpart);
1136   check ("modf (-0, &x) returns -0", result, minus_zero);
1137   check ("modf (-0, &x) sets x to -0", intpart, minus_zero);
1138
1139   result = FUNC(modf) (2.5, &intpart);
1140   check ("modf (2.5, &x) returns 0.5", result, 0.5);
1141   check ("modf (2.5, &x) sets x to 2", intpart, 2);
1142
1143   result = FUNC(modf) (-2.5, &intpart);
1144   check ("modf (-2.5, &x) returns -0.5", result, -0.5);
1145   check ("modf (-2.5, &x) sets x to -2", intpart, -2);
1146
1147 }
1148
1149
1150 static void
1151 scalb_test (void)
1152 {
1153   MATHTYPE x;
1154
1155   check ("scalb (0, 0) == 0", FUNC(scalb) (0, 0), 0);
1156
1157   check_isinfp ("scalb (+inf, 1) == +inf", FUNC(scalb) (plus_infty, 1));
1158   check_isinfn ("scalb (-inf, 1) == -inf", FUNC(scalb) (minus_infty, 1));
1159   check_isnan ("scalb (NaN, 1) == NaN", FUNC(scalb) (nan_value, 1));
1160
1161   check ("scalb (0.8, 4) == 12.8", FUNC(scalb) (0.8L, 4), 12.8L);
1162   check ("scalb (-0.854375, 5) == -27.34", FUNC(scalb) (-0.854375L, 5), -27.34L);
1163
1164   x = random_greater (0.0);
1165   check_ext ("scalb (x, 0) == x", FUNC(scalb) (x, 0L), x, x);
1166 }
1167
1168
1169 static void
1170 scalbn_test (void)
1171 {
1172   MATHTYPE x;
1173
1174   check ("scalbn (0, 0) == 0", FUNC(scalbn) (0, 0), 0);
1175
1176   check_isinfp ("scalbn (+inf, 1) == +inf", FUNC(scalbn) (plus_infty, 1));
1177   check_isinfn ("scalbn (-inf, 1) == -inf", FUNC(scalbn) (minus_infty, 1));
1178   check_isnan ("scalbn (NaN, 1) == NaN", FUNC(scalbn) (nan_value, 1));
1179
1180   check ("scalbn (0.8, 4) == 12.8", FUNC(scalbn) (0.8L, 4), 12.8L);
1181   check ("scalbn (-0.854375, 5) == -27.34", FUNC(scalbn) (-0.854375L, 5), -27.34L);
1182
1183   x = random_greater (0.0);
1184   check_ext ("scalbn (x, 0) == x", FUNC(scalbn) (x, 0L), x, x);
1185 }
1186
1187
1188 static void
1189 sin_test (void)
1190 {
1191   check ("sin (+0) == +0", FUNC(sin) (0), 0);
1192   check ("sin (-0) == -0", FUNC(sin) (minus_zero), minus_zero);
1193   check_isnan_exc ("sin (+inf) == NaN plus invalid exception",
1194                    FUNC(sin) (plus_infty),
1195                    INVALID_EXCEPTION);
1196   check_isnan_exc ("sin (-inf) == NaN plus invalid exception",
1197                    FUNC(sin) (minus_infty),
1198                    INVALID_EXCEPTION);
1199
1200   check_eps ("sin (pi/6) == 0.5", FUNC(sin) (M_PI / 6.0), 0.5,
1201              CHOOSE (4e-18L, 0, 0));
1202   check ("sin (pi/2) == 1", FUNC(sin) (M_PI_2), 1);
1203 }
1204
1205
1206 static void
1207 sinh_test (void)
1208 {
1209   check ("sinh (+0) == +0", FUNC(sinh) (0), 0);
1210   check ("sinh (-0) == -0", FUNC(sinh) (minus_zero), minus_zero);
1211
1212   check_isinfp ("sinh (+inf) == +inf", FUNC(sinh) (plus_infty));
1213   check_isinfn ("sinh (-inf) == -inf", FUNC(sinh) (minus_infty));
1214 }
1215
1216
1217 static void
1218 tan_test (void)
1219 {
1220   check ("tan (+0) == +0", FUNC(tan) (0), 0);
1221   check ("tan (-0) == -0", FUNC(tan) (minus_zero), minus_zero);
1222   check_isnan_exc ("tan (+inf) == NaN plus invalid exception",
1223                    FUNC(tan) (plus_infty), INVALID_EXCEPTION);
1224   check_isnan_exc ("tan (-inf) == NaN plus invalid exception",
1225                    FUNC(tan) (minus_infty), INVALID_EXCEPTION);
1226
1227   check_eps ("tan (pi/4) == 1", FUNC(tan) (M_PI_4), 1,
1228              CHOOSE (2e-18L, 1e-15L, 0));
1229 }
1230
1231
1232 static void
1233 tanh_test (void)
1234 {
1235   check ("tanh (+0) == +0", FUNC(tanh) (0), 0);
1236   check ("tanh (-0) == -0", FUNC(tanh) (minus_zero), minus_zero);
1237
1238   check ("tanh (+inf) == +1", FUNC(tanh) (plus_infty), 1);
1239   check ("tanh (-inf) == -1", FUNC(tanh) (minus_infty), -1);
1240 }
1241
1242
1243 static void
1244 fabs_test (void)
1245 {
1246   check ("fabs (+0) == +0", FUNC(fabs) (0), 0);
1247   check ("fabs (-0) == +0", FUNC(fabs) (minus_zero), 0);
1248
1249   check_isinfp ("fabs (+inf) == +inf", FUNC(fabs) (plus_infty));
1250   check_isinfp ("fabs (-inf) == +inf", FUNC(fabs) (minus_infty));
1251
1252   check ("fabs (+38) == 38", FUNC(fabs) (38.0), 38.0);
1253   check ("fabs (-e) == e", FUNC(fabs) (-M_E), M_E);
1254 }
1255
1256
1257 static void
1258 floor_test (void)
1259 {
1260   check ("floor (+0) == +0", FUNC(floor) (0.0), 0.0);
1261   check ("floor (-0) == -0", FUNC(floor) (minus_zero), minus_zero);
1262   check_isinfp ("floor (+inf) == +inf", FUNC(floor) (plus_infty));
1263   check_isinfn ("floor (-inf) == -inf", FUNC(floor) (minus_infty));
1264
1265   check ("floor (pi) == 3", FUNC(floor) (M_PI), 3.0);
1266   check ("floor (-pi) == -4", FUNC(floor) (-M_PI), -4.0);
1267 }
1268
1269
1270 static void
1271 hypot_test (void)
1272 {
1273   MATHTYPE a;
1274
1275   a = random_greater (0);
1276   check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot) (plus_infty, a), a);
1277   check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot) (minus_infty, a), a);
1278
1279   check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot) (nan_value, nan_value));
1280
1281   a = FUNC(hypot) (12.4L, 0.7L);
1282   check ("hypot (x,y) == hypot (y,x)", FUNC(hypot) (0.7L, 12.4L), a);
1283   check ("hypot (x,y) == hypot (-x,y)", FUNC(hypot) (-12.4L, 0.7L), a);
1284   check ("hypot (x,y) == hypot (-y,x)", FUNC(hypot) (-0.7L, 12.4L), a);
1285   check ("hypot (x,y) == hypot (-x,-y)", FUNC(hypot) (-12.4L, -0.7L), a);
1286   check ("hypot (x,y) == hypot (-y,-x)", FUNC(hypot) (-0.7L, -12.4L), a);
1287   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-0.7L, 0), 0.7L);
1288   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (0.7L, 0), 0.7L);
1289   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-1.0L, 0), 1.0L);
1290   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (1.0L, 0), 1.0L);
1291   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-5.7e7L, 0), 5.7e7L);
1292   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (5.7e7L, 0), 5.7e7L);
1293 }
1294
1295
1296 static void
1297 pow_test (void)
1298 {
1299   MATHTYPE x;
1300
1301   check ("pow (+0, +0) == 1", FUNC(pow) (0, 0), 1);
1302   check ("pow (+0, -0) == 1", FUNC(pow) (0, minus_zero), 1);
1303   check ("pow (-0, +0) == 1", FUNC(pow) (minus_zero, 0), 1);
1304   check ("pow (-0, -0) == 1", FUNC(pow) (minus_zero, minus_zero), 1);
1305
1306   check ("pow (+10, +0) == 1", FUNC(pow) (10, 0), 1);
1307   check ("pow (+10, -0) == 1", FUNC(pow) (10, minus_zero), 1);
1308   check ("pow (-10, +0) == 1", FUNC(pow) (-10, 0), 1);
1309   check ("pow (-10, -0) == 1", FUNC(pow) (-10, minus_zero), 1);
1310
1311   check ("pow (NaN, +0) == 1", FUNC(pow) (nan_value, 0), 1);
1312   check ("pow (NaN, -0) == 1", FUNC(pow) (nan_value, minus_zero), 1);
1313
1314   check_isinfp ("pow (+1.1, +inf) == +inf", FUNC(pow) (1.1, plus_infty));
1315   check_isinfp ("pow (+inf, +inf) == +inf", FUNC(pow) (plus_infty, plus_infty));
1316   check_isinfp ("pow (-1.1, +inf) == +inf", FUNC(pow) (-1.1, plus_infty));
1317   check_isinfp ("pow (-inf, +inf) == +inf", FUNC(pow) (minus_infty, plus_infty));
1318
1319   check ("pow (0.9, +inf) == +0", FUNC(pow) (0.9L, plus_infty), 0);
1320   check ("pow (1e-7, +inf) == +0", FUNC(pow) (1e-7L, plus_infty), 0);
1321   check ("pow (-0.9, +inf) == +0", FUNC(pow) (-0.9L, plus_infty), 0);
1322   check ("pow (-1e-7, +inf) == +0", FUNC(pow) (-1e-7L, plus_infty), 0);
1323
1324   check ("pow (+1.1, -inf) == 0", FUNC(pow) (1.1, minus_infty), 0);
1325   check ("pow (+inf, -inf) == 0", FUNC(pow) (plus_infty, minus_infty), 0);
1326   check ("pow (-1.1, -inf) == 0", FUNC(pow) (-1.1, minus_infty), 0);
1327   check ("pow (-inf, -inf) == 0", FUNC(pow) (minus_infty, minus_infty), 0);
1328
1329   check_isinfp ("pow (0.9, -inf) == +inf", FUNC(pow) (0.9L, minus_infty));
1330   check_isinfp ("pow (1e-7, -inf) == +inf", FUNC(pow) (1e-7L, minus_infty));
1331   check_isinfp ("pow (-0.9, -inf) == +inf", FUNC(pow) (-0.9L, minus_infty));
1332   check_isinfp ("pow (-1e-7, -inf) == +inf", FUNC(pow) (-1e-7L, minus_infty));
1333
1334   check_isinfp ("pow (+inf, 1e-7) == +inf", FUNC(pow) (plus_infty, 1e-7L));
1335   check_isinfp ("pow (+inf, 1) == +inf", FUNC(pow) (plus_infty, 1));
1336   check_isinfp ("pow (+inf, 1e7) == +inf", FUNC(pow) (plus_infty, 1e7L));
1337
1338   check ("pow (+inf, -1e-7) == 0", FUNC(pow) (plus_infty, -1e-7L), 0);
1339   check ("pow (+inf, -1) == 0", FUNC(pow) (plus_infty, -1), 0);
1340   check ("pow (+inf, -1e7) == 0", FUNC(pow) (plus_infty, -1e7L), 0);
1341
1342   check_isinfn ("pow (-inf, 1) == -inf", FUNC(pow) (minus_infty, 1));
1343   check_isinfn ("pow (-inf, 11) == -inf", FUNC(pow) (minus_infty, 11));
1344   check_isinfn ("pow (-inf, 1001) == -inf", FUNC(pow) (minus_infty, 1001));
1345
1346   check_isinfp ("pow (-inf, 2) == +inf", FUNC(pow) (minus_infty, 2));
1347   check_isinfp ("pow (-inf, 12) == +inf", FUNC(pow) (minus_infty, 12));
1348   check_isinfp ("pow (-inf, 1002) == +inf", FUNC(pow) (minus_infty, 1002));
1349   check_isinfp ("pow (-inf, 0.1) == +inf", FUNC(pow) (minus_infty, 0.1));
1350   check_isinfp ("pow (-inf, 1.1) == +inf", FUNC(pow) (minus_infty, 1.1));
1351   check_isinfp ("pow (-inf, 11.1) == +inf", FUNC(pow) (minus_infty, 11.1));
1352   check_isinfp ("pow (-inf, 1001.1) == +inf", FUNC(pow) (minus_infty, 1001.1));
1353
1354   check ("pow (-inf, -1) == -0", FUNC(pow) (minus_infty, -1), minus_zero);
1355   check ("pow (-inf, -11) == -0", FUNC(pow) (minus_infty, -11), minus_zero);
1356   check ("pow (-inf, -1001) == -0", FUNC(pow) (minus_infty, -1001), minus_zero);
1357
1358   check ("pow (-inf, -2) == +0", FUNC(pow) (minus_infty, -2), 0);
1359   check ("pow (-inf, -12) == +0", FUNC(pow) (minus_infty, -12), 0);
1360   check ("pow (-inf, -1002) == +0", FUNC(pow) (minus_infty, -1002), 0);
1361   check ("pow (-inf, -0.1) == +0", FUNC(pow) (minus_infty, -0.1), 0);
1362   check ("pow (-inf, -1.1) == +0", FUNC(pow) (minus_infty, -1.1), 0);
1363   check ("pow (-inf, -11.1) == +0", FUNC(pow) (minus_infty, -11.1), 0);
1364   check ("pow (-inf, -1001.1) == +0", FUNC(pow) (minus_infty, -1001.1), 0);
1365
1366   check_isnan ("pow (NaN, NaN) == NaN", FUNC(pow) (nan_value, nan_value));
1367   check_isnan ("pow (0, NaN) == NaN", FUNC(pow) (0, nan_value));
1368   check_isnan ("pow (1, NaN) == NaN", FUNC(pow) (1, nan_value));
1369   check_isnan ("pow (-1, NaN) == NaN", FUNC(pow) (-1, nan_value));
1370   check_isnan ("pow (NaN, 1) == NaN", FUNC(pow) (nan_value, 1));
1371   check_isnan ("pow (NaN, -1) == NaN", FUNC(pow) (nan_value, -1));
1372
1373   x = random_greater (0.0);
1374   check_isnan_ext ("pow (x, NaN) == NaN", FUNC(pow) (x, nan_value), x);
1375
1376   check_isnan_exc ("pow (+1, +inf) == NaN plus invalid exception",
1377                    FUNC(pow) (1, plus_infty), INVALID_EXCEPTION);
1378   check_isnan_exc ("pow (-1, +inf) == NaN plus invalid exception",
1379                    FUNC(pow) (-1, plus_infty), INVALID_EXCEPTION);
1380   check_isnan_exc ("pow (+1, -inf) == NaN plus invalid exception",
1381                    FUNC(pow) (1, minus_infty), INVALID_EXCEPTION);
1382   check_isnan_exc ("pow (-1, -inf) == NaN plus invalid exception",
1383                    FUNC(pow) (-1, minus_infty), INVALID_EXCEPTION);
1384
1385   check_isnan_exc ("pow (-0.1, 1.1) == NaN plus invalid exception",
1386                    FUNC(pow) (-0.1, 1.1), INVALID_EXCEPTION);
1387   check_isnan_exc ("pow (-0.1, -1.1) == NaN plus invalid exception",
1388                    FUNC(pow) (-0.1, -1.1), INVALID_EXCEPTION);
1389   check_isnan_exc ("pow (-10.1, 1.1) == NaN plus invalid exception",
1390                    FUNC(pow) (-10.1, 1.1), INVALID_EXCEPTION);
1391   check_isnan_exc ("pow (-10.1, -1.1) == NaN plus invalid exception",
1392                    FUNC(pow) (-10.1, -1.1), INVALID_EXCEPTION);
1393
1394   check_isinfp_exc ("pow (+0, -1) == +inf plus divide-by-zero exception",
1395                     FUNC(pow) (0, -1), DIVIDE_BY_ZERO_EXCEPTION);
1396   check_isinfp_exc ("pow (+0, -11) == +inf plus divide-by-zero exception",
1397                     FUNC(pow) (0, -11), DIVIDE_BY_ZERO_EXCEPTION);
1398   check_isinfn_exc ("pow (-0, -1) == -inf plus divide-by-zero exception",
1399                     FUNC(pow) (minus_zero, -1), DIVIDE_BY_ZERO_EXCEPTION);
1400   check_isinfn_exc ("pow (-0, -11) == -inf plus divide-by-zero exception",
1401                     FUNC(pow) (minus_zero, -11), DIVIDE_BY_ZERO_EXCEPTION);
1402
1403   check_isinfp_exc ("pow (+0, -2) == +inf plus divide-by-zero exception",
1404                     FUNC(pow) (0, -2), DIVIDE_BY_ZERO_EXCEPTION);
1405   check_isinfp_exc ("pow (+0, -11.1) == +inf plus divide-by-zero exception",
1406                     FUNC(pow) (0, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
1407   check_isinfp_exc ("pow (-0, -2) == +inf plus divide-by-zero exception",
1408                     FUNC(pow) (minus_zero, -2), DIVIDE_BY_ZERO_EXCEPTION);
1409   check_isinfp_exc ("pow (-0, -11.1) == +inf plus divide-by-zero exception",
1410                     FUNC(pow) (minus_zero, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
1411
1412   check ("pow (+0, 1) == +0", FUNC(pow) (0, 1), 0);
1413   check ("pow (+0, 11) == +0", FUNC(pow) (0, 11), 0);
1414   check ("pow (-0, 1) == -0", FUNC(pow) (minus_zero, 1), minus_zero);
1415   check ("pow (-0, 11) == -0", FUNC(pow) (minus_zero, 11), minus_zero);
1416
1417   check ("pow (+0, 2) == +0", FUNC(pow) (0, 2), 0);
1418   check ("pow (+0, 11.1) == +0", FUNC(pow) (0, 11.1), 0);
1419   check ("pow (-0, 2) == +0", FUNC(pow) (minus_zero, 2), 0);
1420   check ("pow (-0, 11.1) == +0", FUNC(pow) (minus_zero, 11.1), 0);
1421
1422   x = random_greater (1.0);
1423   check_isinfp_ext ("pow (x, +inf) == +inf for |x| > 1",
1424                     FUNC(pow) (x, plus_infty), x);
1425
1426   x = random_value (-1.0, 1.0);
1427   check_ext ("pow (x, +inf) == +0 for |x| < 1",
1428              FUNC(pow) (x, plus_infty), 0.0, x);
1429
1430   x = random_greater (1.0);
1431   check_ext ("pow (x, -inf) == +0 for |x| > 1",
1432              FUNC(pow) (x, minus_infty), 0.0, x);
1433
1434   x = random_value (-1.0, 1.0);
1435   check_isinfp_ext ("pow (x, -inf) == +inf for |x| < 1",
1436                     FUNC(pow) (x, minus_infty), x);
1437
1438   x = random_greater (0.0);
1439   check_isinfp_ext ("pow (+inf, y) == +inf for y > 0",
1440                     FUNC(pow) (plus_infty, x), x);
1441
1442   x = random_less (0.0);
1443   check_ext ("pow (+inf, y) == +0 for y < 0",
1444              FUNC(pow) (plus_infty, x), 0.0, x);
1445
1446   x = (rand () % 1000000) * 2.0 + 1;    /* Get random odd integer > 0 */
1447   check_isinfn_ext ("pow (-inf, y) == -inf for y an odd integer > 0",
1448                     FUNC(pow) (minus_infty, x), x);
1449
1450   x = ((rand () % 1000000) + 1) * 2.0;  /* Get random even integer > 1 */
1451   check_isinfp_ext ("pow (-inf, y) == +inf for y > 0 and not an odd integer",
1452                     FUNC(pow) (minus_infty, x), x);
1453
1454   x = -((rand () % 1000000) * 2.0 + 1); /* Get random odd integer < 0 */
1455   check_ext ("pow (-inf, y) == -0 for y an odd integer < 0",
1456              FUNC(pow) (minus_infty, x), minus_zero, x);
1457
1458   x = ((rand () % 1000000) + 1) * -2.0; /* Get random even integer < 0 */
1459   check_ext ("pow (-inf, y) == +0 for y < 0 and not an odd integer",
1460              FUNC(pow) (minus_infty, x), 0.0, x);
1461
1462   x = (rand () % 1000000) * 2.0 + 1;    /* Get random odd integer > 0 */
1463   check_ext ("pow (+0, y) == +0 for y an odd integer > 0",
1464              FUNC(pow) (0.0, x), 0.0, x);
1465   x = (rand () % 1000000) * 2.0 + 1;    /* Get random odd integer > 0 */
1466   check_ext ("pow (-0, y) == -0 for y an odd integer > 0",
1467              FUNC(pow) (minus_zero, x), minus_zero, x);
1468
1469   x = ((rand () % 1000000) + 1) * 2.0;  /* Get random even integer > 1 */
1470   check_ext ("pow (+0, y) == +0 for y > 0 and not an odd integer",
1471              FUNC(pow) (0.0, x), 0.0, x);
1472
1473   x = ((rand () % 1000000) + 1) * 2.0;  /* Get random even integer > 1 */
1474   check_ext ("pow (-0, y) == +0 for y > 0 and not an odd integer",
1475              FUNC(pow) (minus_zero, x), 0.0, x);
1476 }
1477
1478
1479 static void
1480 fdim_test (void)
1481 {
1482   check ("fdim (+0, +0) = +0", FUNC(fdim) (0, 0), 0);
1483   check ("fdim (9, 0) = 9", FUNC(fdim) (9, 0), 9);
1484   check ("fdim (0, 9) = 0", FUNC(fdim) (0, 9), 0);
1485   check ("fdim (-9, 0) = 9", FUNC(fdim) (-9, 0), 0);
1486   check ("fdim (0, -9) = 9", FUNC(fdim) (0, -9), 9);
1487
1488   check_isinfp ("fdim (+inf, 9) = +inf", FUNC(fdim) (plus_infty, 9));
1489   check_isinfp ("fdim (+inf, -9) = +inf", FUNC(fdim) (plus_infty, -9));
1490   check ("fdim (-inf, 9) = 0", FUNC(fdim) (minus_infty, 9), 0);
1491   check ("fdim (-inf, -9) = 0", FUNC(fdim) (minus_infty, -9), 0);
1492   check_isinfp ("fdim (+9, -inf) = +inf", FUNC(fdim) (9, minus_infty));
1493   check_isinfp ("fdim (-9, -inf) = +inf", FUNC(fdim) (-9, minus_infty));
1494   check ("fdim (9, inf) = 0", FUNC(fdim) (9, plus_infty), 0);
1495   check ("fdim (-9, inf) = 0", FUNC(fdim) (-9, plus_infty), 0);
1496
1497   check_isnan ("fdim (0, NaN) = NaN", FUNC(fdim) (0, nan_value));
1498   check_isnan ("fdim (9, NaN) = NaN", FUNC(fdim) (9, nan_value));
1499   check_isnan ("fdim (-9, NaN) = NaN", FUNC(fdim) (-9, nan_value));
1500   check_isnan ("fdim (NaN, 9) = NaN", FUNC(fdim) (nan_value, 9));
1501   check_isnan ("fdim (NaN, -9) = NaN", FUNC(fdim) (nan_value, -9));
1502   check_isnan ("fdim (+inf, NaN) = NaN", FUNC(fdim) (plus_infty, nan_value));
1503   check_isnan ("fdim (-inf, NaN) = NaN", FUNC(fdim) (minus_infty, nan_value));
1504   check_isnan ("fdim (NaN, +inf) = NaN", FUNC(fdim) (nan_value, plus_infty));
1505   check_isnan ("fdim (NaN, -inf) = NaN", FUNC(fdim) (nan_value, minus_infty));
1506   check_isnan ("fdim (NaN, NaN) = NaN", FUNC(fdim) (nan_value, nan_value));
1507 }
1508
1509
1510 static void
1511 fmin_test (void)
1512 {
1513   check ("fmin (+0, +0) = +0", FUNC(fmin) (0, 0), 0);
1514   check ("fmin (9, 0) = 0", FUNC(fmin) (9, 0), 0);
1515   check ("fmin (0, 9) = 0", FUNC(fmin) (0, 9), 0);
1516   check ("fmin (-9, 0) = -9", FUNC(fmin) (-9, 0), -9);
1517   check ("fmin (0, -9) = -9", FUNC(fmin) (0, -9), -9);
1518
1519   check ("fmin (+inf, 9) = 9", FUNC(fmin) (plus_infty, 9), 9);
1520   check ("fmin (9, +inf) = 9", FUNC(fmin) (9, plus_infty), 9);
1521   check ("fmin (+inf, -9) = -9", FUNC(fmin) (plus_infty, -9), -9);
1522   check ("fmin (-9, +inf) = -9", FUNC(fmin) (-9, plus_infty), -9);
1523   check_isinfn ("fmin (-inf, 9) = -inf", FUNC(fmin) (minus_infty, 9));
1524   check_isinfn ("fmin (-inf, -9) = -inf", FUNC(fmin) (minus_infty, -9));
1525   check_isinfn ("fmin (+9, -inf) = -inf", FUNC(fmin) (9, minus_infty));
1526   check_isinfn ("fmin (-9, -inf) = -inf", FUNC(fmin) (-9, minus_infty));
1527
1528   check ("fmin (0, NaN) = 0", FUNC(fmin) (0, nan_value), 0);
1529   check ("fmin (9, NaN) = 9", FUNC(fmin) (9, nan_value), 9);
1530   check ("fmin (-9, NaN) = 9", FUNC(fmin) (-9, nan_value), -9);
1531   check ("fmin (NaN, 0) = 0", FUNC(fmin) (nan_value, 0), 0);
1532   check ("fmin (NaN, 9) = NaN", FUNC(fmin) (nan_value, 9), 9);
1533   check ("fmin (NaN, -9) = NaN", FUNC(fmin) (nan_value, -9), -9);
1534   check_isinfp ("fmin (+inf, NaN) = +inf", FUNC(fmin) (plus_infty, nan_value));
1535   check_isinfn ("fmin (-inf, NaN) = -inf", FUNC(fmin) (minus_infty, nan_value));
1536   check_isinfp ("fmin (NaN, +inf) = +inf", FUNC(fmin) (nan_value, plus_infty));
1537   check_isinfn ("fmin (NaN, -inf) = -inf", FUNC(fmin) (nan_value, minus_infty));
1538   check_isnan ("fmin (NaN, NaN) = NaN", FUNC(fmin) (nan_value, nan_value));
1539 }
1540
1541
1542 static void
1543 fmax_test (void)
1544 {
1545   check ("fmax (+0, +0) = +0", FUNC(fmax) (0, 0), 0);
1546   check ("fmax (9, 0) = 9", FUNC(fmax) (9, 0), 9);
1547   check ("fmax (0, 9) = 9", FUNC(fmax) (0, 9), 9);
1548   check ("fmax (-9, 0) = 0", FUNC(fmax) (-9, 0), 0);
1549   check ("fmax (0, -9) = 0", FUNC(fmax) (0, -9), 0);
1550
1551   check_isinfp ("fmax (+inf, 9) = +inf", FUNC(fmax) (plus_infty, 9));
1552   check_isinfp ("fmax (9, +inf) = +inf", FUNC(fmax) (0, plus_infty));
1553   check_isinfp ("fmax (-9, +inf) = +inf", FUNC(fmax) (-9, plus_infty));
1554   check_isinfp ("fmax (+inf, -9) = +inf", FUNC(fmax) (plus_infty, -9));
1555   check ("fmax (-inf, 9) = 9", FUNC(fmax) (minus_infty, 9), 9);
1556   check ("fmax (-inf, -9) = -9", FUNC(fmax) (minus_infty, -9), -9);
1557   check ("fmax (+9, -inf) = 9", FUNC(fmax) (9, minus_infty), 9);
1558   check ("fmax (-9, -inf) = -9", FUNC(fmax) (-9, minus_infty), -9);
1559
1560   check ("fmax (0, NaN) = 0", FUNC(fmax) (0, nan_value), 0);
1561   check ("fmax (9, NaN) = 9", FUNC(fmax) (9, nan_value), 9);
1562   check ("fmax (-9, NaN) = 9", FUNC(fmax) (-9, nan_value), -9);
1563   check ("fmax (NaN, 0) = 0", FUNC(fmax) (nan_value, 0), 0);
1564   check ("fmax (NaN, 9) = NaN", FUNC(fmax) (nan_value, 9), 9);
1565   check ("fmax (NaN, -9) = NaN", FUNC(fmax) (nan_value, -9), -9);
1566   check_isinfp ("fmax (+inf, NaN) = +inf", FUNC(fmax) (plus_infty, nan_value));
1567   check_isinfn ("fmax (-inf, NaN) = -inf", FUNC(fmax) (minus_infty, nan_value));
1568   check_isinfp ("fmax (NaN, +inf) = +inf", FUNC(fmax) (nan_value, plus_infty));
1569   check_isinfn ("fmax (NaN, -inf) = -inf", FUNC(fmax) (nan_value, minus_infty));
1570   check_isnan ("fmax (NaN, NaN) = NaN", FUNC(fmax) (nan_value, nan_value));
1571 }
1572
1573
1574 static void
1575 nextafter_test (void)
1576 {
1577   MATHTYPE x;
1578
1579   check ("nextafter (+0, +0) = +0", FUNC(nextafter) (0, 0), 0);
1580   check ("nextafter (-0, +0) = +0", FUNC(nextafter) (minus_zero, 0), 0);
1581   check ("nextafter (+0, -0) = -0", FUNC(nextafter) (0, minus_zero),
1582          minus_zero);
1583   check ("nextafter (-0, -0) = -0", FUNC(nextafter) (minus_zero, minus_zero),
1584          minus_zero);
1585
1586   check ("nextafter (9, 9) = 9",  FUNC(nextafter) (9, 9), 9);
1587   check ("nextafter (-9, -9) = -9",  FUNC(nextafter) (-9, -9), -9);
1588   check_isinfp ("nextafter (+inf, +inf) = +inf",
1589                 FUNC(nextafter) (plus_infty, plus_infty));
1590   check_isinfn ("nextafter (-inf, -inf) = -inf",
1591                 FUNC(nextafter) (minus_infty, minus_infty));
1592
1593   x = rand () * 1.1;
1594   check_isnan ("nextafter (NaN, x) = NaN", FUNC(nextafter) (nan_value, x));
1595   check_isnan ("nextafter (x, NaN) = NaN", FUNC(nextafter) (x, nan_value));
1596   check_isnan ("nextafter (NaN, NaN) = NaN", FUNC(nextafter) (nan_value,
1597                                                               nan_value));
1598
1599   /* XXX We need the hexadecimal FP number representation here for further
1600      tests.  */
1601 }
1602
1603
1604 static void
1605 copysign_test (void)
1606 {
1607   check ("copysign (0, 4) = 0", FUNC(copysign) (0, 4), 0);
1608   check ("copysign (0, -4) = -0", FUNC(copysign) (0, -4), minus_zero);
1609   check ("copysign (-0, 4) = 0", FUNC(copysign) (minus_zero, 4), 0);
1610   check ("copysign (-0, -4) = -0", FUNC(copysign) (minus_zero, -4),
1611          minus_zero);
1612
1613   check_isinfp ("copysign (+inf, 0) = +inf", FUNC(copysign) (plus_infty, 0));
1614   check_isinfn ("copysign (+inf, -0) = -inf", FUNC(copysign) (plus_infty,
1615                                                               minus_zero));
1616   check_isinfp ("copysign (-inf, 0) = +inf", FUNC(copysign) (minus_infty, 0));
1617   check_isinfn ("copysign (-inf, -0) = -inf", FUNC(copysign) (minus_infty,
1618                                                               minus_zero));
1619
1620   check ("copysign (0, +inf) = 0", FUNC(copysign) (0, plus_infty), 0);
1621   check ("copysign (0, -inf) = -0", FUNC(copysign) (0, minus_zero),
1622          minus_zero);
1623   check ("copysign (-0, +inf) = 0", FUNC(copysign) (minus_zero, plus_infty),
1624          0);
1625   check ("copysign (-0, -inf) = -0", FUNC(copysign) (minus_zero, minus_zero),
1626          minus_zero);
1627
1628   /* XXX More correctly we would have to check the sign of the NaN.  */
1629   check_isnan ("copysign (+NaN, 0) = +NaN", FUNC(copysign) (nan_value, 0));
1630   check_isnan ("copysign (+NaN, -0) = -NaN", FUNC(copysign) (nan_value,
1631                                                              minus_zero));
1632   check_isnan ("copysign (-NaN, 0) = +NaN", FUNC(copysign) (-nan_value, 0));
1633   check_isnan ("copysign (-NaN, -0) = -NaN", FUNC(copysign) (-nan_value,
1634                                                              minus_zero));
1635 }
1636
1637
1638 static void
1639 trunc_test (void)
1640 {
1641   check ("trunc(0) = 0", FUNC(trunc) (0), 0);
1642   check ("trunc(-0) = -0", FUNC(trunc) (minus_zero), minus_zero);
1643   check ("trunc(0.625) = 0", FUNC(trunc) (0.625), 0);
1644   check ("trunc(-0.625) = -0", FUNC(trunc) (-0.625), minus_zero);
1645   check ("trunc(1) = 1", FUNC(trunc) (1), 1);
1646   check ("trunc(-1) = -1", FUNC(trunc) (-1), -1);
1647   check ("trunc(1.625) = 1", FUNC(trunc) (1.625), 1);
1648   check ("trunc(-1.625) = -1", FUNC(trunc) (-1.625), -1);
1649
1650   check ("trunc(1048580.625) = 1048580", FUNC(trunc) (1048580.625L),
1651          1048580L);
1652   check ("trunc(-1048580.625) = -1048580", FUNC(trunc) (-1048580.625L),
1653          -1048580L);
1654
1655   check ("trunc(8388610.125) = 8388610", FUNC(trunc) (8388610.125L),
1656          8388610.0L);
1657   check ("trunc(-8388610.125) = -8388610", FUNC(trunc) (-8388610.125L),
1658          -8388610.0L);
1659
1660   check ("trunc(4294967296.625) = 4294967296", FUNC(trunc) (4294967296.625L),
1661          4294967296.0L);
1662   check ("trunc(-4294967296.625) = -4294967296",
1663          FUNC(trunc) (-4294967296.625L), -4294967296.0L);
1664
1665   check_isinfp ("trunc(+inf) = +inf", FUNC(trunc) (plus_infty));
1666   check_isinfn ("trunc(-inf) = -inf", FUNC(trunc) (minus_infty));
1667   check_isnan ("trunc(NaN) = NaN", FUNC(trunc) (nan_value));
1668 }
1669
1670
1671 static void
1672 sqrt_test (void)
1673 {
1674   MATHTYPE x;
1675
1676
1677   /* XXX Tests fuer negative x are missing */
1678   check ("sqrt (0) == 0", FUNC(sqrt) (0), 0);
1679   check_isnan ("sqrt (NaN) == NaN", FUNC(sqrt) (nan_value));
1680   check_isinfp ("sqrt (+inf) == +inf", FUNC(sqrt) (plus_infty));
1681
1682   x = random_value (0, 10000);
1683   check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x);
1684   check ("sqrt (4) == 2", FUNC(sqrt) (4), 2);
1685 }
1686
1687
1688 static void
1689 remquo_test (void)
1690 {
1691   int quo;
1692   MATHTYPE result;
1693
1694   result = FUNC(remquo) (1.625, 1.0, &quo);
1695   check ("remquo(1.625, 1.0, &x) == -0.375", result, -0.375);
1696   check_long ("remquo(1.625, 1.0, &x) puts 1 in x", quo, 1);
1697
1698   result = FUNC(remquo) (-1.625, 1.0, &quo);
1699   check ("remquo(-1.625, 1.0, &x) == 0.375", result, 0.375);
1700   check_long ("remquo(-1.625, 1.0, &x) puts -1 in x", quo, -1);
1701
1702   result = FUNC(remquo) (1.625, -1.0, &quo);
1703   check ("remquo(1.625, -1.0, &x) == -0.375", result, -0.375);
1704   check_long ("remquo(1.625, -1.0, &x) puts -1 in x", quo, -1);
1705
1706   result = FUNC(remquo) (-1.625, -1.0, &quo);
1707   check ("remquo(-1.625, -1.0, &x) == 0.375", result, 0.375);
1708   check_long ("remquo(-1.625, -1.0, &x) puts 1 in x", quo, 1);
1709 }
1710
1711
1712 static void
1713 cexp_test (void)
1714 {
1715   __complex__ MATHTYPE result;
1716
1717   result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, plus_zero));
1718   check ("real(cexp(0 + 0i)) = 1", __real__ result, 1);
1719   check ("imag(cexp(0 + 0i)) = 0", __imag__ result, 0);
1720   result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_zero));
1721   check ("real(cexp(-0 + 0i)) = 1", __real__ result, 1);
1722   check ("imag(cexp(-0 + 0i)) = 0", __imag__ result, 0);
1723   result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, minus_zero));
1724   check ("real(cexp(0 - 0i)) = 1", __real__ result, 1);
1725   check ("imag(cexp(0 - 0i)) = -0", __imag__ result, minus_zero);
1726   result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_zero));
1727   check ("real(cexp(-0 - 0i)) = 1", __real__ result, 1);
1728   check ("imag(cexp(-0 - 0i)) = -0", __imag__ result, minus_zero);
1729
1730   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_zero));
1731   check_isinfp ("real(cexp(+inf + 0i)) = +inf", __real__ result);
1732   check ("imag(cexp(+inf + 0i)) = 0", __imag__ result, 0);
1733   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_zero));
1734   check_isinfp ("real(cexp(+inf - 0i)) = +inf", __real__ result);
1735   check ("imag(cexp(+inf - 0i)) = -0", __imag__ result, minus_zero);
1736
1737   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_zero));
1738   check ("real(cexp(-inf + 0i)) = 0", __real__ result, 0);
1739   check ("imag(cexp(-inf + 0i)) = 0", __imag__ result, 0);
1740   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_zero));
1741   check ("real(cexp(-inf - 0i)) = 0", __real__ result, 0);
1742   check ("imag(cexp(-inf - 0i)) = -0", __imag__ result, minus_zero);
1743
1744   result = FUNC(cexp) (BUILD_COMPLEX (0.0, plus_infty));
1745   check_isnan_exc ("real(cexp(0 + i inf)) = NaN plus invalid exception",
1746                    __real__ result, FE_INVALID);
1747   check_isnan ("imag(cexp(0 + i inf)) = NaN plus invalid exception",
1748                __imag__ result);
1749   result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_infty));
1750   check_isnan_exc ("real(cexp(-0 + i inf)) = NaN plus invalid exception",
1751                    __real__ result, FE_INVALID);
1752   check_isnan ("imag(cexp(-0 + i inf)) = NaN plus invalid exception",
1753                __imag__ result);
1754   result = FUNC(cexp) (BUILD_COMPLEX (0.0, minus_infty));
1755   check_isnan_exc ("real(cexp(0 - i inf)) = NaN plus invalid exception",
1756                    __real__ result, FE_INVALID);
1757   check_isnan ("imag(cexp(0 - i inf)) = NaN plus invalid exception",
1758                __imag__ result);
1759   result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_infty));
1760   check_isnan_exc ("real(cexp(-0 - i inf)) = NaN plus invalid exception",
1761                    __real__ result, FE_INVALID);
1762   check_isnan ("imag(cexp(-0 - i inf)) = NaN plus invalid exception",
1763                __imag__ result);
1764
1765   result = FUNC(cexp) (BUILD_COMPLEX (100.0, plus_infty));
1766   check_isnan_exc ("real(cexp(100.0 + i inf)) = NaN plus invalid exception",
1767                    __real__ result, FE_INVALID);
1768   check_isnan ("imag(cexp(100.0 + i inf)) = NaN plus invalid exception",
1769                __imag__ result);
1770   result = FUNC(cexp) (BUILD_COMPLEX (-100.0, plus_infty));
1771   check_isnan_exc ("real(cexp(-100.0 + i inf)) = NaN plus invalid exception",
1772                    __real__ result, FE_INVALID);
1773   check_isnan ("imag(cexp(-100.0 + i inf)) = NaN plus invalid exception",
1774                __imag__ result);
1775   result = FUNC(cexp) (BUILD_COMPLEX (100.0, minus_infty));
1776   check_isnan_exc ("real(cexp(100.0 - i inf)) = NaN plus invalid exception",
1777                    __real__ result, FE_INVALID);
1778   check_isnan ("imag(cexp(100.0 - i inf)) = NaN plus invalid exception",
1779                __imag__ result);
1780   result = FUNC(cexp) (BUILD_COMPLEX (-100.0, minus_infty));
1781   check_isnan_exc ("real(cexp(-100.0 - i inf)) = NaN plus invalid exception",
1782                    __real__ result, FE_INVALID);
1783   check_isnan ("imag(cexp(-100.0 - i inf)) = NaN", __imag__ result);
1784
1785   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 2.0));
1786   check ("real(cexp(-inf + 2.0i)) = -0", __real__ result, minus_zero);
1787   check ("imag(cexp(-inf + 2.0i)) = 0", __imag__ result, 0);
1788   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 4.0));
1789   check ("real(cexp(-inf + 4.0i)) = -0", __real__ result, minus_zero);
1790   check ("imag(cexp(-inf + 4.0i)) = -0", __imag__ result, minus_zero);
1791
1792   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 2.0));
1793   check_isinfn ("real(cexp(+inf + 2.0i)) = -inf", __real__ result);
1794   check_isinfp ("imag(cexp(+inf + 2.0i)) = +inf", __imag__ result);
1795   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 4.0));
1796   check_isinfn ("real(cexp(+inf + 4.0i)) = -inf", __real__ result);
1797   check_isinfn ("imag(cexp(+inf + 4.0i)) = -inf", __imag__ result);
1798
1799   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_infty));
1800   check_isinfp_exc ("real(cexp(+inf + i inf)) = +inf plus invalid exception",
1801                     __real__ result, FE_INVALID);
1802   check_isnan ("imag(cexp(+inf + i inf)) = NaN plus invalid exception",
1803                __imag__ result);
1804   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_infty));
1805   check_isinfp_exc ("real(cexp(+inf - i inf)) = +inf plus invalid exception",
1806                     __real__ result, FE_INVALID);
1807   check_isnan ("imag(cexp(+inf - i inf)) = NaN plus invalid exception",
1808                __imag__ result);
1809
1810   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_infty));
1811   check ("real(cexp(-inf + i inf)) = 0", __real__ result, 0);
1812   check ("imag(cexp(-inf + i inf)) = 0", __imag__ result, 0);
1813   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_infty));
1814   check ("real(cexp(-inf - i inf)) = 0", __real__ result, 0);
1815   check ("imag(cexp(-inf - i inf)) = -0", __imag__ result, minus_zero);
1816
1817   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, nan_value));
1818   check ("real(cexp(-inf + i NaN)) = 0", __real__ result, 0);
1819   check ("imag(cexp(-inf + i NaN)) = 0", fabs (__imag__ result), 0);
1820
1821   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, nan_value));
1822   check_isinfp ("real(cexp(+inf + i NaN)) = +inf", __real__ result);
1823   check_isnan ("imag(cexp(+inf + i NaN)) = NaN", __imag__ result);
1824
1825   result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 0.0));
1826   check_isnan_maybe_exc ("real(cexp(NaN + i0)) = NaN plus maybe invalid exception",
1827                          __real__ result, FE_INVALID);
1828   check_isnan ("imag(cexp(NaN + i0)) = NaN plus maybe invalid exception",
1829                __imag__ result);
1830   result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
1831   check_isnan_maybe_exc ("real(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
1832                          __real__ result, FE_INVALID);
1833   check_isnan ("imag(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
1834                __imag__ result);
1835   result = FUNC(cexp) (BUILD_COMPLEX (nan_value, plus_infty));
1836   check_isnan_maybe_exc ("real(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
1837                          __real__ result, FE_INVALID);
1838   check_isnan ("imag(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
1839                __imag__ result);
1840
1841   result = FUNC(cexp) (BUILD_COMPLEX (0, nan_value));
1842   check_isnan_maybe_exc ("real(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
1843                          __real__ result, FE_INVALID);
1844   check_isnan ("imag(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
1845                __imag__ result);
1846   result = FUNC(cexp) (BUILD_COMPLEX (1, nan_value));
1847   check_isnan_maybe_exc ("real(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
1848                          __real__ result, FE_INVALID);
1849   check_isnan ("imag(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
1850                __imag__ result);
1851
1852   result = FUNC(cexp) (BUILD_COMPLEX (nan_value, nan_value));
1853   check_isnan ("real(cexp(NaN + i NaN)) = NaN", __real__ result);
1854   check_isnan ("imag(cexp(NaN + i NaN)) = NaN", __imag__ result);
1855 }
1856
1857
1858 static void
1859 csin_test (void)
1860 {
1861   __complex__ MATHTYPE result;
1862
1863   result = FUNC(csin) (BUILD_COMPLEX (0.0, 0.0));
1864   check ("real(csin(0 + 0i)) = 0", __real__ result, 0);
1865   check ("imag(csin(0 + 0i)) = 0", __imag__ result, 0);
1866   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, 0.0));
1867   check ("real(csin(-0 + 0i)) = -0", __real__ result, minus_zero);
1868   check ("imag(csin(-0 + 0i)) = 0", __imag__ result, 0);
1869   result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_zero));
1870   check ("real(csin(0 - 0i)) = 0", __real__ result, 0);
1871   check ("imag(csin(0 - 0i)) = -0", __imag__ result, minus_zero);
1872   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_zero));
1873   check ("real(csin(-0 - 0i)) = -0", __real__ result, minus_zero);
1874   check ("imag(csin(-0 - 0i)) = -0", __imag__ result, minus_zero);
1875
1876   result = FUNC(csin) (BUILD_COMPLEX (0.0, plus_infty));
1877   check ("real(csin(0 + i Inf)) = 0", __real__ result, 0);
1878   check_isinfp ("imag(csin(0 + i Inf)) = +Inf", __imag__ result);
1879   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, plus_infty));
1880   check ("real(csin(-0 + i Inf)) = -0", __real__ result, minus_zero);
1881   check_isinfp ("imag(csin(-0 + i Inf)) = +Inf", __imag__ result);
1882   result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_infty));
1883   check ("real(csin(0 - i Inf)) = 0", __real__ result, 0);
1884   check_isinfn ("imag(csin(0 - i Inf)) = -Inf", __imag__ result);
1885   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_infty));
1886   check ("real(csin(-0 - i Inf)) = -0", __real__ result, minus_zero);
1887   check_isinfn("imag(csin(-0 - i Inf)) = -Inf", __imag__ result);
1888
1889   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 0.0));
1890   check_isnan_exc ("real(csin(+Inf + 0i)) = NaN plus invalid exception",
1891                    __real__ result, FE_INVALID);
1892   check ("imag(csin(+Inf + 0i)) = +-0 plus invalid exception",
1893          FUNC(fabs) (__imag__ result), 0);
1894   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 0.0));
1895   check_isnan_exc ("real(csin(-Inf + 0i)) = NaN plus invalid exception",
1896                    __real__ result, FE_INVALID);
1897   check ("imag(csin(-Inf + 0i)) = +-0 plus invalid exception",
1898          FUNC(fabs) (__imag__ result), 0);
1899   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_zero));
1900   check_isnan_exc ("real(csin(+Inf - 0i)) = NaN plus invalid exception",
1901                    __real__ result, FE_INVALID);
1902   check ("imag(csin(+Inf - 0i)) = +-0 plus invalid exception",
1903          FUNC(fabs) (__imag__ result), 0.0);
1904   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_zero));
1905   check_isnan_exc ("real(csin(-Inf - 0i)) = NaN plus invalid exception",
1906                    __real__ result, FE_INVALID);
1907   check ("imag(csin(-Inf - 0i)) = +-0 plus invalid exception",
1908          FUNC(fabs) (__imag__ result), 0.0);
1909
1910   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, plus_infty));
1911   check_isnan_exc ("real(csin(+Inf + i Inf)) = NaN plus invalid exception",
1912                    __real__ result, FE_INVALID);
1913   check_isinfp ("imag(csin(+Inf + i Inf)) = +-Inf plus invalid exception",
1914                 FUNC(fabs) (__imag__ result));
1915   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, plus_infty));
1916   check_isnan_exc ("real(csin(-Inf + i Inf)) = NaN plus invalid exception",
1917                    __real__ result, FE_INVALID);
1918   check_isinfp ("imag(csin(-Inf + i Inf)) = +-Inf plus invalid exception",
1919                 FUNC(fabs) (__imag__ result));
1920   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_infty));
1921   check_isnan_exc ("real(csin(Inf - i Inf)) = NaN plus invalid exception",
1922                    __real__ result, FE_INVALID);
1923   check_isinfp ("imag(csin(Inf - i Inf)) = +-Inf plus invalid exception",
1924                 FUNC(fabs) (__imag__ result));
1925   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_infty));
1926   check_isnan_exc ("real(csin(-Inf - i Inf)) = NaN plus invalid exception",
1927                    __real__ result, FE_INVALID);
1928   check_isinfp ("imag(csin(-Inf - i Inf)) = +-Inf plus invalid exception",
1929                 FUNC(fabs) (__imag__ result));
1930
1931   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 6.75));
1932   check_isnan_exc ("real(csin(+Inf + i 6.75)) = NaN plus invalid exception",
1933                    __real__ result, FE_INVALID);
1934   check_isnan ("imag(csin(+Inf + i6.75)) = NaN plus invalid exception",
1935                __imag__ result);
1936   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, -6.75));
1937   check_isnan_exc ("real(csin(+Inf - i 6.75)) = NaN plus invalid exception",
1938                    __real__ result, FE_INVALID);
1939   check_isnan ("imag(csin(+Inf - i6.75)) = NaN plus invalid exception",
1940                __imag__ result);
1941   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 6.75));
1942   check_isnan_exc ("real(csin(-Inf + i6.75)) = NaN plus invalid exception",
1943                    __real__ result, FE_INVALID);
1944   check_isnan ("imag(csin(-Inf + i6.75)) = NaN plus invalid exception",
1945                __imag__ result);
1946   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, -6.75));
1947   check_isnan_exc ("real(csin(-Inf - i6.75)) = NaN plus invalid exception",
1948                    __real__ result, FE_INVALID);
1949   check_isnan ("imag(csin(-Inf - i6.75)) = NaN plus invalid exception",
1950                __imag__ result);
1951
1952   result = FUNC(csin) (BUILD_COMPLEX (4.625, plus_infty));
1953   check_isinfn ("real(csin(4.625 + i Inf)) = -Inf", __real__ result);
1954   check_isinfn ("imag(csin(4.625 + i Inf)) = -Inf", __imag__ result);
1955   result = FUNC(csin) (BUILD_COMPLEX (4.625, minus_infty));
1956   check_isinfn ("real(csin(4.625 - i Inf)) = -Inf", __real__ result);
1957   check_isinfp ("imag(csin(4.625 - i Inf)) = +Inf", __imag__ result);
1958   result = FUNC(csin) (BUILD_COMPLEX (-4.625, plus_infty));
1959   check_isinfp ("real(csin(-4.625 + i Inf)) = +Inf", __real__ result);
1960   check_isinfn ("imag(csin(-4.625 + i Inf)) = -Inf", __imag__ result);
1961   result = FUNC(csin) (BUILD_COMPLEX (-4.625, minus_infty));
1962   check_isinfp ("real(csin(-4.625 - i Inf)) = +Inf", __real__ result);
1963   check_isinfp ("imag(csin(-4.625 - i Inf)) = +Inf", __imag__ result);
1964
1965   result = FUNC(csin) (BUILD_COMPLEX (nan_value, 0.0));
1966   check_isnan ("real(csin(NaN + i0)) = NaN", __real__ result);
1967   check ("imag(csin(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
1968   result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_zero));
1969   check_isnan ("real(csin(NaN - i0)) = NaN", __real__ result);
1970   check ("imag(csin(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
1971
1972   result = FUNC(csin) (BUILD_COMPLEX (nan_value, plus_infty));
1973   check_isnan ("real(csin(NaN + i Inf)) = NaN", __real__ result);
1974   check_isinfp ("imag(csin(NaN + i Inf)) = +-Inf",
1975                 FUNC(fabs) (__imag__ result));
1976   result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_infty));
1977   check_isnan ("real(csin(NaN - i Inf)) = NaN", __real__ result);
1978   check_isinfp ("real(csin(NaN - i Inf)) = +-Inf",
1979                 FUNC(fabs) (__imag__ result));
1980
1981   result = FUNC(csin) (BUILD_COMPLEX (nan_value, 9.0));
1982   check_isnan_maybe_exc ("real(csin(NaN + i9.0)) = NaN plus maybeinvalid exception",
1983                          __real__ result, FE_INVALID);
1984   check_isnan ("imag(csin(NaN + i9.0)) = NaN plus maybeinvalid exception",
1985                __imag__ result);
1986   result = FUNC(csin) (BUILD_COMPLEX (nan_value, -9.0));
1987   check_isnan_maybe_exc ("real(csin(NaN - i9.0)) = NaN plus maybeinvalid exception",
1988                          __real__ result, FE_INVALID);
1989   check_isnan ("imag(csin(NaN - i9.0)) = NaN plus maybeinvalid exception",
1990                __imag__ result);
1991
1992   result = FUNC(csin) (BUILD_COMPLEX (0.0, nan_value));
1993   check ("real(csin(0 + i NaN))", __real__ result, 0.0);
1994   check_isnan ("imag(csin(0 + i NaN)) = NaN", __imag__ result);
1995   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, nan_value));
1996   check ("real(csin(-0 + i NaN)) = -0", __real__ result, minus_zero);
1997   check_isnan ("imag(csin(-0 + NaN)) = NaN", __imag__ result);
1998
1999   result = FUNC(csin) (BUILD_COMPLEX (10.0, nan_value));
2000   check_isnan_maybe_exc ("real(csin(10 + i NaN)) = NaN plus maybeinvalid exception",
2001                          __real__ result, FE_INVALID);
2002   check_isnan ("imag(csin(10 + i NaN)) = NaN plus maybeinvalid exception",
2003                __imag__ result);
2004   result = FUNC(csin) (BUILD_COMPLEX (nan_value, -10.0));
2005   check_isnan_maybe_exc ("real(csin(-10 + i NaN)) = NaN plus maybeinvalid exception",
2006                          __real__ result, FE_INVALID);
2007   check_isnan ("imag(csin(-10 + i NaN)) = NaN plus maybeinvalid exception",
2008                __imag__ result);
2009
2010   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, nan_value));
2011   check_isnan ("real(csin(+Inf + i NaN)) = NaN", __real__ result);
2012   check_isnan ("imag(csin(+Inf + i NaN)) = NaN", __imag__ result);
2013   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, nan_value));
2014   check_isnan ("real(csin(-Inf + i NaN)) = NaN", __real__ result);
2015   check_isnan ("imag(csin(-Inf + i NaN)) = NaN", __imag__ result);
2016
2017   result = FUNC(csin) (BUILD_COMPLEX (nan_value, nan_value));
2018   check_isnan ("real(csin(NaN + i NaN)) = NaN", __real__ result);
2019   check_isnan ("imag(csin(NaN + i NaN)) = NaN", __imag__ result);
2020 }
2021
2022
2023 static void
2024 csinh_test (void)
2025 {
2026   __complex__ MATHTYPE result;
2027
2028   result = FUNC(csinh) (BUILD_COMPLEX (0.0, 0.0));
2029   check ("real(csinh(0 + 0i)) = 0", __real__ result, 0);
2030   check ("imag(csinh(0 + 0i)) = 0", __imag__ result, 0);
2031   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, 0.0));
2032   check ("real(csinh(-0 + 0i)) = -0", __real__ result, minus_zero);
2033   check ("imag(csinh(-0 + 0i)) = 0", __imag__ result, 0);
2034   result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_zero));
2035   check ("real(csinh(0 - 0i)) = 0", __real__ result, 0);
2036   check ("imag(csinh(0 - 0i)) = -0", __imag__ result, minus_zero);
2037   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_zero));
2038   check ("real(csinh(-0 - 0i)) = -0", __real__ result, minus_zero);
2039   check ("imag(csinh(-0 - 0i)) = -0", __imag__ result, minus_zero);
2040
2041   result = FUNC(csinh) (BUILD_COMPLEX (0.0, plus_infty));
2042   check_exc ("real(csinh(0 + i Inf)) = +-0 plus invalid exception",
2043              FUNC(fabs) (__real__ result), 0, FE_INVALID);
2044   check_isnan ("imag(csinh(0 + i Inf)) = NaN plus invalid exception",
2045                __imag__ result);
2046   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, plus_infty));
2047   check_exc ("real(csinh(-0 + i Inf)) = +-0 plus invalid exception",
2048              FUNC(fabs) (__real__ result), 0, FE_INVALID);
2049   check_isnan ("imag(csinh(-0 + i Inf)) = NaN plus invalid exception",
2050                __imag__ result);
2051   result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_infty));
2052   check_exc ("real(csinh(0 - i Inf)) = +-0 plus invalid exception",
2053              FUNC(fabs) (__real__ result), 0, FE_INVALID);
2054   check_isnan ("imag(csinh(0 - i Inf)) = NaN plus invalid exception",
2055                __imag__ result);
2056   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_infty));
2057   check_exc ("real(csinh(-0 - i Inf)) = +-0 plus invalid exception",
2058              FUNC(fabs) (__real__ result), 0, FE_INVALID);
2059   check_isnan ("imag(csinh(-0 - i Inf)) = NaN plus invalid exception",
2060                __imag__ result);
2061
2062   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 0.0));
2063   check_isinfp ("real(csinh(+Inf + 0i)) = +Inf", __real__ result);
2064   check ("imag(csinh(+Inf + 0i)) = 0", __imag__ result, 0);
2065   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 0.0));
2066   check_isinfn ("real(csinh(-Inf + 0i)) = -Inf", __real__ result);
2067   check ("imag(csinh(-Inf + 0i)) = 0", __imag__ result, 0);
2068   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_zero));
2069   check_isinfp ("real(csinh(+Inf - 0i)) = +Inf", __real__ result);
2070   check ("imag(csinh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
2071   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_zero));
2072   check_isinfn ("real(csinh(-Inf - 0i)) = -Inf", __real__ result);
2073   check ("imag(csinh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
2074
2075   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, plus_infty));
2076   check_isinfp_exc ("real(csinh(+Inf + i Inf)) = +-Inf plus invalid exception",
2077                     FUNC(fabs) (__real__ result), FE_INVALID);
2078   check_isnan ("imag(csinh(+Inf + i Inf)) = NaN plus invalid exception",
2079                __imag__ result);
2080   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, plus_infty));
2081   check_isinfp_exc ("real(csinh(-Inf + i Inf)) = +-Inf plus invalid exception",
2082                     FUNC(fabs) (__real__ result), FE_INVALID);
2083   check_isnan ("imag(csinh(-Inf + i Inf)) = NaN plus invalid exception",
2084                __imag__ result);
2085   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_infty));
2086   check_isinfp_exc ("real(csinh(Inf - i Inf)) = +-Inf plus invalid exception",
2087                     FUNC(fabs) (__real__ result), FE_INVALID);
2088   check_isnan ("imag(csinh(Inf - i Inf)) = NaN plus invalid exception",
2089                __imag__ result);
2090   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_infty));
2091   check_isinfp_exc ("real(csinh(-Inf - i Inf)) = +-Inf plus invalid exception",
2092                     FUNC(fabs) (__real__ result), FE_INVALID);
2093   check_isnan ("imag(csinh(-Inf - i Inf)) = NaN plus invalid exception",
2094                __imag__ result);
2095
2096   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 4.625));
2097   check_isinfn ("real(csinh(+Inf + i4.625)) = -Inf", __real__ result);
2098   check_isinfn ("imag(csinh(+Inf + i4.625)) = -Inf", __imag__ result);
2099   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 4.625));
2100   check_isinfp ("real(csinh(-Inf + i4.625)) = +Inf", __real__ result);
2101   check_isinfn ("imag(csinh(-Inf + i4.625)) = -Inf", __imag__ result);
2102   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, -4.625));
2103   check_isinfn ("real(csinh(+Inf - i4.625)) = -Inf", __real__ result);
2104   check_isinfp ("imag(csinh(+Inf - i4.625)) = +Inf", __imag__ result);
2105   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, -4.625));
2106   check_isinfp ("real(csinh(-Inf - i4.625)) = +Inf", __real__ result);
2107   check_isinfp ("imag(csinh(-Inf - i4.625)) = +Inf", __imag__ result);
2108
2109   result = FUNC(csinh) (BUILD_COMPLEX (6.75, plus_infty));
2110   check_isnan_exc ("real(csinh(6.75 + i Inf)) = NaN plus invalid exception",
2111                    __real__ result, FE_INVALID);
2112   check_isnan ("imag(csinh(6.75 + i Inf)) = NaN plus invalid exception",
2113                __imag__ result);
2114   result = FUNC(csinh) (BUILD_COMPLEX (-6.75, plus_infty));
2115   check_isnan_exc ("real(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
2116                    __real__ result, FE_INVALID);
2117   check_isnan ("imag(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
2118                __imag__ result);
2119   result = FUNC(csinh) (BUILD_COMPLEX (6.75, minus_infty));
2120   check_isnan_exc ("real(csinh(6.75 - i Inf)) = NaN plus invalid exception",
2121                    __real__ result, FE_INVALID);
2122   check_isnan ("imag(csinh(6.75 - i Inf)) = NaN plus invalid exception",
2123                __imag__ result);
2124   result = FUNC(csinh) (BUILD_COMPLEX (-6.75, minus_infty));
2125   check_isnan_exc ("real(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
2126                    __real__ result, FE_INVALID);
2127   check_isnan ("imag(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
2128                __imag__ result);
2129
2130   result = FUNC(csinh) (BUILD_COMPLEX (0.0, nan_value));
2131   check ("real(csinh(0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
2132   check_isnan ("imag(csinh(0 + i NaN)) = NaN", __imag__ result);
2133   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, nan_value));
2134   check ("real(csinh(-0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
2135   check_isnan ("imag(csinh(-0 + i NaN)) = NaN", __imag__ result);
2136
2137   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, nan_value));
2138   check_isinfp ("real(csinh(+Inf + i NaN)) = +-Inf",
2139                 FUNC(fabs) (__real__ result));
2140   check_isnan ("imag(csinh(+Inf + i NaN)) = NaN", __imag__ result);
2141   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, nan_value));
2142   check_isinfp ("real(csinh(-Inf + i NaN)) = +-Inf",
2143                 FUNC(fabs) (__real__ result));
2144   check_isnan ("imag(csinh(-Inf + i NaN)) = NaN", __imag__ result);
2145
2146   result = FUNC(csinh) (BUILD_COMPLEX (9.0, nan_value));
2147   check_isnan_maybe_exc ("real(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
2148                          __real__ result, FE_INVALID);
2149   check_isnan ("imag(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
2150                __imag__ result);
2151   result = FUNC(csinh) (BUILD_COMPLEX (-9.0, nan_value));
2152   check_isnan_maybe_exc ("real(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
2153                          __real__ result, FE_INVALID);
2154   check_isnan ("imag(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
2155                __imag__ result);
2156
2157   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 0.0));
2158   check_isnan ("real(csinh(NaN + i0)) = NaN", __real__ result);
2159   check ("imag(csinh(NaN + i0)) = 0", __imag__ result, 0.0);
2160   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_zero));
2161   check_isnan ("real(csinh(NaN - i0)) = NaN", __real__ result);
2162   check ("imag(csinh(NaN - i0)) = -0", __imag__ result, minus_zero);
2163
2164   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 10.0));
2165   check_isnan_maybe_exc ("real(csinh(NaN + i10)) = NaN plus maybe invalid exception",
2166                          __real__ result, FE_INVALID);
2167   check_isnan ("imag(csinh(NaN + i10)) = NaN plus maybe invalid exception",
2168                __imag__ result);
2169   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, -10.0));
2170   check_isnan_maybe_exc ("real(csinh(NaN - i10)) = NaN plus maybe invalid exception",
2171                          __real__ result, FE_INVALID);
2172   check_isnan ("imag(csinh(NaN - i10)) = NaN plus maybe invalid exception",
2173                __imag__ result);
2174
2175   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, plus_infty));
2176   check_isnan ("real(csinh(NaN + i Inf)) = NaN", __real__ result);
2177   check_isnan ("imag(csinh(NaN + i Inf)) = NaN", __imag__ result);
2178   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_infty));
2179   check_isnan ("real(csinh(NaN - i Inf)) = NaN", __real__ result);
2180   check_isnan ("imag(csinh(NaN - i Inf)) = NaN", __imag__ result);
2181
2182   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, nan_value));
2183   check_isnan ("real(csinh(NaN + i NaN)) = NaN", __real__ result);
2184   check_isnan ("imag(csinh(NaN + i NaN)) = NaN", __imag__ result);
2185 }
2186
2187
2188 static void
2189 ccos_test (void)
2190 {
2191   __complex__ MATHTYPE result;
2192
2193   result = FUNC(ccos) (BUILD_COMPLEX (0.0, 0.0));
2194   check ("real(ccos(0 + 0i)) = 1.0", __real__ result, 1.0);
2195   check ("imag(ccos(0 + 0i)) = 0", __imag__ result, 0);
2196   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, 0.0));
2197   check ("real(ccos(-0 + 0i)) = 1.0", __real__ result, 1.0);
2198   check ("imag(ccos(-0 + 0i)) = -0", __imag__ result, minus_zero);
2199   result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_zero));
2200   check ("real(ccos(0 - 0i)) = 1.0", __real__ result, 1.0);
2201   check ("imag(ccos(0 - 0i)) = 0", __imag__ result, 0.0);
2202   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_zero));
2203   check ("real(ccos(-0 - 0i)) = 1.0", __real__ result, 1.0);
2204   check ("imag(ccos(-0 - 0i)) = -0", __imag__ result, minus_zero);
2205
2206   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 0.0));
2207   check_isnan_exc ("real(ccos(+Inf + i0)) = NaN plus invalid exception",
2208                    __real__ result, FE_INVALID);
2209   check ("imag(ccos(Inf + i0)) = +-0 plus invalid exception",
2210          FUNC(fabs) (__imag__ result), 0);
2211   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_zero));
2212   check_isnan_exc ("real(ccos(Inf - i0)) = NaN plus invalid exception",
2213                    __real__ result, FE_INVALID);
2214   check ("imag(ccos(Inf - i0)) = +-0 plus invalid exception",
2215          FUNC(fabs) (__imag__ result), 0);
2216   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 0.0));
2217   check_isnan_exc ("real(ccos(-Inf + i0)) = NaN plus invalid exception",
2218                    __real__ result, FE_INVALID);
2219   check ("imag(ccos(-Inf + i0)) = +-0 plus invalid exception",
2220          FUNC(fabs) (__imag__ result), 0);
2221   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_zero));
2222   check_isnan_exc ("real(ccos(-Inf - i0)) = NaN plus invalid exception",
2223                    __real__ result, FE_INVALID);
2224   check ("imag(ccos(-Inf - i0)) = +-0 plus invalid exception",
2225          FUNC(fabs) (__imag__ result), 0);
2226
2227   result = FUNC(ccos) (BUILD_COMPLEX (0.0, plus_infty));
2228   check_isinfp ("real(ccos(0 + i Inf)) = +Inf", __real__ result);
2229   check ("imag(ccos(0 + i Inf)) = 0", __imag__ result, 0);
2230   result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_infty));
2231   check_isinfp ("real(ccos(0 - i Inf)) = +Inf", __real__ result);
2232   check ("imag(ccos(0 - i Inf)) = 0", __imag__ result, 0);
2233   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, plus_infty));
2234   check_isinfp ("real(ccos(-0 + i Inf)) = +Inf", __real__ result);
2235   check ("imag(ccos(-0 + i Inf)) = -0", __imag__ result, minus_zero);
2236   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_infty));
2237   check_isinfp ("real(ccos(-0 - i Inf)) = +Inf", __real__ result);
2238   check ("imag(ccos(-0 - i Inf)) = -0", __imag__ result, minus_zero);
2239
2240   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, plus_infty));
2241   check_isinfp_exc ("real(ccos(+Inf + i Inf)) = +Inf plus invalid exception",
2242                     __real__ result, FE_INVALID);
2243   check_isnan ("imag(ccos(+Inf + i Inf)) = NaN plus invalid exception",
2244                __imag__ result);
2245   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, plus_infty));
2246   check_isinfp_exc ("real(ccos(-Inf + i Inf)) = +Inf plus invalid exception",
2247                     __real__ result, FE_INVALID);
2248   check_isnan ("imag(ccos(-Inf + i Inf)) = NaN plus invalid exception",
2249                __imag__ result);
2250   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_infty));
2251   check_isinfp_exc ("real(ccos(Inf - i Inf)) = +Inf plus invalid exception",
2252                     __real__ result, FE_INVALID);
2253   check_isnan ("imag(ccos(Inf - i Inf)) = NaN plus invalid exception",
2254                __imag__ result);
2255   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_infty));
2256   check_isinfp_exc ("real(ccos(-Inf - i Inf)) = +Inf plus invalid exception",
2257                     __real__ result, FE_INVALID);
2258   check_isnan ("imag(ccos(-Inf - i Inf)) = NaN plus invalid exception",
2259                __imag__ result);
2260
2261   result = FUNC(ccos) (BUILD_COMPLEX (4.625, plus_infty));
2262   check_isinfn ("real(ccos(4.625 + i Inf)) = -Inf", __real__ result);
2263   check_isinfn ("imag(ccos(4.625 + i Inf)) = -Inf", __imag__ result);
2264   result = FUNC(ccos) (BUILD_COMPLEX (4.625, minus_infty));
2265   check_isinfn ("real(ccos(4.625 - i Inf)) = -Inf", __real__ result);
2266   check_isinfn ("imag(ccos(4.625 - i Inf)) = -Inf", __imag__ result);
2267   result = FUNC(ccos) (BUILD_COMPLEX (-4.625, plus_infty));
2268   check_isinfn ("real(ccos(-4.625 + i Inf)) = -Inf", __real__ result);
2269   check_isinfp ("imag(ccos(-4.625 + i Inf)) = +Inf", __imag__ result);
2270   result = FUNC(ccos) (BUILD_COMPLEX (-4.625, minus_infty));
2271   check_isinfn ("real(ccos(-4.625 - i Inf)) = -Inf", __real__ result);
2272   check_isinfp ("imag(ccos(-4.625 - i Inf)) = +Inf", __imag__ result);
2273
2274   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 6.75));
2275   check_isnan_exc ("real(ccos(+Inf + i6.75)) = NaN plus invalid exception",
2276                    __real__ result, FE_INVALID);
2277   check_isnan ("imag(ccos(+Inf + i6.75)) = NaN plus invalid exception",
2278                __imag__ result);
2279   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, -6.75));
2280   check_isnan_exc ("real(ccos(+Inf - i6.75)) = NaN plus invalid exception",
2281                    __real__ result, FE_INVALID);
2282   check_isnan ("imag(ccos(+Inf - i6.75)) = NaN plus invalid exception",
2283                __imag__ result);
2284   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 6.75));
2285   check_isnan_exc ("real(ccos(-Inf + i6.75)) = NaN plus invalid exception",
2286                    __real__ result, FE_INVALID);
2287   check_isnan ("imag(ccos(-Inf + i6.75)) = NaN plus invalid exception",
2288                __imag__ result);
2289   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, -6.75));
2290   check_isnan_exc ("real(ccos(-Inf - i6.75)) = NaN plus invalid exception",
2291                    __real__ result, FE_INVALID);
2292   check_isnan ("imag(ccos(-Inf - i6.75)) = NaN plus invalid exception",
2293                __imag__ result);
2294
2295   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 0.0));
2296   check_isnan ("real(ccos(NaN + i0)) = NaN", __real__ result);
2297   check ("imag(ccos(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2298   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_zero));
2299   check_isnan ("real(ccos(NaN - i0)) = NaN", __real__ result);
2300   check ("imag(ccos(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2301
2302   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, plus_infty));
2303   check_isinfp ("real(ccos(NaN + i Inf)) = +Inf", __real__ result);
2304   check_isnan ("imag(ccos(NaN + i Inf)) = NaN", __imag__ result);
2305   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_infty));
2306   check_isinfp ("real(ccos(NaN - i Inf)) = +Inf", __real__ result);
2307   check_isnan ("imag(ccos(NaN - i Inf)) = NaN", __imag__ result);
2308
2309   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 9.0));
2310   check_isnan_maybe_exc ("real(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
2311                          __real__ result, FE_INVALID);
2312   check_isnan ("imag(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
2313                __imag__ result);
2314   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, -9.0));
2315   check_isnan_maybe_exc ("real(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
2316                          __real__ result, FE_INVALID);
2317   check_isnan ("imag(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
2318                __imag__ result);
2319
2320   result = FUNC(ccos) (BUILD_COMPLEX (0.0, nan_value));
2321   check_isnan ("real(ccos(0 + i NaN)) = NaN", __real__ result);
2322   check ("imag(ccos(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
2323   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, nan_value));
2324   check_isnan ("real(ccos(-0 + i NaN)) = NaN", __real__ result);
2325   check ("imag(ccos(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
2326
2327   result = FUNC(ccos) (BUILD_COMPLEX (10.0, nan_value));
2328   check_isnan_maybe_exc ("real(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
2329                          __real__ result, FE_INVALID);
2330   check_isnan ("imag(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
2331                __imag__ result);
2332   result = FUNC(ccos) (BUILD_COMPLEX (-10.0, nan_value));
2333   check_isnan_maybe_exc ("real(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
2334                          __real__ result, FE_INVALID);
2335   check_isnan ("imag(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
2336                __imag__ result);
2337
2338   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, nan_value));
2339   check_isnan_maybe_exc ("real(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
2340                          __real__ result, FE_INVALID);
2341   check_isnan ("imag(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
2342                __imag__ result);
2343   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, nan_value));
2344   check_isnan_maybe_exc ("real(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
2345                          __real__ result, FE_INVALID);
2346   check_isnan ("imag(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
2347                __imag__ result);
2348
2349   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, nan_value));
2350   check_isnan ("real(ccos(NaN + i NaN)) = NaN", __real__ result);
2351   check_isnan ("imag(ccos(NaN + i NaN)) = NaN", __imag__ result);
2352 }
2353
2354
2355 static void
2356 ccosh_test (void)
2357 {
2358   __complex__ MATHTYPE result;
2359
2360   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, 0.0));
2361   check ("real(ccosh(0 + 0i)) = 1.0", __real__ result, 1.0);
2362   check ("imag(ccosh(0 + 0i)) = 0", __imag__ result, 0);
2363   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, 0.0));
2364   check ("real(ccosh(-0 + 0i)) = 1.0", __real__ result, 1.0);
2365   check ("imag(ccosh(-0 + 0i)) = 0", __imag__ result, 0);
2366   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_zero));
2367   check ("real(ccosh(0 - 0i)) = 1.0", __real__ result, 1.0);
2368   check ("imag(ccosh(0 - 0i)) = -0", __imag__ result, minus_zero);
2369   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_zero));
2370   check ("real(ccosh(-0 - 0i)) = 1.0", __real__ result, 1.0);
2371   check ("imag(ccosh(-0 - 0i)) = -0", __imag__ result, minus_zero);
2372
2373   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, plus_infty));
2374   check_isnan_exc ("real(ccosh(0 + i Inf)) = NaN plus invalid exception",
2375                    __real__ result, FE_INVALID);
2376   check ("imag(ccosh(0 + i Inf)) = +-0 plus invalid exception",
2377          FUNC(fabs) (__imag__ result), 0);
2378   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, plus_infty));
2379   check_isnan_exc ("real(ccosh(-0 + i Inf)) = NaN plus invalid exception",
2380                    __real__ result, FE_INVALID);
2381   check ("imag(ccosh(-0 + i Inf)) = +-0 plus invalid exception",
2382          FUNC(fabs) (__imag__ result), 0);
2383   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_infty));
2384   check_isnan_exc ("real(ccosh(0 - i Inf)) = NaN plus invalid exception",
2385                    __real__ result, FE_INVALID);
2386   check ("imag(ccosh(0 - i Inf)) = +-0 plus invalid exception",
2387          FUNC(fabs) (__imag__ result), 0);
2388   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_infty));
2389   check_isnan_exc ("real(ccosh(-0 - i Inf)) = NaN plus invalid exception",
2390                    __real__ result, FE_INVALID);
2391   check ("imag(ccosh(-0 - i Inf)) = +-0 plus invalid exception",
2392          FUNC(fabs) (__imag__ result), 0);
2393
2394   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 0.0));
2395   check_isinfp ("real(ccosh(+Inf + 0i)) = +Inf", __real__ result);
2396   check ("imag(ccosh(+Inf + 0i)) = 0", __imag__ result, 0);
2397   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 0.0));
2398   check_isinfp ("real(ccosh(-Inf + 0i)) = +Inf", __real__ result);
2399   check ("imag(ccosh(-Inf + 0i)) = 0", __imag__ result, 0);
2400   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_zero));
2401   check_isinfp ("real(ccosh(+Inf - 0i)) = +Inf", __real__ result);
2402   check ("imag(ccosh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
2403   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_zero));
2404   check_isinfp ("real(ccosh(-Inf - 0i)) = +Inf", __real__ result);
2405   check ("imag(ccosh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
2406
2407   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, plus_infty));
2408   check_isinfp_exc ("real(ccosh(+Inf + i Inf)) = +Inf plus invalid exception",
2409                     __real__ result, FE_INVALID);
2410   check_isnan ("imag(ccosh(+Inf + i Inf)) = NaN plus invalid exception",
2411                __imag__ result);
2412   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, plus_infty));
2413   check_isinfp_exc ("real(ccosh(-Inf + i Inf)) = +Inf plus invalid exception",
2414                     __real__ result, FE_INVALID);
2415   check_isnan ("imag(ccosh(-Inf + i Inf)) = NaN plus invalid exception",
2416                __imag__ result);
2417   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_infty));
2418   check_isinfp_exc ("real(ccosh(Inf - i Inf)) = +Inf plus invalid exception",
2419                     __real__ result, FE_INVALID);
2420   check_isnan ("imag(ccosh(Inf - i Inf)) = NaN plus invalid exception",
2421                __imag__ result);
2422   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_infty));
2423   check_isinfp_exc ("real(ccosh(-Inf - i Inf)) = +Inf plus invalid exception",
2424                     __real__ result, FE_INVALID);
2425   check_isnan ("imag(ccosh(-Inf - i Inf)) = NaN plus invalid exception",
2426                __imag__ result);
2427
2428   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 4.625));
2429   check_isinfn ("real(ccosh(+Inf + i4.625)) = -Inf", __real__ result);
2430   check_isinfn ("imag(ccosh(+Inf + i4.625)) = -Inf", __imag__ result);
2431   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 4.625));
2432   check_isinfn ("real(ccosh(-Inf + i4.625)) = -Inf", __real__ result);
2433   check_isinfn ("imag(ccosh(-Inf + i4.625)) = -Inf", __imag__ result);
2434   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, -4.625));
2435   check_isinfn ("real(ccosh(+Inf - i4.625)) = -Inf", __real__ result);
2436   check_isinfp ("imag(ccosh(+Inf - i4.625)) = +Inf", __imag__ result);
2437   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, -4.625));
2438   check_isinfn ("real(ccosh(-Inf - i4.625)) = -Inf", __real__ result);
2439   check_isinfp ("imag(ccosh(-Inf - i4.625)) = +Inf", __imag__ result);
2440
2441   result = FUNC(ccosh) (BUILD_COMPLEX (6.75, plus_infty));
2442   check_isnan_exc ("real(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
2443                    __real__ result, FE_INVALID);
2444   check_isnan ("imag(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
2445                __imag__ result);
2446   result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, plus_infty));
2447   check_isnan_exc ("real(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
2448                    __real__ result, FE_INVALID);
2449   check_isnan ("imag(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
2450                __imag__ result);
2451   result = FUNC(ccosh) (BUILD_COMPLEX (6.75, minus_infty));
2452   check_isnan_exc ("real(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
2453                    __real__ result, FE_INVALID);
2454   check_isnan ("imag(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
2455                __imag__ result);
2456   result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, minus_infty));
2457   check_isnan_exc ("real(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
2458                    __real__ result, FE_INVALID);
2459   check_isnan ("imag(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
2460                __imag__ result);
2461
2462   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, nan_value));
2463   check_isnan ("real(ccosh(0 + i NaN)) = NaN", __real__ result);
2464   check ("imag(ccosh(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
2465   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, nan_value));
2466   check_isnan ("real(ccosh(-0 + i NaN)) = NaN", __real__ result);
2467   check ("imag(ccosh(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
2468
2469   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, nan_value));
2470   check_isinfp ("real(ccosh(+Inf + i NaN)) = +Inf", __real__ result);
2471   check_isnan ("imag(ccosh(+Inf + i NaN)) = NaN", __imag__ result);
2472   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, nan_value));
2473   check_isinfp ("real(ccosh(-Inf + i NaN)) = +Inf", __real__ result);
2474   check_isnan ("imag(ccosh(-Inf + i NaN)) = NaN", __imag__ result);
2475
2476   result = FUNC(ccosh) (BUILD_COMPLEX (9.0, nan_value));
2477   check_isnan_maybe_exc ("real(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
2478                          __real__ result, FE_INVALID);
2479   check_isnan ("imag(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
2480                __imag__ result);
2481   result = FUNC(ccosh) (BUILD_COMPLEX (-9.0, nan_value));
2482   check_isnan_maybe_exc ("real(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
2483                          __real__ result, FE_INVALID);
2484   check_isnan ("imag(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
2485                __imag__ result);
2486
2487   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 0.0));
2488   check_isnan ("real(ccosh(NaN + i0)) = NaN", __real__ result);
2489   check ("imag(ccosh(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
2490   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_zero));
2491   check_isnan ("real(ccosh(NaN - i0)) = NaN", __real__ result);
2492   check ("imag(ccosh(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
2493
2494   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 10.0));
2495   check_isnan_maybe_exc ("real(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
2496                          __real__ result, FE_INVALID);
2497   check_isnan ("imag(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
2498                __imag__ result);
2499   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, -10.0));
2500   check_isnan_maybe_exc ("real(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
2501                          __real__ result, FE_INVALID);
2502   check_isnan ("imag(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
2503                __imag__ result);
2504
2505   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, plus_infty));
2506   check_isnan_maybe_exc ("real(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
2507                          __real__ result, FE_INVALID);
2508   check_isnan ("imag(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
2509                __imag__ result);
2510   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_infty));
2511   check_isnan_maybe_exc ("real(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
2512                          __real__ result, FE_INVALID);
2513   check_isnan ("imag(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
2514                __imag__ result);
2515
2516   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, nan_value));
2517   check_isnan ("real(ccosh(NaN + i NaN)) = NaN", __real__ result);
2518   check_isnan ("imag(ccosh(NaN + i NaN)) = NaN", __imag__ result);
2519 }
2520
2521
2522 static void
2523 cacos_test (void)
2524 {
2525   __complex__ MATHTYPE result;
2526
2527   result = FUNC(cacos) (BUILD_COMPLEX (0, 0));
2528   check ("real(cacos(0 + i0)) = pi/2", __real__ result, M_PI_2);
2529   check ("imag(cacos(0 + i0)) = -0", __imag__ result, minus_zero);
2530   result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, 0));
2531   check ("real(cacos(-0 + i0)) = pi/2", __real__ result, M_PI_2);
2532   check ("imag(cacos(-0 + i0)) = -0", __imag__ result, minus_zero);
2533   result = FUNC(cacos) (BUILD_COMPLEX (0, minus_zero));
2534   check ("real(cacos(0 - i0)) = pi/2", __real__ result, M_PI_2);
2535   check ("imag(cacos(0 - i0)) = 0", __imag__ result, 0);
2536   result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, minus_zero));
2537   check ("real(cacos(-0 - i0)) = pi/2", __real__ result, M_PI_2);
2538   check ("imag(cacos(-0 - i0)) = 0", __imag__ result, 0);
2539
2540   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, plus_infty));
2541   check ("real(cacos(-Inf + i Inf)) = 3*pi/4", __real__ result, M_PI - M_PI_4);
2542   check_isinfn ("imag(cacos(-Inf + i Inf)) = -Inf", __imag__ result);
2543   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_infty));
2544   check ("real(cacos(-Inf - i Inf)) = 3*pi/4", __real__ result, M_PI - M_PI_4);
2545   check_isinfp ("imag(cacos(-Inf - i Inf)) = +Inf", __imag__ result);
2546
2547   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, plus_infty));
2548   check ("real(cacos(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4);
2549   check_isinfn ("imag(cacos(+Inf + i Inf)) = -Inf", __imag__ result);
2550   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_infty));
2551   check ("real(cacos(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4);
2552   check_isinfp ("imag(cacos(+Inf - i Inf)) = +Inf", __imag__ result);
2553
2554   result = FUNC(cacos) (BUILD_COMPLEX (-10.0, plus_infty));
2555   check ("real(cacos(-10.0 + i Inf)) = pi/2", __real__ result, M_PI_2);
2556   check_isinfn ("imag(cacos(-10.0 + i Inf)) = -Inf", __imag__ result);
2557   result = FUNC(cacos) (BUILD_COMPLEX (-10.0, minus_infty));
2558   check ("real(cacos(-10.0 - i Inf)) = pi/2", __real__ result, M_PI_2);
2559   check_isinfp ("imag(cacos(-10.0 - i Inf)) = +Inf", __imag__ result);
2560   result = FUNC(cacos) (BUILD_COMPLEX (0, plus_infty));
2561   check ("real(cacos(0 + i Inf)) = pi/2", __real__ result, M_PI_2);
2562   check_isinfn ("imag(cacos(0 + i Inf)) = -Inf", __imag__ result);
2563   result = FUNC(cacos) (BUILD_COMPLEX (0, minus_infty));
2564   check ("real(cacos(0 - i Inf)) = pi/2", __real__ result, M_PI_2);
2565   check_isinfp ("imag(cacos(0 - i Inf)) = +Inf", __imag__ result);
2566   result = FUNC(cacos) (BUILD_COMPLEX (0.1, plus_infty));
2567   check ("real(cacos(0.1 + i Inf)) = pi/2", __real__ result, M_PI_2);
2568   check_isinfn ("imag(cacos(0.1 + i Inf)) = -Inf", __imag__ result);
2569   result = FUNC(cacos) (BUILD_COMPLEX (0.1, minus_infty));
2570   check ("real(cacos(0.1 - i Inf)) = pi/2", __real__ result, M_PI_2);
2571   check_isinfp ("imag(cacos(0.1 - i Inf)) = +Inf", __imag__ result);
2572
2573   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 0));
2574   check ("real(cacos(-Inf + i0)) = pi", __real__ result, M_PI);
2575   check_isinfn ("imag(cacos(-Inf + i0)) = -Inf", __imag__ result);
2576   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_zero));
2577   check ("real(cacos(-Inf - i0)) = pi", __real__ result, M_PI);
2578   check_isinfp ("imag(cacos(-Inf - i0)) = +Inf", __imag__ result);
2579   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 100));
2580   check ("real(cacos(-Inf + i100)) = pi", __real__ result, M_PI);
2581   check_isinfn ("imag(cacos(-Inf + i100)) = -Inf", __imag__ result);
2582   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, -100));
2583   check ("real(cacos(-Inf - i100)) = pi", __real__ result, M_PI);
2584   check_isinfp ("imag(cacos(-Inf - i100)) = +Inf", __imag__ result);
2585
2586   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0));
2587   check ("real(cacos(+Inf + i0)) = 0", __real__ result, 0);
2588   check_isinfn ("imag(cacos(+Inf + i0)) = -Inf", __imag__ result);
2589   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_zero));
2590   check ("real(cacos(+Inf - i0)) = 0", __real__ result, 0);
2591   check_isinfp ("imag(cacos(+Inf - i0)) = +Inf", __imag__ result);
2592   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0.5));
2593   check ("real(cacos(+Inf + i0.5)) = 0", __real__ result, 0);
2594   check_isinfn ("imag(cacos(+Inf + i0.5)) = -Inf", __imag__ result);
2595   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, -0.5));
2596   check ("real(cacos(+Inf - i0.5)) = 0", __real__ result, 0);
2597   check_isinfp ("imag(cacos(+Inf - i0.5)) = +Inf", __imag__ result);
2598
2599   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, nan_value));
2600   check_isnan ("real(cacos(+Inf + i NaN)) = NaN", __real__ result);
2601   check_isinfp ("imag(cacos(+Inf + i NaN)) = +-Inf",
2602                 FUNC(fabs) (__imag__ result));
2603   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, nan_value));
2604   check_isnan ("real(cacos(-Inf + i NaN)) = NaN", __real__ result);
2605   check_isinfp ("imag(cacos(-Inf + i NaN)) = +-Inf",
2606                 FUNC(fabs) (__imag__ result));
2607
2608   result = FUNC(cacos) (BUILD_COMPLEX (0, nan_value));
2609   check ("real(cacos(0 + i NaN)) = pi/2", __real__ result, M_PI_2);
2610   check_isnan ("imag(cacos(0 + i NaN)) = NaN", __imag__ result);
2611   result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, nan_value));
2612   check ("real(cacos(-0 + i NaN)) = pi/2", __real__ result, M_PI_2);
2613   check_isnan ("imag(cacos(-0 + i NaN)) = NaN", __imag__ result);
2614
2615   result = FUNC(cacos) (BUILD_COMPLEX (nan_value, plus_infty));
2616   check_isnan ("real(cacos(NaN + i Inf)) = NaN", __real__ result);
2617   check_isinfn ("imag(cacos(NaN + i Inf)) = -Inf", __imag__ result);
2618   result = FUNC(cacos) (BUILD_COMPLEX (nan_value, minus_infty));
2619   check_isnan ("real(cacos(NaN - i Inf)) = NaN", __real__ result);
2620   check_isinfp ("imag(cacos(NaN - i Inf)) = +Inf", __imag__ result);
2621
2622   result = FUNC(cacos) (BUILD_COMPLEX (10.5, nan_value));
2623   check_isnan_maybe_exc ("real(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
2624                          __real__ result, FE_INVALID);
2625   check_isnan ("imag(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
2626                __imag__ result);
2627   result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
2628   check_isnan_maybe_exc ("real(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
2629                          __real__ result, FE_INVALID);
2630   check_isnan ("imag(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
2631                __imag__ result);
2632
2633   result = FUNC(cacos) (BUILD_COMPLEX (nan_value, 0.75));
2634   check_isnan_maybe_exc ("real(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
2635                          __real__ result, FE_INVALID);
2636   check_isnan ("imag(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
2637                __imag__ result);
2638   result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
2639   check_isnan_maybe_exc ("real(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
2640                          __real__ result, FE_INVALID);
2641   check_isnan ("imag(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
2642                __imag__ result);
2643
2644   result = FUNC(cacos) (BUILD_COMPLEX (nan_value, nan_value));
2645   check_isnan ("real(cacos(NaN + i NaN)) = NaN", __real__ result);
2646   check_isnan ("imag(cacos(NaN + i NaN)) = NaN", __imag__ result);
2647 }
2648
2649
2650 static void
2651 cacosh_test (void)
2652 {
2653   __complex__ MATHTYPE result;
2654
2655   result = FUNC(cacosh) (BUILD_COMPLEX (0, 0));
2656   check ("real(cacosh(0 + i0)) = 0", __real__ result, 0);
2657   check ("imag(cacosh(0 + i0)) = pi/2", __imag__ result, M_PI_2);
2658   result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, 0));
2659   check ("real(cacosh(-0 + i0)) = 0", __real__ result, 0);
2660   check ("imag(cacosh(-0 + i0)) = pi/2", __imag__ result, M_PI_2);
2661   result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_zero));
2662   check ("real(cacosh(0 - i0)) = 0", __real__ result, 0);
2663   check ("imag(cacosh(0 - i0)) = -pi/2", __imag__ result, -M_PI_2);
2664   result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, minus_zero));
2665   check ("real(cacosh(-0 - i0)) = 0", __real__ result, 0);
2666   check ("imag(cacosh(-0 - i0)) = -pi/2", __imag__ result, -M_PI_2);
2667
2668   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, plus_infty));
2669   check_isinfp ("real(cacosh(-Inf + i Inf)) = +Inf", __real__ result);
2670   check ("imag(cacosh(-Inf + i Inf)) = 3*pi/4", __imag__ result,
2671          M_PI - M_PI_4);
2672   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_infty));
2673   check_isinfp ("real(cacosh(-Inf - i Inf)) = +Inf", __real__ result);
2674   check ("imag(cacosh(-Inf - i Inf)) = -3*pi/4", __imag__ result,
2675          M_PI_4 - M_PI);
2676
2677   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, plus_infty));
2678   check_isinfp ("real(cacosh(+Inf + i Inf)) = +Inf", __real__ result);
2679   check ("imag(cacosh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
2680   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_infty));
2681   check_isinfp ("real(cacosh(+Inf - i Inf)) = +Inf", __real__ result);
2682   check ("imag(cacosh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
2683
2684   result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, plus_infty));
2685   check_isinfp ("real(cacosh(-10.0 + i Inf)) = +Inf", __real__ result);
2686   check ("imag(cacosh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2687   result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, minus_infty));
2688   check_isinfp ("real(cacosh(-10.0 - i Inf)) = +Inf", __real__ result);
2689   check ("imag(cacosh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2690   result = FUNC(cacosh) (BUILD_COMPLEX (0, plus_infty));
2691   check_isinfp ("real(cacosh(0 + i Inf)) = +Inf", __real__ result);
2692   check ("imag(cacosh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2693   result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_infty));
2694   check_isinfp ("real(cacosh(0 - i Inf)) = +Inf", __real__ result);
2695   check ("imag(cacosh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2696   result = FUNC(cacosh) (BUILD_COMPLEX (0.1, plus_infty));
2697   check_isinfp ("real(cacosh(0.1 + i Inf)) = +Inf", __real__ result);
2698   check ("imag(cacosh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2699   result = FUNC(cacosh) (BUILD_COMPLEX (0.1, minus_infty));
2700   check_isinfp ("real(cacosh(0.1 - i Inf)) = +Inf", __real__ result);
2701   check ("imag(cacosh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2702
2703   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 0));
2704   check_isinfp ("real(cacosh(-Inf + i0)) = +Inf", __real__ result);
2705   check ("imag(cacosh(-Inf + i0)) = pi", __imag__ result, M_PI);
2706   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_zero));
2707   check_isinfp ("real(cacosh(-Inf - i0)) = +Inf", __real__ result);
2708   check ("imag(cacosh(-Inf - i0)) = -pi", __imag__ result, -M_PI);
2709   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 100));
2710   check_isinfp ("real(cacosh(-Inf + i100)) = +Inf", __real__ result);
2711   check ("imag(cacosh(-Inf + i100)) = pi", __imag__ result, M_PI);
2712   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, -100));
2713   check_isinfp ("real(cacosh(-Inf - i100)) = +Inf", __real__ result);
2714   check ("imag(cacosh(-Inf - i100)) = -pi", __imag__ result, -M_PI);
2715
2716   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0));
2717   check_isinfp ("real(cacosh(+Inf + i0)) = +Inf", __real__ result);
2718   check ("imag(cacosh(+Inf + i0)) = 0", __imag__ result, 0);
2719   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_zero));
2720   check_isinfp ("real(cacosh(+Inf - i0)) = +Inf", __real__ result);
2721   check ("imag(cacosh(+Inf - i0)) = -0", __imag__ result, minus_zero);
2722   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0.5));
2723   check_isinfp ("real(cacosh(+Inf + i0.5)) = +Inf", __real__ result);
2724   check ("imag(cacosh(+Inf + i0.5)) = 0", __imag__ result, 0);
2725   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, -0.5));
2726   check_isinfp ("real(cacosh(+Inf - i0.5)) = +Inf", __real__ result);
2727   check ("imag(cacosh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
2728
2729   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, nan_value));
2730   check_isinfp ("real(cacosh(+Inf + i NaN)) = +Inf", __real__ result);
2731   check_isnan ("imag(cacosh(+Inf + i NaN)) = NaN", __imag__ result);
2732   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, nan_value));
2733   check_isinfp ("real(cacosh(-Inf + i NaN)) = +Inf", __real__ result);
2734   check_isnan ("imag(cacosh(-Inf + i NaN)) = NaN", __imag__ result);
2735
2736   result = FUNC(cacosh) (BUILD_COMPLEX (0, nan_value));
2737   check_isnan ("real(cacosh(0 + i NaN)) = NaN", __real__ result);
2738   check_isnan ("imag(cacosh(0 + i NaN)) = NaN", __imag__ result);
2739   result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, nan_value));
2740   check_isnan ("real(cacosh(-0 + i NaN)) = NaN", __real__ result);
2741   check_isnan ("imag(cacosh(-0 + i NaN)) = NaN", __imag__ result);
2742
2743   result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, plus_infty));
2744   check_isinfp ("real(cacosh(NaN + i Inf)) = +Inf", __real__ result);
2745   check_isnan ("imag(cacosh(NaN + i Inf)) = NaN", __imag__ result);
2746   result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, minus_infty));
2747   check_isinfp ("real(cacosh(NaN - i Inf)) = +Inf", __real__ result);
2748   check_isnan ("imag(cacosh(NaN - i Inf)) = NaN", __imag__ result);
2749
2750   result = FUNC(cacosh) (BUILD_COMPLEX (10.5, nan_value));
2751   check_isnan_maybe_exc ("real(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
2752                          __real__ result, FE_INVALID);
2753   check_isnan ("imag(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
2754                __imag__ result);
2755   result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
2756   check_isnan_maybe_exc ("real(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
2757                          __real__ result, FE_INVALID);
2758   check_isnan ("imag(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
2759                __imag__ result);
2760
2761   result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, 0.75));
2762   check_isnan_maybe_exc ("real(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
2763                          __real__ result, FE_INVALID);
2764   check_isnan ("imag(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
2765                __imag__ result);
2766   result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
2767   check_isnan_maybe_exc ("real(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
2768                          __real__ result, FE_INVALID);
2769   check_isnan ("imag(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
2770                __imag__ result);
2771
2772   result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, nan_value));
2773   check_isnan ("real(cacosh(NaN + i NaN)) = NaN", __real__ result);
2774   check_isnan ("imag(cacosh(NaN + i NaN)) = NaN", __imag__ result);
2775 }
2776
2777
2778 static void
2779 casin_test (void)
2780 {
2781   __complex__ MATHTYPE result;
2782
2783   result = FUNC(casin) (BUILD_COMPLEX (0, 0));
2784   check ("real(casin(0 + i0)) = 0", __real__ result, 0);
2785   check ("imag(casin(0 + i0)) = 0", __imag__ result, 0);
2786   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, 0));
2787   check ("real(casin(-0 + i0)) = -0", __real__ result, minus_zero);
2788   check ("imag(casin(-0 + i0)) = 0", __imag__ result, 0);
2789   result = FUNC(casin) (BUILD_COMPLEX (0, minus_zero));
2790   check ("real(casin(0 - i0)) = 0", __real__ result, 0);
2791   check ("imag(casin(0 - i0)) = -0", __imag__ result, minus_zero);
2792   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_zero));
2793   check ("real(casin(-0 - i0)) = -0", __real__ result, minus_zero);
2794   check ("imag(casin(-0 - i0)) = -0", __imag__ result, minus_zero);
2795
2796   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, plus_infty));
2797   check ("real(casin(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4);
2798   check_isinfp ("imag(casin(+Inf + i Inf)) = +Inf", __imag__ result);
2799   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_infty));
2800   check ("real(casin(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4);
2801   check_isinfn ("imag(casin(+Inf - i Inf)) = -Inf", __imag__ result);
2802   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, plus_infty));
2803   check ("real(casin(-Inf + i Inf)) = -pi/4", __real__ result, -M_PI_4);
2804   check_isinfp ("imag(casin(-Inf + i Inf)) = +Inf", __imag__ result);
2805   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_infty));
2806   check ("real(casin(-Inf - i Inf)) = -pi/4", __real__ result, -M_PI_4);
2807   check_isinfn ("imag(casin(-Inf - i Inf)) = -Inf", __imag__ result);
2808
2809   result = FUNC(casin) (BUILD_COMPLEX (-10.0, plus_infty));
2810   check ("real(casin(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
2811   check_isinfp ("imag(casin(-10.0 + i Inf)) = +Inf", __imag__ result);
2812   result = FUNC(casin) (BUILD_COMPLEX (-10.0, minus_infty));
2813   check ("real(casin(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
2814   check_isinfn ("imag(casin(-10.0 - i Inf)) = -Inf", __imag__ result);
2815   result = FUNC(casin) (BUILD_COMPLEX (0, plus_infty));
2816   check ("real(casin(0 + i Inf)) = 0", __real__ result, 0.0);
2817   check_isinfp ("imag(casin(0 + i Inf)) = +Inf", __imag__ result);
2818   result = FUNC(casin) (BUILD_COMPLEX (0, minus_infty));
2819   check ("real(casin(0 - i Inf)) = 0", __real__ result, 0.0);
2820   check_isinfn ("imag(casin(0 - i Inf)) = -Inf", __imag__ result);
2821   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, plus_infty));
2822   check ("real(casin(-0 + i Inf)) = -0", __real__ result, minus_zero);
2823   check_isinfp ("imag(casin(-0 + i Inf)) = +Inf", __imag__ result);
2824   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_infty));
2825   check ("real(casin(-0 - i Inf)) = -0", __real__ result, minus_zero);
2826   check_isinfn ("imag(casin(-0 - i Inf)) = -Inf", __imag__ result);
2827   result = FUNC(casin) (BUILD_COMPLEX (0.1, plus_infty));
2828   check ("real(casin(0.1 + i Inf)) = 0", __real__ result, 0);
2829   check_isinfp ("imag(casin(0.1 + i Inf)) = +Inf", __imag__ result);
2830   result = FUNC(casin) (BUILD_COMPLEX (0.1, minus_infty));
2831   check ("real(casin(0.1 - i Inf)) = 0", __real__ result, 0);
2832   check_isinfn ("imag(casin(0.1 - i Inf)) = -Inf", __imag__ result);
2833
2834   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 0));
2835   check ("real(casin(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2);
2836   check_isinfp ("imag(casin(-Inf + i0)) = +Inf", __imag__ result);
2837   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_zero));
2838   check ("real(casin(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2);
2839   check_isinfn ("imag(casin(-Inf - i0)) = -Inf", __imag__ result);
2840   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 100));
2841   check ("real(casin(-Inf + i100)) = -pi/2", __real__ result, -M_PI_2);
2842   check_isinfp ("imag(casin(-Inf + i100)) = +Inf", __imag__ result);
2843   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, -100));
2844   check ("real(casin(-Inf - i100)) = -pi/2", __real__ result, -M_PI_2);
2845   check_isinfn ("imag(casin(-Inf - i100)) = -Inf", __imag__ result);
2846
2847   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0));
2848   check ("real(casin(+Inf + i0)) = pi/2", __real__ result, M_PI_2);
2849   check_isinfp ("imag(casin(+Inf + i0)) = +Inf", __imag__ result);
2850   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_zero));
2851   check ("real(casin(+Inf - i0)) = pi/2", __real__ result, M_PI_2);
2852   check_isinfn ("imag(casin(+Inf - i0)) = -Inf", __imag__ result);
2853   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0.5));
2854   check ("real(casin(+Inf + i0.5)) = pi/2", __real__ result, M_PI_2);
2855   check_isinfp ("imag(casin(+Inf + i0.5)) = +Inf", __imag__ result);
2856   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, -0.5));
2857   check ("real(casin(+Inf - i0.5)) = pi/2", __real__ result, M_PI_2);
2858   check_isinfn ("imag(casin(+Inf - i0.5)) = -Inf", __imag__ result);
2859
2860   result = FUNC(casin) (BUILD_COMPLEX (nan_value, plus_infty));
2861   check_isnan ("real(casin(NaN + i Inf)) = NaN", __real__ result);
2862   check_isinfp ("imag(casin(NaN + i Inf)) = +Inf", __imag__ result);
2863   result = FUNC(casin) (BUILD_COMPLEX (nan_value, minus_infty));
2864   check_isnan ("real(casin(NaN - i Inf)) = NaN", __real__ result);
2865   check_isinfn ("imag(casin(NaN - i Inf)) = -Inf", __imag__ result);
2866
2867   result = FUNC(casin) (BUILD_COMPLEX (0.0, nan_value));
2868   check ("real(casin(0 + i NaN)) = 0", __real__ result, 0.0);
2869   check_isnan ("imag(casin(0 + i NaN)) = NaN", __imag__ result);
2870   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, nan_value));
2871   check ("real(casin(-0 + i NaN)) = -0", __real__ result, minus_zero);
2872   check_isnan ("imag(casin(-0 + i NaN)) = NaN", __imag__ result);
2873
2874   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, nan_value));
2875   check_isnan ("real(casin(+Inf + i NaN)) = NaN", __real__ result);
2876   check_isinfp ("imag(casin(+Inf + i NaN)) = +-Inf",
2877                 FUNC(fabs) (__imag__ result));
2878   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, nan_value));
2879   check_isnan ("real(casin(-Inf + i NaN)) = NaN", __real__ result);
2880   check_isinfp ("imag(casin(-Inf + NaN)) = +-Inf",
2881                 FUNC(fabs) (__imag__ result));
2882
2883   result = FUNC(casin) (BUILD_COMPLEX (nan_value, 10.5));
2884   check_isnan_maybe_exc ("real(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
2885                          __real__ result, FE_INVALID);
2886   check_isnan ("imag(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
2887                __imag__ result);
2888   result = FUNC(casin) (BUILD_COMPLEX (nan_value, -10.5));
2889   check_isnan_maybe_exc ("real(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
2890                          __real__ result, FE_INVALID);
2891   check_isnan ("imag(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
2892                __imag__ result);
2893
2894   result = FUNC(casin) (BUILD_COMPLEX (0.75, nan_value));
2895   check_isnan_maybe_exc ("real(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
2896                          __real__ result, FE_INVALID);
2897   check_isnan ("imag(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
2898                __imag__ result);
2899   result = FUNC(casin) (BUILD_COMPLEX (-0.75, nan_value));
2900   check_isnan_maybe_exc ("real(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
2901                          __real__ result, FE_INVALID);
2902   check_isnan ("imag(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
2903                __imag__ result);
2904
2905   result = FUNC(casin) (BUILD_COMPLEX (nan_value, nan_value));
2906   check_isnan ("real(casin(NaN + i NaN)) = NaN", __real__ result);
2907   check_isnan ("imag(casin(NaN + i NaN)) = NaN", __imag__ result);
2908 }
2909
2910
2911 static void
2912 casinh_test (void)
2913 {
2914   __complex__ MATHTYPE result;
2915
2916   result = FUNC(casinh) (BUILD_COMPLEX (0, 0));
2917   check ("real(casinh(0 + i0)) = 0", __real__ result, 0);
2918   check ("imag(casinh(0 + i0)) = 0", __imag__ result, 0);
2919   result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, 0));
2920   check ("real(casinh(-0 + i0)) = -0", __real__ result, minus_zero);
2921   check ("imag(casinh(-0 + i0)) = 0", __imag__ result, 0);
2922   result = FUNC(casinh) (BUILD_COMPLEX (0, minus_zero));
2923   check ("real(casinh(0 - i0)) = 0", __real__ result, 0);
2924   check ("imag(casinh(0 - i0)) = -0", __imag__ result, minus_zero);
2925   result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_zero));
2926   check ("real(casinh(-0 - i0)) = -0", __real__ result, minus_zero);
2927   check ("imag(casinh(-0 - i0)) = -0", __imag__ result, minus_zero);
2928
2929   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, plus_infty));
2930   check_isinfp ("real(casinh(+Inf + i Inf)) = +Inf", __real__ result);
2931   check ("imag(casinh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
2932   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_infty));
2933   check_isinfp ("real(casinh(+Inf - i Inf)) = +Inf", __real__ result);
2934   check ("imag(casinh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
2935   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, plus_infty));
2936   check_isinfn ("real(casinh(-Inf + i Inf)) = -Inf", __real__ result);
2937   check ("imag(casinh(-Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
2938   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_infty));
2939   check_isinfn ("real(casinh(-Inf - i Inf)) = -Inf", __real__ result);
2940   check ("imag(casinh(-Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
2941
2942   result = FUNC(casinh) (BUILD_COMPLEX (-10.0, plus_infty));
2943   check_isinfn ("real(casinh(-10.0 + i Inf)) = -Inf", __real__ result);
2944   check ("imag(casinh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2945   result = FUNC(casinh) (BUILD_COMPLEX (-10.0, minus_infty));
2946   check_isinfn ("real(casinh(-10.0 - i Inf)) = -Inf", __real__ result);
2947   check ("imag(casinh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2948   result = FUNC(casinh) (BUILD_COMPLEX (0, plus_infty));
2949   check_isinfp ("real(casinh(0 + i Inf)) = +Inf", __real__ result);
2950   check ("imag(casinh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2951   result = FUNC(casinh) (BUILD_COMPLEX (0, minus_infty));
2952   check_isinfp ("real(casinh(0 - i Inf)) = +Inf", __real__ result);
2953   check ("imag(casinh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2954   result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, plus_infty));
2955   check_isinfn ("real(casinh(-0 + i Inf)) = -Inf", __real__ result);
2956   check ("imag(casinh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2957   result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_infty));
2958   check_isinfn ("real(casinh(-0 - i Inf)) = -Inf", __real__ result);
2959   check ("imag(casinh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2960   result = FUNC(casinh) (BUILD_COMPLEX (0.1, plus_infty));
2961   check_isinfp ("real(casinh(0.1 + i Inf)) = +Inf", __real__ result);
2962   check ("imag(casinh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2963   result = FUNC(casinh) (BUILD_COMPLEX (0.1, minus_infty));
2964   check_isinfp ("real(casinh(0.1 - i Inf)) = +Inf", __real__ result);
2965   check ("imag(casinh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2966
2967   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 0));
2968   check_isinfn ("real(casinh(-Inf + i0)) = -Inf", __real__ result);
2969   check ("imag(casinh(-Inf + i0)) = 0", __imag__ result, 0);
2970   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_zero));
2971   check_isinfn ("real(casinh(-Inf - i0)) = -Inf", __real__ result);
2972   check ("imag(casinh(-Inf - i0)) = -0", __imag__ result, minus_zero);
2973   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 100));
2974   check_isinfn ("real(casinh(-Inf + i100)) = -Inf", __real__ result);
2975   check ("imag(casinh(-Inf + i100)) = 0", __imag__ result, 0);
2976   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, -100));
2977   check_isinfn ("real(casinh(-Inf - i100)) = -Inf", __real__ result);
2978   check ("imag(casinh(-Inf - i100)) = -0", __imag__ result, minus_zero);
2979
2980   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0));
2981   check_isinfp ("real(casinh(+Inf + i0)) = +Inf", __real__ result);
2982   check ("imag(casinh(+Inf + i0)) = 0", __imag__ result, 0);
2983   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_zero));
2984   check_isinfp ("real(casinh(+Inf - i0)) = +Inf", __real__ result);
2985   check ("imag(casinh(+Inf - i0)) = -0", __imag__ result, minus_zero);
2986   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0.5));
2987   check_isinfp ("real(casinh(+Inf + i0.5)) = +Inf", __real__ result);
2988   check ("imag(casinh(+Inf + i0.5)) = 0", __imag__ result, 0);
2989   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, -0.5));
2990   check_isinfp ("real(casinh(+Inf - i0.5)) = +Inf", __real__ result);
2991   check ("imag(casinh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
2992
2993   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, nan_value));
2994   check_isinfp ("real(casinh(+Inf + i NaN)) = +Inf", __real__ result);
2995   check_isnan ("imag(casinh(+Inf + i NaN)) = NaN", __imag__ result);
2996   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, nan_value));
2997   check_isinfn ("real(casinh(-Inf + i NaN)) = -Inf", __real__ result);
2998   check_isnan ("imag(casinh(-Inf + i NaN)) = NaN", __imag__ result);
2999
3000   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0));
3001   check_isnan ("real(casinh(NaN + i0)) = NaN", __real__ result);
3002   check ("imag(casinh(NaN + i0)) = 0", __imag__ result, 0);
3003   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_zero));
3004   check_isnan ("real(casinh(NaN - i0)) = NaN", __real__ result);
3005   check ("imag(casinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3006
3007   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, plus_infty));
3008   check_isinfp ("real(casinh(NaN + i Inf)) = +-Inf",
3009                 FUNC(fabs) (__real__ result));
3010   check_isnan ("imag(casinh(NaN + i Inf)) = NaN", __imag__ result);
3011   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_infty));
3012   check_isinfp ("real(casinh(NaN - i Inf)) = +-Inf",
3013                 FUNC(fabs) (__real__ result));
3014   check_isnan ("imag(casinh(NaN - i Inf)) = NaN", __imag__ result);
3015
3016   result = FUNC(casinh) (BUILD_COMPLEX (10.5, nan_value));
3017   check_isnan_maybe_exc ("real(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3018                          __real__ result, FE_INVALID);
3019   check_isnan ("imag(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3020                __imag__ result);
3021   result = FUNC(casinh) (BUILD_COMPLEX (-10.5, nan_value));
3022   check_isnan_maybe_exc ("real(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3023                          __real__ result, FE_INVALID);
3024   check_isnan ("imag(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3025                __imag__ result);
3026
3027   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0.75));
3028   check_isnan_maybe_exc ("real(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
3029                          __real__ result, FE_INVALID);
3030   check_isnan ("imag(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
3031                __imag__ result);
3032   result = FUNC(casinh) (BUILD_COMPLEX (-0.75, nan_value));
3033   check_isnan_maybe_exc ("real(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
3034                          __real__ result, FE_INVALID);
3035   check_isnan ("imag(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
3036                __imag__ result);
3037
3038   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, nan_value));
3039   check_isnan ("real(casinh(NaN + i NaN)) = NaN", __real__ result);
3040   check_isnan ("imag(casinh(NaN + i NaN)) = NaN", __imag__ result);
3041 }
3042
3043
3044 static void
3045 catan_test (void)
3046 {
3047   __complex__ MATHTYPE result;
3048
3049   result = FUNC(catan) (BUILD_COMPLEX (0, 0));
3050   check ("real(catan(0 + i0)) = 0", __real__ result, 0);
3051   check ("imag(catan(0 + i0)) = 0", __imag__ result, 0);
3052   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, 0));
3053   check ("real(catan(-0 + i0)) = -0", __real__ result, minus_zero);
3054   check ("imag(catan(-0 + i0)) = 0", __imag__ result, 0);
3055   result = FUNC(catan) (BUILD_COMPLEX (0, minus_zero));
3056   check ("real(catan(0 - i0)) = 0", __real__ result, 0);
3057   check ("imag(catan(0 - i0)) = -0", __imag__ result, minus_zero);
3058   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_zero));
3059   check ("real(catan(-0 - i0)) = -0", __real__ result, minus_zero);
3060   check ("imag(catan(-0 - i0)) = -0", __imag__ result, minus_zero);
3061
3062   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, plus_infty));
3063   check ("real(catan(+Inf + i Inf)) = pi/2", __real__ result, M_PI_2);
3064   check ("imag(catan(+Inf + i Inf)) = 0", __imag__ result, 0);
3065   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_infty));
3066   check ("real(catan(+Inf - i Inf)) = pi/2", __real__ result, M_PI_2);
3067   check ("imag(catan(+Inf - i Inf)) = -0", __imag__ result, minus_zero);
3068   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, plus_infty));
3069   check ("real(catan(-Inf + i Inf)) = -pi/2", __real__ result, -M_PI_2);
3070   check ("imag(catan(-Inf + i Inf)) = 0", __imag__ result, 0.0);
3071   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_infty));
3072   check ("real(catan(-Inf - i Inf)) = -pi/2", __real__ result, -M_PI_2);
3073   check ("imag(catan(-Inf - i Inf)) = -0", __imag__ result, minus_zero);
3074
3075   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, -10.0));
3076   check ("real(catan(+Inf - i10.0)) = pi/2", __real__ result, M_PI_2);
3077   check ("imag(catan(+Inf - i10.0)) = -0", __imag__ result, minus_zero);
3078   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, -10.0));
3079   check ("real(catan(-Inf - i10.0)) = -pi/2", __real__ result, -M_PI_2);
3080   check ("imag(catan(-Inf - i10.0)) = -0", __imag__ result, minus_zero);
3081   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_zero));
3082   check ("real(catan(Inf - i0)) = pi/2", __real__ result, M_PI_2);
3083   check ("imag(catan(Inf - i0)) = -0", __imag__ result, minus_zero);
3084   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_zero));
3085   check ("real(catan(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2);
3086   check ("imag(catan(-Inf - i0)) = -0", __imag__ result, minus_zero);
3087   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.0));
3088   check ("real(catan(Inf + i0)) = pi/2", __real__ result, M_PI_2);
3089   check ("imag(catan(Inf + i0)) = 0", __imag__ result, 0.0);
3090   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.0));
3091   check ("real(catan(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2);
3092   check ("imag(catan(-Inf + i0)) = 0", __imag__ result, 0.0);
3093   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.1));
3094   check ("real(catan(+Inf + i0.1)) = pi/2", __real__ result, M_PI_2);
3095   check ("imag(catan(+Inf + i0.1)) = 0", __imag__ result, 0);
3096   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.1));
3097   check ("real(catan(-Inf + i0.1)) = -pi/2", __real__ result, -M_PI_2);
3098   check ("imag(catan(-Inf + i0.1)) = 0", __imag__ result, 0);
3099
3100   result = FUNC(catan) (BUILD_COMPLEX (0.0, minus_infty));
3101   check ("real(catan(0 - i Inf)) = pi/2", __real__ result, M_PI_2);
3102   check ("imag(catan(0 - i Inf)) = -0", __imag__ result, minus_zero);
3103   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_infty));
3104   check ("real(catan(-0 - i Inf)) = -pi/2", __real__ result, -M_PI_2);
3105   check ("imag(catan(-0 - i Inf)) = -0", __imag__ result, minus_zero);
3106   result = FUNC(catan) (BUILD_COMPLEX (100.0, minus_infty));
3107   check ("real(catan(100 - i Inf)) = pi/2", __real__ result, M_PI_2);
3108   check ("imag(catan(100 - i Inf)) = -0", __imag__ result, minus_zero);
3109   result = FUNC(catan) (BUILD_COMPLEX (-100.0, minus_infty));
3110   check ("real(catan(-100 - i Inf)) = -pi/2", __real__ result, -M_PI_2);
3111   check ("imag(catan(-100 - i Inf)) = -0", __imag__ result, minus_zero);
3112
3113   result = FUNC(catan) (BUILD_COMPLEX (0.0, plus_infty));
3114   check ("real(catan(0 + i Inf)) = pi/2", __real__ result, M_PI_2);
3115   check ("imag(catan(0 + i Inf)) = 0", __imag__ result, 0);
3116   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, plus_infty));
3117   check ("real(catan(-0 + i Inf)) = -pi/2", __real__ result, -M_PI_2);
3118   check ("imag(catan(-0 + i Inf)) = 0", __imag__ result, 0);
3119   result = FUNC(catan) (BUILD_COMPLEX (0.5, plus_infty));
3120   check ("real(catan(0.5 + i Inf)) = pi/2", __real__ result, M_PI_2);
3121   check ("imag(catan(0.5 + i Inf)) = 0", __imag__ result, 0);
3122   result = FUNC(catan) (BUILD_COMPLEX (-0.5, plus_infty));
3123   check ("real(catan(-0.5 + i Inf)) = -pi/2", __real__ result, -M_PI_2);
3124   check ("imag(catan(-0.5 + i Inf)) = 0", __imag__ result, 0);
3125
3126   result = FUNC(catan) (BUILD_COMPLEX (nan_value, 0.0));
3127   check_isnan ("real(catan(NaN + i0)) = NaN", __real__ result);
3128   check ("imag(catan(NaN + i0)) = 0", __imag__ result, 0.0);
3129   result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_zero));
3130   check_isnan ("real(catan(NaN - i0)) = NaN", __real__ result);
3131   check ("imag(catan(NaN - i0)) = -0", __imag__ result, minus_zero);
3132
3133   result = FUNC(catan) (BUILD_COMPLEX (nan_value, plus_infty));
3134   check_isnan ("real(catan(NaN + i Inf)) = NaN", __real__ result);
3135   check ("imag(catan(NaN + i Inf)) = 0", __imag__ result, 0);
3136   result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_infty));
3137   check_isnan ("real(catan(NaN - i Inf)) = NaN", __real__ result);
3138   check ("imag(catan(NaN - i Inf)) = -0", __imag__ result, minus_zero);
3139
3140   result = FUNC(catan) (BUILD_COMPLEX (0.0, nan_value));
3141   check_isnan ("real(catan(0 + i NaN)) = NaN", __real__ result);
3142   check_isnan ("imag(catan(0 + i NaN)) = NaN", __imag__ result);
3143   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, nan_value));
3144   check_isnan ("real(catan(-0 + i NaN)) = NaN", __real__ result);
3145   check_isnan ("imag(catan(-0 + i NaN)) = NaN", __imag__ result);
3146
3147   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, nan_value));
3148   check ("real(catan(+Inf + i NaN)) = pi/2", __real__ result, M_PI_2);
3149   check ("imag(catan(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3150   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, nan_value));
3151   check ("real(catan(-Inf + i NaN)) = -pi/2", __real__ result, -M_PI_2);
3152   check ("imag(catan(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3153
3154   result = FUNC(catan) (BUILD_COMPLEX (nan_value, 10.5));
3155   check_isnan_maybe_exc ("real(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
3156                          __real__ result, FE_INVALID);
3157   check_isnan ("imag(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
3158                __imag__ result);
3159   result = FUNC(catan) (BUILD_COMPLEX (nan_value, -10.5));
3160   check_isnan_maybe_exc ("real(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
3161                          __real__ result, FE_INVALID);
3162   check_isnan ("imag(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
3163                __imag__ result);
3164
3165   result = FUNC(catan) (BUILD_COMPLEX (0.75, nan_value));
3166   check_isnan_maybe_exc ("real(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
3167                          __real__ result, FE_INVALID);
3168   check_isnan ("imag(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
3169                __imag__ result);
3170   result = FUNC(catan) (BUILD_COMPLEX (-0.75, nan_value));
3171   check_isnan_maybe_exc ("real(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3172                          __real__ result, FE_INVALID);
3173   check_isnan ("imag(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3174                __imag__ result);
3175
3176   result = FUNC(catan) (BUILD_COMPLEX (nan_value, nan_value));
3177   check_isnan ("real(catan(NaN + i NaN)) = NaN", __real__ result);
3178   check_isnan ("imag(catan(NaN + i NaN)) = NaN", __imag__ result);
3179 }
3180
3181
3182 static void
3183 catanh_test (void)
3184 {
3185   __complex__ MATHTYPE result;
3186
3187   result = FUNC(catanh) (BUILD_COMPLEX (0, 0));
3188   check ("real(catanh(0 + i0)) = 0", __real__ result, 0);
3189   check ("imag(catanh(0 + i0)) = 0", __imag__ result, 0);
3190   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, 0));
3191   check ("real(catanh(-0 + i0)) = -0", __real__ result, minus_zero);
3192   check ("imag(catanh(-0 + i0)) = 0", __imag__ result, 0);
3193   result = FUNC(catanh) (BUILD_COMPLEX (0, minus_zero));
3194   check ("real(catanh(0 - i0)) = 0", __real__ result, 0);
3195   check ("imag(catanh(0 - i0)) = -0", __imag__ result, minus_zero);
3196   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_zero));
3197   check ("real(catanh(-0 - i0)) = -0", __real__ result, minus_zero);
3198   check ("imag(catanh(-0 - i0)) = -0", __imag__ result, minus_zero);
3199
3200   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, plus_infty));
3201   check ("real(catanh(+Inf + i Inf)) = 0", __real__ result, 0);
3202   check ("imag(catanh(+Inf + i Inf)) = pi/2", __imag__ result, M_PI_2);
3203   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_infty));
3204   check ("real(catanh(+Inf - i Inf)) = 0", __real__ result, 0);
3205   check ("imag(catanh(+Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3206   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, plus_infty));
3207   check ("real(catanh(-Inf + i Inf)) = -0", __real__ result, minus_zero);
3208   check ("imag(catanh(-Inf + i Inf)) = pi/2", __imag__ result, M_PI_2);
3209   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_infty));
3210   check ("real(catanh(-Inf - i Inf)) = -0", __real__ result, minus_zero);
3211   check ("imag(catanh(-Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3212
3213   result = FUNC(catanh) (BUILD_COMPLEX (-10.0, plus_infty));
3214   check ("real(catanh(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
3215   check ("imag(catanh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3216   result = FUNC(catanh) (BUILD_COMPLEX (-10.0, minus_infty));
3217   check ("real(catanh(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
3218   check ("imag(catanh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3219   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, plus_infty));
3220   check ("real(catanh(-0 + i Inf)) = -0", __real__ result, minus_zero);
3221   check ("imag(catanh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3222   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_infty));
3223   check ("real(catanh(-0 - i Inf)) = -0", __real__ result, minus_zero);
3224   check ("imag(catanh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3225   result = FUNC(catanh) (BUILD_COMPLEX (0, plus_infty));
3226   check ("real(catanh(0 + i Inf)) = 0", __real__ result, 0);
3227   check ("imag(catanh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3228   result = FUNC(catanh) (BUILD_COMPLEX (0, minus_infty));
3229   check ("real(catanh(0 - i Inf)) = 0", __real__ result, 0);
3230   check ("imag(catanh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3231   result = FUNC(catanh) (BUILD_COMPLEX (0.1, plus_infty));
3232   check ("real(catanh(0.1 + i Inf)) = 0", __real__ result, 0);
3233   check ("imag(catanh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3234   result = FUNC(catanh) (BUILD_COMPLEX (0.1, minus_infty));
3235   check ("real(catanh(0.1 - i Inf)) = 0", __real__ result, 0);
3236   check ("imag(catanh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3237
3238   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 0));
3239   check ("real(catanh(-Inf + i0)) = -0", __real__ result, minus_zero);
3240   check ("imag(catanh(-Inf + i0)) = pi/2", __imag__ result, M_PI_2);
3241   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_zero));
3242   check ("real(catanh(-Inf - i0)) = -0", __real__ result, minus_zero);
3243   check ("imag(catanh(-Inf - i0)) = -pi/2", __imag__ result, -M_PI_2);
3244   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 100));
3245   check ("real(catanh(-Inf + i100)) = -0", __real__ result, minus_zero);
3246   check ("imag(catanh(-Inf + i100)) = pi/2", __imag__ result, M_PI_2);
3247   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, -100));
3248   check ("real(catanh(-Inf - i100)) = -0", __real__ result, minus_zero);
3249   check ("imag(catanh(-Inf - i100)) = -pi/2", __imag__ result, -M_PI_2);
3250
3251   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0));
3252   check ("real(catanh(+Inf + i0)) = 0", __real__ result, 0);
3253   check ("imag(catanh(+Inf + i0)) = pi/2", __imag__ result, M_PI_2);
3254   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_zero));
3255   check ("real(catanh(+Inf - i0)) = 0", __real__ result, 0);
3256   check ("imag(catanh(+Inf - i0)) = -pi/2", __imag__ result, -M_PI_2);
3257   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0.5));
3258   check ("real(catanh(+Inf + i0.5)) = 0", __real__ result, 0);
3259   check ("imag(catanh(+Inf + i0.5)) = pi/2", __imag__ result, M_PI_2);
3260   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, -0.5));
3261   check ("real(catanh(+Inf - i0.5)) = 0", __real__ result, 0);
3262   check ("imag(catanh(+Inf - i0.5)) = -pi/2", __imag__ result, -M_PI_2);
3263
3264   result = FUNC(catanh) (BUILD_COMPLEX (0, nan_value));
3265   check ("real(catanh(0 + i NaN)) = 0", __real__ result, 0);
3266   check_isnan ("imag(catanh(0 + i NaN)) = NaN", __imag__ result);
3267   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, nan_value));
3268   check ("real(catanh(-0 + i NaN)) = -0", __real__ result, minus_zero);
3269   check_isnan ("imag(catanh(-0 + i NaN)) = NaN", __imag__ result);
3270
3271   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, nan_value));
3272   check ("real(catanh(+Inf + i NaN)) = 0", __real__ result, 0);
3273   check_isnan ("imag(catanh(+Inf + i NaN)) = NaN", __imag__ result);
3274   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, nan_value));
3275   check ("real(catanh(-Inf + i NaN)) = -0", __real__ result, minus_zero);
3276   check_isnan ("imag(catanh(-Inf + i NaN)) = NaN", __imag__ result);
3277
3278   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0));
3279   check_isnan ("real(catanh(NaN + i0)) = NaN", __real__ result);
3280   check_isnan ("imag(catanh(NaN + i0)) = NaN", __imag__ result);
3281   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_zero));
3282   check_isnan ("real(catanh(NaN - i0)) = NaN", __real__ result);
3283   check_isnan ("imag(catanh(NaN - i0)) = NaN", __imag__ result);
3284
3285   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, plus_infty));
3286   check ("real(catanh(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
3287   check ("imag(catanh(NaN + i Inf)) = pi/2", __imag__ result, M_PI_2);
3288   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_infty));
3289   check ("real(catanh(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
3290   check ("imag(catanh(NaN - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3291
3292   result = FUNC(catanh) (BUILD_COMPLEX (10.5, nan_value));
3293   check_isnan_maybe_exc ("real(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3294                          __real__ result, FE_INVALID);
3295   check_isnan ("imag(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3296                __imag__ result);
3297   result = FUNC(catanh) (BUILD_COMPLEX (-10.5, nan_value));
3298   check_isnan_maybe_exc ("real(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3299                          __real__ result, FE_INVALID);
3300   check_isnan ("imag(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3301                __imag__ result);
3302
3303   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0.75));
3304   check_isnan_maybe_exc ("real(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
3305                          __real__ result, FE_INVALID);
3306   check_isnan ("imag(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
3307                __imag__ result);
3308   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, -0.75));
3309   check_isnan_maybe_exc ("real(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
3310                          __real__ result, FE_INVALID);
3311   check_isnan ("imag(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
3312                __imag__ result);
3313
3314   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, nan_value));
3315   check_isnan ("real(catanh(NaN + i NaN)) = NaN", __real__ result);
3316   check_isnan ("imag(catanh(NaN + i NaN)) = NaN", __imag__ result);
3317 }
3318
3319
3320 static void
3321 ctanh_test (void)
3322 {
3323   __complex__ MATHTYPE result;
3324
3325   result = FUNC(ctanh) (BUILD_COMPLEX (0, 0));
3326   check ("real(ctanh(0 + i0)) = 0", __real__ result, 0);
3327   check ("imag(ctanh(0 + i0)) = 0", __imag__ result, 0);
3328   result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_zero));
3329   check ("real(ctanh(0 - i0)) = 0", __real__ result, 0);
3330   check ("imag(ctanh(0 - i0)) = -0", __imag__ result, minus_zero);
3331   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, 0));
3332   check ("real(ctanh(-0 + i0)) = -0", __real__ result, minus_zero);
3333   check ("imag(ctanh(-0 + i0)) = 0", __imag__ result, 0);
3334   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_zero));
3335   check ("real(ctanh(-0 - i0)) = -0", __real__ result, minus_zero);
3336   check ("imag(ctanh(-0 - i0)) = -0", __imag__ result, minus_zero);
3337
3338   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 0));
3339   check ("real(ctanh(+Inf + i0)) = 1", __real__ result, 1);
3340   check ("imag(ctanh(+Inf + i0)) = 0", __imag__ result, 0);
3341   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 1));
3342   check ("real(ctanh(+Inf + i1)) = 1", __real__ result, 1);
3343   check ("imag(ctanh(+Inf + i1)) = 0", __imag__ result, 0);
3344   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, minus_zero));
3345   check ("real(ctanh(+Inf - i0)) = 1", __real__ result, 1);
3346   check ("imag(ctanh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3347   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, -1));
3348   check ("real(ctanh(+Inf - i1)) = 1", __real__ result, 1);
3349   check ("imag(ctanh(+Inf - i1)) = -0", __imag__ result, minus_zero);
3350   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 0));
3351   check ("real(ctanh(-Inf + i0)) = -1", __real__ result, -1);
3352   check ("imag(ctanh(-Inf + i0)) = 0", __imag__ result, 0);
3353   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 1));
3354   check ("real(ctanh(-Inf + i1)) = -1", __real__ result, -1);
3355   check ("imag(ctanh(-Inf + i1)) = 0", __imag__ result, 0);
3356   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, minus_zero));
3357   check ("real(ctanh(-Inf - i0)) = -1", __real__ result, -1);
3358   check ("imag(ctanh(-Inf - i0)) = -0", __imag__ result, minus_zero);
3359   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, -1));
3360   check ("real(ctanh(-Inf - i1)) = -1", __real__ result, -1);
3361   check ("imag(ctanh(-Inf - i1)) = -0", __imag__ result, minus_zero);
3362
3363   result = FUNC(ctanh) (BUILD_COMPLEX (0, plus_infty));
3364   check_isnan_exc ("real(ctanh(0 + i Inf)) = NaN plus invalid exception",
3365                    __real__ result, FE_INVALID);
3366   check_isnan ("imag(ctanh(0 + i Inf)) = NaN plus invalid exception",
3367                __imag__ result);
3368   result = FUNC(ctanh) (BUILD_COMPLEX (2, plus_infty));
3369   check_isnan_exc ("real(ctanh(2 + i Inf)) = NaN plus invalid exception",
3370                    __real__ result, FE_INVALID);
3371   check_isnan ("imag(ctanh(2 + i Inf)) = NaN plus invalid exception",
3372                __imag__ result);
3373   result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_infty));
3374   check_isnan_exc ("real(ctanh(0 - i Inf)) = NaN plus invalid exception",
3375                    __real__ result, FE_INVALID);
3376   check_isnan ("imag(ctanh(0 - i Inf)) = NaN plus invalid exception",
3377                __imag__ result);
3378   result = FUNC(ctanh) (BUILD_COMPLEX (2, minus_infty));
3379   check_isnan_exc ("real(ctanh(2 - i Inf)) = NaN plus invalid exception",
3380                    __real__ result, FE_INVALID);
3381   check_isnan ("imag(ctanh(2 - i Inf)) = NaN plus invalid exception",
3382                __imag__ result);
3383   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, plus_infty));
3384   check_isnan_exc ("real(ctanh(-0 + i Inf)) = NaN plus invalid exception",
3385                    __real__ result, FE_INVALID);
3386   check_isnan ("imag(ctanh(-0 + i Inf)) = NaN plus invalid exception",
3387                __imag__ result);
3388   result = FUNC(ctanh) (BUILD_COMPLEX (-2, plus_infty));
3389   check_isnan_exc ("real(ctanh(-2 + i Inf)) = NaN plus invalid exception",
3390                    __real__ result, FE_INVALID);
3391   check_isnan ("imag(ctanh(-2 + i Inf)) = NaN plus invalid exception",
3392                __imag__ result);
3393   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_infty));
3394   check_isnan_exc ("real(ctanh(-0 - i Inf)) = NaN plus invalid exception",
3395                    __real__ result, FE_INVALID);
3396   check_isnan ("imag(ctanh(-0 - i Inf)) = NaN plus invalid exception",
3397                __imag__ result);
3398   result = FUNC(ctanh) (BUILD_COMPLEX (-2, minus_infty));
3399   check_isnan_exc ("real(ctanh(-2 - i Inf)) = NaN plus invalid exception",
3400                    __real__ result, FE_INVALID);
3401   check_isnan ("imag(ctanh(-2 - i Inf)) = NaN plus invalid exception",
3402                __imag__ result);
3403
3404   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, nan_value));
3405   check ("real(ctanh(+Inf + i NaN)) = 1", __real__ result, 1);
3406   check ("imag(ctanh(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3407   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, nan_value));
3408   check ("real(ctanh(-Inf + i NaN)) = -1", __real__ result, -1);
3409   check ("imag(ctanh(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3410
3411   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0));
3412   check_isnan ("real(ctanh(NaN + i0)) = NaN", __real__ result);
3413   check ("imag(ctanh(NaN + i0)) = 0", __imag__ result, 0);
3414   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, minus_zero));
3415   check_isnan ("real(ctanh(NaN - i0)) = NaN", __real__ result);
3416   check ("imag(ctanh(NaN - i0)) = -0", __imag__ result, minus_zero);
3417
3418   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0.5));
3419   check_isnan_maybe_exc ("real(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
3420                          __real__ result, FE_INVALID);
3421   check_isnan ("imag(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
3422                __imag__ result);
3423   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, -4.5));
3424   check_isnan_maybe_exc ("real(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
3425                          __real__ result, FE_INVALID);
3426   check_isnan ("imag(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
3427                __imag__ result);
3428
3429   result = FUNC(ctanh) (BUILD_COMPLEX (0, nan_value));
3430   check_isnan_maybe_exc ("real(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
3431                          __real__ result, FE_INVALID);
3432   check_isnan ("imag(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
3433                __imag__ result);
3434   result = FUNC(ctanh) (BUILD_COMPLEX (5, nan_value));
3435   check_isnan_maybe_exc ("real(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
3436                          __real__ result, FE_INVALID);
3437   check_isnan ("imag(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
3438                __imag__ result);
3439   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, nan_value));
3440   check_isnan_maybe_exc ("real(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
3441                          __real__ result, FE_INVALID);
3442   check_isnan ("imag(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
3443                __imag__ result);
3444   result = FUNC(ctanh) (BUILD_COMPLEX (-0.25, nan_value));
3445   check_isnan_maybe_exc ("real(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
3446                          __real__ result, FE_INVALID);
3447   check_isnan ("imag(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
3448                __imag__ result);
3449
3450   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, nan_value));
3451   check_isnan ("real(ctanh(NaN + i NaN)) = NaN", __real__ result);
3452   check_isnan ("imag(ctanh(NaN + i NaN)) = NaN", __imag__ result);
3453 }
3454
3455
3456 static void
3457 clog_test (void)
3458 {
3459   __complex__ MATHTYPE result;
3460
3461   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, 0));
3462   check_isinfn_exc ("real(clog(-0 + i0)) = -Inf plus divide-by-zero exception",
3463                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
3464   check ("imag(clog(-0 + i0)) = pi plus divide-by-zero exception",
3465          __imag__ result, M_PI);
3466   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_zero));
3467   check_isinfn_exc ("real(clog(-0 - i0)) = -Inf plus divide-by-zero exception",
3468                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
3469   check ("imag(clog(-0 - i0)) = -pi plus divide-by-zero exception",
3470          __imag__ result, -M_PI);
3471
3472   result = FUNC(clog) (BUILD_COMPLEX (0, 0));
3473   check_isinfn_exc ("real(clog(0 + i0)) = -Inf plus divide-by-zero exception",
3474                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
3475   check ("imag(clog(0 + i0)) = 0 plus divide-by-zero exception",
3476          __imag__ result, 0);
3477   result = FUNC(clog) (BUILD_COMPLEX (0, minus_zero));
3478   check_isinfn_exc ("real(clog(0 - i0)) = -Inf plus divide-by-zero exception",
3479                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
3480   check ("imag(clog(0 - i0)) = -0 plus divide-by-zero exception",
3481          __imag__ result, minus_zero);
3482
3483   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, plus_infty));
3484   check_isinfp ("real(clog(-Inf + i Inf)) = +Inf", __real__ result);
3485   check ("imag(clog(-Inf + i Inf)) = 3*pi/4", __imag__ result, M_PI - M_PI_4);
3486   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_infty));
3487   check_isinfp ("real(clog(-Inf - i Inf)) = +Inf", __real__ result);
3488   check ("imag(clog(-Inf - i Inf)) = -3*pi/4", __imag__ result, M_PI_4 - M_PI);
3489
3490   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, plus_infty));
3491   check_isinfp ("real(clog(+Inf + i Inf)) = +Inf", __real__ result);
3492   check ("imag(clog(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
3493   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_infty));
3494   check_isinfp ("real(clog(+Inf - i Inf)) = +Inf", __real__ result);
3495   check ("imag(clog(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
3496
3497   result = FUNC(clog) (BUILD_COMPLEX (0, plus_infty));
3498   check_isinfp ("real(clog(0 + i Inf)) = +Inf", __real__ result);
3499   check ("imag(clog(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3500   result = FUNC(clog) (BUILD_COMPLEX (3, plus_infty));
3501   check_isinfp ("real(clog(3 + i Inf)) = +Inf", __real__ result);
3502   check ("imag(clog(3 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3503   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, plus_infty));
3504   check_isinfp ("real(clog(-0 + i Inf)) = +Inf", __real__ result);
3505   check ("imag(clog(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3506   result = FUNC(clog) (BUILD_COMPLEX (-3, plus_infty));
3507   check_isinfp ("real(clog(-3 + i Inf)) = +Inf", __real__ result);
3508   check ("imag(clog(-3 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3509   result = FUNC(clog) (BUILD_COMPLEX (0, minus_infty));
3510   check_isinfp ("real(clog(0 - i Inf)) = +Inf", __real__ result);
3511   check ("imag(clog(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3512   result = FUNC(clog) (BUILD_COMPLEX (3, minus_infty));
3513   check_isinfp ("real(clog(3 - i Inf)) = +Inf", __real__ result);
3514   check ("imag(clog(3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3515   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_infty));
3516   check_isinfp ("real(clog(-0 - i Inf)) = +Inf", __real__ result);
3517   check ("imag(clog(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3518   result = FUNC(clog) (BUILD_COMPLEX (-3, minus_infty));
3519   check_isinfp ("real(clog(-3 - i Inf)) = +Inf", __real__ result);
3520   check ("imag(clog(-3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3521
3522   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 0));
3523   check_isinfp ("real(clog(-Inf + i0)) = +Inf", __real__ result);
3524   check ("imag(clog(-Inf + i0)) = pi", __imag__ result, M_PI);
3525   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 1));
3526   check_isinfp ("real(clog(-Inf + i1)) = +Inf", __real__ result);
3527   check ("imag(clog(-Inf + i1)) = pi", __imag__ result, M_PI);
3528   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_zero));
3529   check_isinfp ("real(clog(-Inf - i0)) = +Inf", __real__ result);
3530   check ("imag(clog(-Inf - i0)) = -pi", __imag__ result, -M_PI);
3531   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, -1));
3532   check_isinfp ("real(clog(-Inf - i1)) = +Inf", __real__ result);
3533   check ("imag(clog(-Inf - i1)) = -pi", __imag__ result, -M_PI);
3534
3535   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 0));
3536   check_isinfp ("real(clog(+Inf + i0)) = +Inf", __real__ result);
3537   check ("imag(clog(+Inf + i0)) = 0", __imag__ result, 0);
3538   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 1));
3539   check_isinfp ("real(clog(+Inf + i1)) = +Inf", __real__ result);
3540   check ("imag(clog(+Inf + i1)) = 0", __imag__ result, 0);
3541   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_zero));
3542   check_isinfp ("real(clog(+Inf - i0)) = +Inf", __real__ result);
3543   check ("imag(clog(+Inf - i0)) = -0", __imag__ result, minus_zero);
3544   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, -1));
3545   check_isinfp ("real(clog(+Inf - i1)) = +Inf", __real__ result);
3546   check ("imag(clog(+Inf - i1)) = -0", __imag__ result, minus_zero);
3547
3548   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, nan_value));
3549   check_isinfp ("real(clog(+Inf + i NaN)) = +Inf", __real__ result);
3550   check_isnan ("imag(clog(+Inf + i NaN)) = NaN", __imag__ result);
3551   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, nan_value));
3552   check_isinfp ("real(clog(-Inf + i NaN)) = +Inf", __real__ result);
3553   check_isnan ("imag(clog(-Inf + i NaN)) = NaN", __imag__ result);
3554
3555   result = FUNC(clog) (BUILD_COMPLEX (nan_value, plus_infty));
3556   check_isinfp ("real(clog(NaN + i Inf)) = +Inf", __real__ result);
3557   check_isnan ("imag(clog(NaN + i Inf)) = NaN", __imag__ result);
3558   result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_infty));
3559   check_isinfp ("real(clog(NaN - i Inf)) = +Inf", __real__ result);
3560   check_isnan ("imag(clog(NaN - i Inf)) = NaN", __imag__ result);
3561
3562   result = FUNC(clog) (BUILD_COMPLEX (0, nan_value));
3563   check_isnan_maybe_exc ("real(clog(0 + i NaN)) = NaN plus maybe invalid exception",
3564                          __real__ result, FE_INVALID);
3565   check_isnan ("imag(clog(0 + i NaN)) = NaN plus maybe invalid exception",
3566                __imag__ result);
3567   result = FUNC(clog) (BUILD_COMPLEX (3, nan_value));
3568   check_isnan_maybe_exc ("real(clog(3 + i NaN)) = NaN plus maybe invalid exception",
3569                          __real__ result, FE_INVALID);
3570   check_isnan ("imag(clog(3 + i NaN)) = NaN plus maybe invalid exception",
3571                __imag__ result);
3572   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, nan_value));
3573   check_isnan_maybe_exc ("real(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
3574                          __real__ result, FE_INVALID);
3575   check_isnan ("imag(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
3576                __imag__ result);
3577   result = FUNC(clog) (BUILD_COMPLEX (-3, nan_value));
3578   check_isnan_maybe_exc ("real(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
3579                          __real__ result, FE_INVALID);
3580   check_isnan ("imag(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
3581                __imag__ result);
3582
3583   result = FUNC(clog) (BUILD_COMPLEX (nan_value, 0));
3584   check_isnan_maybe_exc ("real(clog(NaN + i0)) = NaN plus maybe invalid exception",
3585                          __real__ result, FE_INVALID);
3586   check_isnan ("imag(clog(NaN + i0)) = NaN plus maybe invalid exception",
3587                __imag__ result);
3588   result = FUNC(clog) (BUILD_COMPLEX (nan_value, 5));
3589   check_isnan_maybe_exc ("real(clog(NaN + i5)) = NaN plus maybe invalid exception",
3590                          __real__ result, FE_INVALID);
3591   check_isnan ("imag(clog(NaN + i5)) = NaN plus maybe invalid exception",
3592                __imag__ result);
3593   result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_zero));
3594   check_isnan_maybe_exc ("real(clog(NaN - i0)) = NaN plus maybe invalid exception",
3595                          __real__ result, FE_INVALID);
3596   check_isnan ("imag(clog(NaN - i0)) = NaN plus maybe invalid exception",
3597                __imag__ result);
3598   result = FUNC(clog) (BUILD_COMPLEX (nan_value, -5));
3599   check_isnan_maybe_exc ("real(clog(NaN - i5)) = NaN plus maybe invalid exception",
3600                          __real__ result, FE_INVALID);
3601   check_isnan ("imag(clog(NaN - i5)) = NaN plus maybe invalid exception",
3602                __imag__ result);
3603
3604   result = FUNC(clog) (BUILD_COMPLEX (nan_value, nan_value));
3605   check_isnan ("real(clog(NaN + i NaN)) = NaN", __real__ result);
3606   check_isnan ("imag(clog(NaN + i NaN)) = NaN", __imag__ result);
3607 }
3608
3609
3610 static void
3611 csqrt_test (void)
3612 {
3613   __complex__ MATHTYPE result;
3614
3615   result = FUNC(csqrt) (BUILD_COMPLEX (0, 0));
3616   check ("real(csqrt(0 + i0)) = 0", __real__ result, 0);
3617   check ("imag(csqrt(0 + i0)) = 0", __imag__ result, 0);
3618   result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_zero));
3619   check ("real(csqrt(0 - i0)) = 0", __real__ result, 0);
3620   check ("imag(csqrt(0 - i0)) = -0", __imag__ result, minus_zero);
3621   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, 0));
3622   check ("real(csqrt(-0 + i0)) = 0", __real__ result, 0);
3623   check ("imag(csqrt(-0 + i0)) = 0", __imag__ result, 0);
3624   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_zero));
3625   check ("real(csqrt(-0 - i0)) = 0", __real__ result, 0);
3626   check ("imag(csqrt(-0 - i0)) = -0", __imag__ result, minus_zero);
3627
3628   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 0));
3629   check ("real(csqrt(-Inf + i0)) = 0", __real__ result, 0);
3630   check_isinfp ("imag(csqrt(-Inf + i0)) = +Inf", __imag__ result);
3631   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 6));
3632   check ("real(csqrt(-Inf + i6)) = 0", __real__ result, 0);
3633   check_isinfp ("imag(csqrt(-Inf + i6)) = +Inf", __imag__ result);
3634   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_zero));
3635   check ("real(csqrt(-Inf - i0)) = 0", __real__ result, 0);
3636   check_isinfn ("imag(csqrt(-Inf - i0)) = -Inf", __imag__ result);
3637   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, -6));
3638   check ("real(csqrt(-Inf - i6)) = 0", __real__ result, 0);
3639   check_isinfn ("imag(csqrt(-Inf - i6)) = -Inf", __imag__ result);
3640
3641   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 0));
3642   check_isinfp ("real(csqrt(+Inf + i0)) = +Inf", __real__ result);
3643   check ("imag(csqrt(+Inf + i0)) = 0", __imag__ result, 0);
3644   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 6));
3645   check_isinfp ("real(csqrt(+Inf + i6)) = +Inf", __real__ result);
3646   check ("imag(csqrt(+Inf + i6)) = 0", __imag__ result, 0);
3647   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_zero));
3648   check_isinfp ("real(csqrt(+Inf - i0)) = +Inf", __real__ result);
3649   check ("imag(csqrt(+Inf - i0)) = -0", __imag__ result, minus_zero);
3650   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, -6));
3651   check_isinfp ("real(csqrt(+Inf - i6)) = +Inf", __real__ result);
3652   check ("imag(csqrt(+Inf - i6)) = -0", __imag__ result, minus_zero);
3653
3654   result = FUNC(csqrt) (BUILD_COMPLEX (0, plus_infty));
3655   check_isinfp ("real(csqrt(0 + i Inf)) = +Inf", __real__ result);
3656   check_isinfp ("imag(csqrt(0 + i Inf)) = +Inf", __imag__ result);
3657   result = FUNC(csqrt) (BUILD_COMPLEX (4, plus_infty));
3658   check_isinfp ("real(csqrt(4 + i Inf)) = +Inf", __real__ result);
3659   check_isinfp ("imag(csqrt(4 + i Inf)) = +Inf", __imag__ result);
3660   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, plus_infty));
3661   check_isinfp ("real(csqrt(+Inf + i Inf)) = +Inf", __real__ result);
3662   check_isinfp ("imag(csqrt(+Inf + i Inf)) = +Inf", __imag__ result);
3663   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, plus_infty));
3664   check_isinfp ("real(csqrt(-0 + i Inf)) = +Inf", __real__ result);
3665   check_isinfp ("imag(csqrt(-0 + i Inf)) = +Inf", __imag__ result);
3666   result = FUNC(csqrt) (BUILD_COMPLEX (-4, plus_infty));
3667   check_isinfp ("real(csqrt(-4 + i Inf)) = +Inf", __real__ result);
3668   check_isinfp ("imag(csqrt(-4 + i Inf)) = +Inf", __imag__ result);
3669   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, plus_infty));
3670   check_isinfp ("real(csqrt(-Inf + i Inf)) = +Inf", __real__ result);
3671   check_isinfp ("imag(csqrt(-Inf + i Inf)) = +Inf", __imag__ result);
3672   result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_infty));
3673   check_isinfp ("real(csqrt(0 - i Inf)) = +Inf", __real__ result);
3674   check_isinfn ("imag(csqrt(0 - i Inf)) = -Inf", __imag__ result);
3675   result = FUNC(csqrt) (BUILD_COMPLEX (4, minus_infty));
3676   check_isinfp ("real(csqrt(4 - i Inf)) = +Inf", __real__ result);
3677   check_isinfn ("imag(csqrt(4 - i Inf)) = -Inf", __imag__ result);
3678   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_infty));
3679   check_isinfp ("real(csqrt(+Inf - i Inf)) = +Inf", __real__ result);
3680   check_isinfn ("imag(csqrt(+Inf - i Inf)) = -Inf", __imag__ result);
3681   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_infty));
3682   check_isinfp ("real(csqrt(-0 - i Inf)) = +Inf", __real__ result);
3683   check_isinfn ("imag(csqrt(-0 - i Inf)) = -Inf", __imag__ result);
3684   result = FUNC(csqrt) (BUILD_COMPLEX (-4, minus_infty));
3685   check_isinfp ("real(csqrt(-4 - i Inf)) = +Inf", __real__ result);
3686   check_isinfn ("imag(csqrt(-4 - i Inf)) = -Inf", __imag__ result);
3687   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_infty));
3688   check_isinfp ("real(csqrt(-Inf - i Inf)) = +Inf", __real__ result);
3689   check_isinfn ("imag(csqrt(-Inf - i Inf)) = -Inf", __imag__ result);
3690
3691   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, nan_value));
3692   check_isnan ("real(csqrt(-Inf + i NaN)) = NaN", __real__ result);
3693   check_isinfp ("imag(csqrt(-Inf + i NaN)) = +-Inf",
3694                 FUNC(fabs) (__imag__ result));
3695
3696   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, nan_value));
3697   check_isinfp ("real(csqrt(+Inf + i NaN)) = +Inf", __real__ result);
3698   check_isnan ("imag(csqrt(+Inf + i NaN)) = NaN", __imag__ result);
3699
3700   result = FUNC(csqrt) (BUILD_COMPLEX (0, nan_value));
3701   check_isnan_maybe_exc ("real(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
3702                          __real__ result, FE_INVALID);
3703   check_isnan ("imag(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
3704                __imag__ result);
3705   result = FUNC(csqrt) (BUILD_COMPLEX (1, nan_value));
3706   check_isnan_maybe_exc ("real(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
3707                          __real__ result, FE_INVALID);
3708   check_isnan ("imag(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
3709                __imag__ result);
3710   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, nan_value));
3711   check_isnan_maybe_exc ("real(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
3712                          __real__ result, FE_INVALID);
3713   check_isnan ("imag(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
3714                __imag__ result);
3715   result = FUNC(csqrt) (BUILD_COMPLEX (-1, nan_value));
3716   check_isnan_maybe_exc ("real(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
3717                          __real__ result, FE_INVALID);
3718   check_isnan ("imag(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
3719                __imag__ result);
3720
3721   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 0));
3722   check_isnan_maybe_exc ("real(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
3723                          __real__ result, FE_INVALID);
3724   check_isnan ("imag(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
3725                __imag__ result);
3726   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 8));
3727   check_isnan_maybe_exc ("real(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
3728                          __real__ result, FE_INVALID);
3729   check_isnan ("imag(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
3730                __imag__ result);
3731   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, minus_zero));
3732   check_isnan_maybe_exc ("real(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
3733                          __real__ result, FE_INVALID);
3734   check_isnan ("imag(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
3735                __imag__ result);
3736   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, -8));
3737   check_isnan_maybe_exc ("real(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
3738                          __real__ result, FE_INVALID);
3739   check_isnan ("imag(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
3740                __imag__ result);
3741
3742   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, nan_value));
3743   check_isnan ("real(csqrt(NaN + i NaN)) = NaN", __real__ result);
3744   check_isnan ("imag(csqrt(NaN + i NaN)) = NaN", __imag__ result);
3745 }
3746
3747
3748 static void
3749 cpow_test (void)
3750 {
3751   __complex__ MATHTYPE result;
3752 }
3753
3754
3755 static void
3756 rint_test (void)
3757 {
3758   check ("rint(0) = 0", FUNC(rint) (0.0), 0.0);
3759   check ("rint(-0) = -0", FUNC(rint) (minus_zero), minus_zero);
3760   check_isinfp ("rint(+Inf) = +Inf", FUNC(rint) (plus_infty));
3761   check_isinfn ("rint(-Inf) = -Inf", FUNC(rint) (minus_infty));
3762 }
3763
3764
3765 static void
3766 rinttol_test (void)
3767 {
3768   /* XXX this test is incomplete.  We need to have a way to specifiy
3769      the rounding method and test the critical cases.  So far, only
3770      unproblematic numbers are tested.  */
3771
3772   check_long ("rinttol(0) = 0", rinttol (0.0), 0);
3773   check_long ("rinttol(-0) = 0", rinttol (minus_zero), 0);
3774   check_long ("rinttol(0.2) = 0", rinttol (0.2), 0);
3775   check_long ("rinttol(-0.2) = 0", rinttol (-0.2), 0);
3776
3777   check_long ("rinttol(1.4) = 1", rinttol (1.4), 1);
3778   check_long ("rinttol(-1.4) = -1", rinttol (-1.4), -1);
3779
3780   check_long ("rinttol(8388600.3) = 8388600", rinttol (8388600.3), 8388600);
3781   check_long ("rinttol(-8388600.3) = -8388600", rinttol (-8388600.3),
3782               -8388600);
3783 }
3784
3785
3786 static void
3787 rinttoll_test (void)
3788 {
3789   /* XXX this test is incomplete.  We need to have a way to specifiy
3790      the rounding method and test the critical cases.  So far, only
3791      unproblematic numbers are tested.  */
3792
3793   check_longlong ("rinttoll(0) = 0", rinttoll (0.0), 0);
3794   check_longlong ("rinttoll(-0) = 0", rinttoll (minus_zero), 0);
3795   check_longlong ("rinttoll(0.2) = 0", rinttoll (0.2), 0);
3796   check_longlong ("rinttoll(-0.2) = 0", rinttoll (-0.2), 0);
3797
3798   check_longlong ("rinttoll(1.4) = 1", rinttoll (1.4), 1);
3799   check_longlong ("rinttoll(-1.4) = -1", rinttoll (-1.4), -1);
3800
3801   check_longlong ("rinttoll(8388600.3) = 8388600", rinttoll (8388600.3),
3802                   8388600);
3803   check_longlong ("rinttoll(-8388600.3) = -8388600", rinttoll (-8388600.3),
3804                   -8388600);
3805 }
3806
3807
3808 static void
3809 round_test (void)
3810 {
3811   check ("round(0) = 0", FUNC(round) (0), 0);
3812   check ("round(-0) = -0", FUNC(round) (minus_zero), minus_zero);
3813   check ("round(0.2) = 0", FUNC(round) (0.2), 0.0);
3814   check ("round(-0.2) = -0", FUNC(round) (-0.2), minus_zero);
3815   check ("round(0.5) = 1", FUNC(round) (0.5), 1.0);
3816   check ("round(-0.5) = -1", FUNC(round) (-0.5), -1.0);
3817   check ("round(0.8) = 1", FUNC(round) (0.8), 1.0);
3818   check ("round(-0.8) = -1", FUNC(round) (-0.8), -1.0);
3819   check ("round(1.5) = 2", FUNC(round) (1.5), 2.0);
3820   check ("round(-1.5) = -2", FUNC(round) (-1.5), -2.0);
3821   check ("round(2097152.5) = 2097153", FUNC(round) (2097152.5), 2097153);
3822   check ("round(-2097152.5) = -2097153", FUNC(round) (-2097152.5), -2097153);
3823 }
3824
3825
3826 static void
3827 roundtol_test (void)
3828 {
3829   check_long ("roundtol(0) = 0", roundtol (0), 0);
3830   check_long ("roundtol(-0) = 0", roundtol (minus_zero), 0);
3831   check_long ("roundtol(0.2) = 0", roundtol (0.2), 0.0);
3832   check_long ("roundtol(-0.2) = 0", roundtol (-0.2), 0);
3833   check_long ("roundtol(0.5) = 1", roundtol (0.5), 1);
3834   check_long ("roundtol(-0.5) = -1", roundtol (-0.5), -1);
3835   check_long ("roundtol(0.8) = 1", roundtol (0.8), 1);
3836   check_long ("roundtol(-0.8) = -1", roundtol (-0.8), -1);
3837   check_long ("roundtol(1.5) = 2", roundtol (1.5), 2);
3838   check_long ("roundtol(-1.5) = -2", roundtol (-1.5), -2);
3839   check_long ("roundtol(2097152.5) = 2097153", roundtol (2097152.5), 2097153);
3840   check_long ("roundtol(-2097152.5) = -2097153", roundtol (-2097152.5),
3841               -2097153);
3842 }
3843
3844
3845 static void
3846 roundtoll_test (void)
3847 {
3848   check_longlong ("roundtoll(0) = 0", roundtoll (0), 0);
3849   check_longlong ("roundtoll(-0) = 0", roundtoll (minus_zero), 0);
3850   check_longlong ("roundtoll(0.2) = 0", roundtoll (0.2), 0.0);
3851   check_longlong ("roundtoll(-0.2) = 0", roundtoll (-0.2), 0);
3852   check_longlong ("roundtoll(0.5) = 1", roundtoll (0.5), 1);
3853   check_longlong ("roundtoll(-0.5) = -1", roundtoll (-0.5), -1);
3854   check_longlong ("roundtoll(0.8) = 1", roundtoll (0.8), 1);
3855   check_longlong ("roundtoll(-0.8) = -1", roundtoll (-0.8), -1);
3856   check_longlong ("roundtoll(1.5) = 2", roundtoll (1.5), 2);
3857   check_longlong ("roundtoll(-1.5) = -2", roundtoll (-1.5), -2);
3858   check_longlong ("roundtoll(2097152.5) = 2097153",
3859                   roundtoll (2097152.5), 2097153);
3860   check_longlong ("roundtoll(-2097152.5) = -2097153",
3861                   roundtoll (-2097152.5), -2097153);
3862   check_longlong ("roundtoll(34359738368.5) = 34359738369",
3863                   roundtoll (34359738368.5), 34359738369ll);
3864   check_longlong ("roundtoll(-34359738368.5) = -34359738369",
3865                   roundtoll (-34359738368.5), -34359738369ll);
3866 }
3867
3868
3869 static void
3870 inverse_func_pair_test (const char *test_name,
3871                         mathfunc f1, mathfunc inverse,
3872                         MATHTYPE x, MATHTYPE epsilon)
3873 {
3874   MATHTYPE a, b, difference;
3875   int result;
3876
3877   a = f1 (x);
3878   (void) &a;
3879   b = inverse (a);
3880   (void) &b;
3881
3882   result = check_equal (b, x, epsilon, &difference);
3883   output_result (test_name, result,
3884                  b, x, difference, PRINT, PRINT);
3885 }
3886
3887
3888 static void
3889 inverse_functions (void)
3890 {
3891   inverse_func_pair_test ("asin(sin(x)) == x",
3892                         FUNC(sin), FUNC(asin), 1.0, CHOOSE (2e-18L, 0, 1e-7L));
3893   inverse_func_pair_test ("sin(asin(x)) == x",
3894                           FUNC(asin), FUNC(sin), 1.0, 0.0);
3895
3896   inverse_func_pair_test ("acos(cos(x)) == x",
3897                        FUNC(cos), FUNC(acos), 1.0, CHOOSE (4e-18L, 1e-15L, 0));
3898   inverse_func_pair_test ("cos(acos(x)) == x",
3899                           FUNC(acos), FUNC(cos), 1.0, 0.0);
3900   inverse_func_pair_test ("atan(tan(x)) == x",
3901                           FUNC(tan), FUNC(atan), 1.0, CHOOSE (2e-18L, 0, 0));
3902   inverse_func_pair_test ("tan(atan(x)) == x",
3903                        FUNC(atan), FUNC(tan), 1.0, CHOOSE (2e-18L, 1e-15L, 0));
3904
3905   inverse_func_pair_test ("asinh(sinh(x)) == x",
3906                      FUNC(sinh), FUNC(asinh), 1.0, CHOOSE (1e-18L, 0, 1e-7));
3907   inverse_func_pair_test ("sinh(asinh(x)) == x",
3908                           FUNC(asinh), FUNC(sinh), 1.0, CHOOSE (2e-18L, 0, 0));
3909
3910   inverse_func_pair_test ("acosh(cosh(x)) == x",
3911                 FUNC(cosh), FUNC(acosh), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
3912   inverse_func_pair_test ("cosh(acosh(x)) == x",
3913                           FUNC(acosh), FUNC(cosh), 1.0, 0.0);
3914
3915   inverse_func_pair_test ("atanh(tanh(x)) == x",
3916                      FUNC(tanh), FUNC(atanh), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
3917   inverse_func_pair_test ("tanh(atanh(x)) == x",
3918                           FUNC(atanh), FUNC(tanh), 1.0, 0.0);
3919
3920 }
3921
3922 /* Test sin and cos with the identity: sin(x)^2 + cos(x)^2 = 1.  */
3923 static void
3924 identities1_test (MATHTYPE x, MATHTYPE epsilon)
3925 {
3926   MATHTYPE res1, res2, res3, diff;
3927   int result;
3928
3929   res1 = FUNC(sin) (x);
3930   (void) &res1;
3931   res2 = FUNC(cos) (x);
3932   (void) &res2;
3933   res3 = res1 * res1 + res2 * res2;
3934   (void) &res3;
3935
3936   result = check_equal (res3, 1.0, epsilon, &diff);
3937   output_result_ext ("sin^2 + cos^2 == 1", result,
3938                      res3, 1.0, diff, x, PRINT, PRINT);
3939 }
3940
3941
3942 /* Test sin, cos, tan with the following relation: tan = sin/cos.  */
3943 static void
3944 identities2_test (MATHTYPE x, MATHTYPE epsilon)
3945 {
3946   MATHTYPE res1, res2, res3, res4, diff;
3947   int result;
3948
3949   res1 = FUNC(sin) (x);
3950   (void) &res1;
3951   res2 = FUNC(cos) (x);
3952   (void) &res2;
3953   res3 = FUNC(tan) (x);
3954   (void) &res3;
3955   res4 = res1 / res2;
3956   (void) &res4;
3957
3958   result = check_equal (res4, res3, epsilon, &diff);
3959   output_result_ext ("sin/cos == tan", result,
3960                      res4, res3, diff, x, PRINT, PRINT);
3961 }
3962
3963
3964 /* Test cosh and sinh with the identity cosh^2 - sinh^2 = 1.  */
3965 static void
3966 identities3_test (MATHTYPE x, MATHTYPE epsilon)
3967 {
3968   MATHTYPE res1, res2, res3, diff;
3969   int result;
3970
3971   res1 = FUNC(sinh) (x);
3972   (void) &res1;
3973   res2 = FUNC(cosh) (x);
3974   (void) &res2;
3975   res3 = res2 * res2 - res1 * res1;
3976   (void) &res3;
3977
3978   result = check_equal (res3, 1.0, epsilon, &diff);
3979   output_result_ext ("cosh^2 - sinh^2 == 1", result,
3980                      res3, 1.0, diff, x, PRINT, PRINT);
3981 }
3982
3983
3984 static void
3985 identities (void)
3986 {
3987   identities1_test (0.2L, CHOOSE (1e-18L, 0, 2e-7));
3988   identities1_test (0.9L, CHOOSE (1e-18L, 0, 0));
3989   identities1_test (0, 0);
3990   identities1_test (-1, CHOOSE (1e-18L, 0, 1e-7));
3991
3992   identities2_test (0.2L, CHOOSE (0, 1e-16, 0));
3993   identities2_test (0.9L, CHOOSE (0, 1e-15, 0));
3994   identities2_test (0, 0);
3995   identities2_test (-1, CHOOSE (1e-18L, 1e-15, 0));
3996
3997   identities3_test (0.2L, CHOOSE (1e-18L, 0, 1e-7));
3998   identities3_test (0.9L, CHOOSE (1e-18L, 1e-15, 1e-6));
3999   identities3_test (0, CHOOSE (0, 0, 1e-6));
4000   identities3_test (-1, CHOOSE (1e-18L, 0, 1e-6));
4001 }
4002
4003
4004 /*
4005    Let's test that basic arithmetic is working
4006    tests: Infinity and NaN
4007  */
4008 static void
4009 basic_tests (void)
4010 {
4011   /* variables are declared volatile to forbid some compiler
4012      optimizations */
4013   volatile MATHTYPE Inf_var, NaN_var, zero_var, one_var;
4014   MATHTYPE x1, x2;
4015
4016   zero_var = 0.0;
4017   one_var = 1.0;
4018   NaN_var = nan_value;
4019   Inf_var = one_var / zero_var;
4020
4021   (void) &zero_var;
4022   (void) &one_var;
4023   (void) &NaN_var;
4024   (void) &Inf_var;
4025
4026   /* Clear all exceptions.  The previous computations raised exceptions.  */
4027   feclearexcept (FE_ALL_EXCEPT);
4028
4029   check_isinfp ("isinf (inf) == +1", Inf_var);
4030   check_isinfn ("isinf (-inf) == -1", -Inf_var);
4031   check_bool ("!isinf (1)", !(FUNC(isinf) (one_var)));
4032   check_bool ("!isinf (NaN)", !(FUNC(isinf) (NaN_var)));
4033
4034   check_isnan ("isnan (NaN)", NaN_var);
4035   check_isnan ("isnan (-NaN)", -NaN_var);
4036   check_bool ("!isnan (1)", !(FUNC(isnan) (one_var)));
4037   check_bool ("!isnan (inf)", !(FUNC(isnan) (Inf_var)));
4038
4039   check_bool ("inf == inf", Inf_var == Inf_var);
4040   check_bool ("-inf == -inf", -Inf_var == -Inf_var);
4041   check_bool ("inf != -inf", Inf_var != -Inf_var);
4042   check_bool ("NaN != NaN", NaN_var != NaN_var);
4043
4044   /*
4045      the same tests but this time with NAN from <nan.h>
4046      NAN is a double const
4047    */
4048   check_bool ("isnan (NAN)", isnan (NAN));
4049   check_bool ("isnan (-NAN)", isnan (-NAN));
4050   check_bool ("!isinf (NAN)", !(isinf (NAN)));
4051   check_bool ("!isinf (-NAN)", !(isinf (-NAN)));
4052   check_bool ("NAN != NAN", NAN != NAN);
4053
4054   /*
4055      And again with the value returned by the `nan' function.
4056    */
4057   check_bool ("isnan (NAN)", FUNC(isnan) (FUNC(nan) ("")));
4058   check_bool ("isnan (-NAN)", FUNC(isnan) (-FUNC(nan) ("")));
4059   check_bool ("!isinf (NAN)", !(FUNC(isinf) (FUNC(nan) (""))));
4060   check_bool ("!isinf (-NAN)", !(FUNC(isinf) (-FUNC(nan) (""))));
4061   check_bool ("NAN != NAN", FUNC(nan) ("") != FUNC(nan) (""));
4062
4063   /* test if EPSILON is ok */
4064   x1 = MATHCONST (1.0);
4065   x2 = x1 + CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
4066   check_bool ("1 != 1+EPSILON", x1 != x2);
4067
4068   x1 = MATHCONST (1.0);
4069   x2 = x1 - CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
4070   check_bool ("1 != 1-EPSILON", x1 != x2);
4071
4072   /* test if HUGE_VALx is ok */
4073   x1 = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
4074   check_bool ("isinf (HUGE_VALx) == +1", ISINF (x1) == +1);
4075   x1 = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
4076   check_bool ("isinf (-HUGE_VALx) == -1", ISINF (x1) == -1);
4077
4078 }
4079
4080
4081 static void
4082 initialize (void)
4083 {
4084   fpstack_test ("start *init*");
4085   plus_zero = 0.0;
4086   nan_value = plus_zero / plus_zero;    /* Suppress GCC warning */
4087
4088   minus_zero = FUNC (copysign) (0.0, -1.0);
4089   plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
4090   minus_infty = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
4091
4092   (void) &plus_zero;
4093   (void) &nan_value;
4094   (void) &minus_zero;
4095   (void) &plus_infty;
4096   (void) &minus_infty;
4097
4098   /* Clear all exceptions.  From now on we must not get random exceptions.  */
4099   feclearexcept (FE_ALL_EXCEPT);
4100
4101   /* Test to make sure we start correctly.  */
4102   fpstack_test ("end *init*");
4103 }
4104
4105
4106 static struct option long_options[] =
4107 {
4108   {"verbose", optional_argument, NULL, 'v'},
4109   {"silent", no_argument, NULL, 's'},
4110   {0, 0, 0, 0}
4111 };
4112
4113
4114 static void
4115 parse_options (int argc, char *argv[])
4116 {
4117   int c;
4118   int option_index;
4119
4120   verbose = 1;
4121
4122   while (1)
4123     {
4124       c = getopt_long (argc, argv, "v::s",
4125                        long_options, &option_index);
4126
4127       /* Detect the end of the options. */
4128       if (c == -1)
4129         break;
4130
4131       switch (c)
4132         {
4133         case 'v':
4134           if (optarg)
4135             verbose = (unsigned int) strtoul (optarg, NULL, 0);
4136           else
4137             verbose = 3;
4138           break;
4139         case 's':
4140           verbose = 0;
4141         default:
4142           break;
4143         }
4144     }
4145 }
4146
4147
4148 int
4149 main (int argc, char *argv[])
4150 {
4151   parse_options (argc, argv);
4152
4153   initialize ();
4154   printf (TEST_MSG);
4155   basic_tests ();
4156
4157   acos_test ();
4158   acosh_test ();
4159   asin_test ();
4160   asinh_test ();
4161   atan_test ();
4162   atanh_test ();
4163   atan2_test ();
4164   cbrt_test ();
4165   ceil_test ();
4166   cos_test ();
4167   cosh_test ();
4168   exp_test ();
4169   exp2_test ();
4170   expm1_test ();
4171   frexp_test ();
4172   ilogb_test ();
4173   ldexp_test ();
4174   log_test ();
4175   log10_test ();
4176   log1p_test ();
4177   log2_test ();
4178   logb_test ();
4179   modf_test ();
4180   scalb_test ();
4181   scalbn_test ();
4182   sin_test ();
4183   sinh_test ();
4184   tan_test ();
4185   tanh_test ();
4186   fabs_test ();
4187   floor_test ();
4188   fpclassify_test ();
4189   hypot_test ();
4190   pow_test ();
4191   fdim_test ();
4192   fmin_test ();
4193   fmax_test ();
4194   nextafter_test ();
4195   copysign_test ();
4196   sqrt_test ();
4197   trunc_test ();
4198 #if 0
4199   /* XXX I'm not sure what is the correct result.  */
4200   remquo_test ();
4201 #endif
4202   cexp_test ();
4203   csin_test ();
4204   csinh_test ();
4205   ccos_test ();
4206   ccosh_test ();
4207   clog_test ();
4208   cacos_test ();
4209   cacosh_test ();
4210   casin_test ();
4211   casinh_test ();
4212   catan_test ();
4213   catanh_test ();
4214   ctanh_test ();
4215   csqrt_test ();
4216   cpow_test ();
4217
4218   rint_test ();
4219   rinttol_test ();
4220   rinttoll_test ();
4221   round_test ();
4222   roundtol_test ();
4223   roundtoll_test ();
4224
4225   identities ();
4226   inverse_functions ();
4227
4228   if (noErrors)
4229     {
4230       printf ("\n%d errors occured.\n", noErrors);
4231       exit (1);
4232     }
4233   printf ("\n All tests passed successfully.\n");
4234   exit (0);
4235 }