Update.
[platform/upstream/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.rhein-neckar.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    PRINTF_XEXPR    Like PRINTF_EXPR, but print in hexadecimal format.
40  */
41
42 /* This program isn't finished yet.
43    It has tests for:
44    acos, acosh, asin, asinh, atan, atan2, atanh,
45    cbrt, ceil, copysign, cos, cosh, erf, erfc, exp, exp2, expm1,
46    fabs, fdim, floor, fma, fmax, fmin, fmod, fpclassify,
47    frexp, gamma, hypot,
48    ilogb, isfinite, isinf, isnan, isnormal,
49    ldexp, lgamma, log, log10, log1p, log2, logb,
50    modf, nearbyint, nextafter,
51    pow, remainder, remquo, rint, lrint, llrint,
52    round, lround, llround,
53    scalb, scalbn, signbit, sin, sincos, sinh, sqrt, tan, tanh, trunc
54
55    and for the following complex math functions:
56    cabs, cacos, cacosh, carg, casin, casinh, catan, catanh,
57    ccos, ccosh, cexp, clog, cpow, csin, csinh, csqrt, ctan, ctanh.
58
59    At the moment the following functions aren't tested:
60    conj, cproj, cimag, creal, drem,
61    j0, j1, jn, y0, y1, yn,
62    significand,
63    nan, comparison macros (isless,isgreater,...).
64
65    The routines using random variables are still under construction. I don't
66    like it the way it's working now and will change it.
67
68    Parameter handling is primitive in the moment:
69    --verbose=[0..4] for different levels of output:
70    0: only error count
71    1: basic report on failed tests (default)
72    2: full report on failed tests
73    3: full report on failed and passed tests
74    4: additional report on exceptions
75    -v for full output (equals --verbose=4)
76    -s,--silent outputs only the error count (equals --verbose=0)
77  */
78
79 /* "Philosophy":
80
81    This suite tests some aspects of the correct implementation of
82    mathematical functions in libm.  Some simple, specific parameters
83    are tested for correctness but there's no exhaustive
84    testing. Handling of specific inputs (e.g. infinity, not-a-number)
85    is also tested. Correct handling of exceptions is checked
86    against. These implemented tests should check all cases that are
87    specified in ISO C 9X.
88
89    Exception testing: At the moment only divide-by-zero and invalid
90    exceptions are tested. Overflow/underflow and inexact exceptions
91    aren't checked at the moment.
92
93    NaN values: There exist signalling and quiet NaNs. This implementation
94    only uses signalling NaN as parameter but does not differenciate
95    between the two kinds of NaNs as result.
96
97    Inline functions: Inlining functions should give an improvement in
98    speed - but not in precission. The inlined functions return
99    reasonable values for a reasonable range of input values. The
100    result is not necessarily correct for all values and exceptions are
101    not correctly raised in all cases. Problematic input and return
102    values are infinity, not-a-number and minus zero. This suite
103    therefore does not check these specific inputs and the exception
104    handling for inlined mathematical functions - just the "reasonable"
105    values are checked.
106
107    Beware: The tests might fail for any of the following reasons:
108    - Tests are wrong
109    - Functions are wrong
110    - Floating Point Unit not working properly
111    - Compiler has errors
112
113    With e.g. gcc 2.7.2.2 the test for cexp fails because of a compiler error.
114
115 */
116
117 #ifndef _GNU_SOURCE
118 # define _GNU_SOURCE
119 #endif
120
121 #include <complex.h>
122 #include <math.h>
123 #include <float.h>
124 #include <fenv.h>
125
126 #include <errno.h>
127 #include <stdlib.h>
128 #include <stdio.h>
129 #include <getopt.h>
130
131 /* Possible exceptions */
132 #define NO_EXCEPTION             0x0
133 #define INVALID_EXCEPTION        0x1
134 #define DIVIDE_BY_ZERO_EXCEPTION 0x2
135
136 #define PRINT 1
137 #define NO_PRINT 0
138
139 /* Various constants (we must supply them precalculated for accuracy).  */
140 #define M_PI_6  .52359877559829887308L
141
142 static int noErrors;   /* number of errors */
143 static int noTests;    /* number of tests (without testing exceptions) */
144 static int noExcTests; /* number of tests for exception flags */
145
146 static int verbose = 3;
147 static MATHTYPE minus_zero, plus_zero;
148 static MATHTYPE plus_infty, minus_infty, nan_value;
149
150 typedef MATHTYPE (*mathfunc) (MATHTYPE);
151
152 #define BUILD_COMPLEX(real, imag) \
153   ({ __complex__ MATHTYPE __retval;                                           \
154      __real__ __retval = (real);                                              \
155      __imag__ __retval = (imag);                                              \
156      __retval; })
157
158
159 #define ISINF(x) \
160 (sizeof (x) == sizeof (float) ?                                               \
161  isinff (x)                                                                   \
162  : sizeof (x) == sizeof (double) ?                                            \
163  isinf (x) : isinfl (x))
164
165
166      /*
167         Test if Floating-Point stack hasn't changed
168       */
169 static void
170 fpstack_test (const char *test_name)
171 {
172 #ifdef i386
173   static int old_stack;
174   int sw;
175 asm ("fnstsw":"=a" (sw));
176   sw >>= 11;
177   sw &= 7;
178   if (sw != old_stack)
179     {
180       printf ("FP-Stack wrong after test %s\n", test_name);
181       if (verbose > 2)
182         printf ("=======> stack = %d\n", sw);
183       ++noErrors;
184       old_stack = sw;
185     }
186 #endif
187 }
188
189
190 /*
191    Get a random value x with min_value < x < max_value
192    and min_value, max_value finite,
193    max_value and min_value shouldn't be too close together
194  */
195 static MATHTYPE
196 random_value (MATHTYPE min_value, MATHTYPE max_value)
197 {
198   int r;
199   MATHTYPE x;
200
201   r = rand ();
202
203   x = (max_value - min_value) / RAND_MAX * (MATHTYPE) r + min_value;
204
205   if ((x <= min_value) || (x >= max_value) || !isfinite (x))
206     x = (max_value - min_value) / 2 + min_value;
207
208   /* Make sure the RNG has no influence on the exceptions.  */
209   feclearexcept (FE_ALL_EXCEPT);
210
211   return x;
212 }
213
214 /* Get a random value x with x > min_value.  */
215 static MATHTYPE
216 random_greater (MATHTYPE min_value)
217 {
218   return random_value (min_value, 1e6);         /* CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX) */
219 }
220
221 /* Get a random value x with x < max_value.  */
222 static MATHTYPE
223 random_less (MATHTYPE max_value)
224 {
225   return random_value (-1e6, max_value);
226 }
227
228
229 static void
230 output_new_test (const char *test_name)
231 {
232   if (verbose > 2)
233     printf ("\nTesting: %s\n", test_name);
234 }
235
236
237 static void
238 output_pass_value (void)
239 {
240   if (verbose > 2)
241     printf ("Pass: Value Ok.\n");
242 }
243
244
245 static void
246 output_fail_value (const char * test_name)
247 {
248   if (verbose > 0 && verbose < 3)
249     printf ("Fail: %s\n", test_name);
250   if (verbose >= 3)
251     printf ("Fail:\n");
252 }
253
254
255 /* Test whether a given exception was raised.  */
256 static void
257 test_single_exception (const char *test_name,
258                        short int exception,
259                        short int exc_flag,
260                        int fe_flag,
261                        const char *flag_name)
262 {
263 #ifndef TEST_INLINE
264   if (exception & exc_flag)
265     {
266       if (fetestexcept (fe_flag))
267         {
268           if (verbose > 3)
269             printf ("Pass: Exception \"%s\" set\n", flag_name);
270         }
271       else
272         {
273           if (verbose && verbose < 3)
274             printf ("Fail: %s: Exception \"%s\" not set\n",
275                     test_name, flag_name);
276           if (verbose >= 3)
277             printf ("Fail:  Exception \"%s\" not set\n",
278                     flag_name);
279           ++noErrors;
280         }
281     }
282   else
283     {
284       if (fetestexcept (fe_flag))
285         {
286           if (verbose  && verbose < 3)
287             printf ("Fail: %s: Exception \"%s\" set\n",
288                     test_name, flag_name);
289           if (verbose >= 3)
290             printf ("Fail:  Exception \"%s\" set\n",
291                     flag_name);
292           ++noErrors;
293         }
294       else
295         {
296           if (verbose > 3)
297             printf ("Pass: Exception \"%s\" not set\n",
298                     flag_name);
299         }
300     }
301 #endif
302 }
303
304
305 /* Test whether exception given by EXCEPTION are raised.  */
306 static void
307 test_not_exception (const char *test_name, short int exception)
308 {
309   ++noExcTests;
310 #ifdef FE_DIVBYZERO
311   if ((exception & DIVIDE_BY_ZERO_EXCEPTION) == 0)
312     test_single_exception (test_name, exception,
313                            DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
314                            "Divide by zero");
315 #endif
316 #ifdef FE_INVALID
317   if ((exception & INVALID_EXCEPTION) == 0)
318     test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
319                            "Invalid operation");
320 #endif
321   feclearexcept (FE_ALL_EXCEPT);
322 }
323
324
325 /* Test whether exceptions given by EXCEPTION are raised.  */
326 static void
327 test_exceptions (const char *test_name, short int exception)
328 {
329   ++noExcTests;
330 #ifdef FE_DIVBYZERO
331   test_single_exception (test_name, exception,
332                          DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
333                          "Divide by zero");
334 #endif
335 #ifdef FE_INVALID
336   test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
337                          "Invalid operation");
338 #endif
339   feclearexcept (FE_ALL_EXCEPT);
340 }
341
342
343 /* Test if two floating point numbers are equal.  */
344 static int
345 check_equal (MATHTYPE computed, MATHTYPE supplied, MATHTYPE eps, MATHTYPE * diff)
346 {
347   int ret_value;
348
349   /* Both plus Infinity or both minus infinity.  */
350   if (ISINF (computed) && (ISINF (computed) == ISINF (supplied)))
351     return 1;
352
353   if (isnan (computed) && isnan (supplied))     /* isnan works for all types */
354     return 1;
355
356   *diff = FUNC(fabs) (computed - supplied);
357
358
359   ret_value = (*diff <= eps &&
360                (signbit (computed) == signbit (supplied) || eps != 0.0));
361
362   /* Make sure the subtraction/comparsion have no influence on the exceptions. */
363   feclearexcept (FE_ALL_EXCEPT);
364
365   return ret_value;
366 }
367
368
369
370 static void
371 output_result_bool (const char *test_name, int result)
372 {
373   ++noTests;
374   if (result)
375     {
376       output_pass_value ();
377     }
378   else
379     {
380       output_fail_value (test_name);
381       if (verbose > 1)
382         printf (" Value: %d\n", result);
383       ++noErrors;
384     }
385
386   fpstack_test (test_name);
387 }
388
389
390 static void
391 output_isvalue (const char *test_name, int result,
392                 MATHTYPE value)
393 {
394   ++noTests;
395   if (result)
396     {
397       output_pass_value ();
398     }
399   else
400     {
401       output_fail_value (test_name);
402       if (verbose > 1)
403         printf (" Value: % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
404                 value, value);
405       ++noErrors;
406     }
407
408   fpstack_test (test_name);
409 }
410
411
412 static void
413 output_isvalue_ext (const char *test_name, int result,
414                     MATHTYPE value, MATHTYPE parameter)
415 {
416   ++noTests;
417   if (result)
418     {
419       output_pass_value ();
420     }
421   else
422     {
423       output_fail_value (test_name);
424       if (verbose > 1)
425         {
426           printf (" Value:     % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
427                   value, value);
428           printf (" Parameter: % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
429                   parameter, parameter);
430         }
431       noErrors++;
432     }
433
434   fpstack_test (test_name);
435 }
436
437
438 static void
439 output_result (const char *test_name, int result,
440                MATHTYPE computed, MATHTYPE expected,
441                MATHTYPE difference,
442                int print_values, int print_diff)
443 {
444   ++noTests;
445   if (result)
446     {
447       output_pass_value ();
448     }
449   else
450     {
451       output_fail_value (test_name);
452       if (verbose > 1 && print_values)
453         {
454           printf ("Result:\n");
455           printf (" is:         % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
456                   computed, computed);
457           printf (" should be:  % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
458                   expected, expected);
459           if (print_diff)
460             printf (" difference: % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR
461                     "\n", difference, difference);
462         }
463       ++noErrors;
464     }
465
466   fpstack_test (test_name);
467 }
468
469
470 static void
471 output_result_ext (const char *test_name, int result,
472                    MATHTYPE computed, MATHTYPE expected,
473                    MATHTYPE difference,
474                    MATHTYPE parameter,
475                    int print_values, int print_diff)
476 {
477   ++noTests;
478   if (result)
479     {
480       output_pass_value ();
481     }
482   else
483     {
484       output_fail_value (test_name);
485       if (verbose > 1 && print_values)
486         {
487           printf ("Result:\n");
488           printf (" is:         % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
489                   computed, computed);
490           printf (" should be:  % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
491                   expected, expected);
492           if (print_diff)
493             printf (" difference: % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR
494                     "\n", difference, difference);
495           printf ("Parameter:   % .20" PRINTF_EXPR "  % .20" PRINTF_XEXPR "\n",
496                   parameter, parameter);
497         }
498       ++noErrors;
499     }
500
501   fpstack_test (test_name);
502 }
503
504 /*
505   check that computed and expected values are the same
506  */
507 static void
508 check (const char *test_name, MATHTYPE computed, MATHTYPE expected)
509 {
510   MATHTYPE diff;
511   int result;
512
513   output_new_test (test_name);
514   test_exceptions (test_name, NO_EXCEPTION);
515   result = check_equal (computed, expected, 0, &diff);
516   output_result (test_name, result,
517                  computed, expected, diff, PRINT, PRINT);
518 }
519
520
521 /*
522   check that computed and expected values are the same,
523   outputs the parameter to the function
524  */
525 static void
526 check_ext (const char *test_name, MATHTYPE computed, MATHTYPE expected,
527            MATHTYPE parameter)
528 {
529   MATHTYPE diff;
530   int result;
531
532   output_new_test (test_name);
533   test_exceptions (test_name, NO_EXCEPTION);
534   result = check_equal (computed, expected, 0, &diff);
535   output_result_ext (test_name, result,
536                      computed, expected, diff, parameter, PRINT, PRINT);
537 }
538
539
540 /*
541   check that computed and expected values are the same and
542   checks also for exception flags
543  */
544 static void
545 check_exc (const char *test_name, MATHTYPE computed, MATHTYPE expected,
546            short exception)
547 {
548   MATHTYPE diff;
549   int result;
550
551   output_new_test (test_name);
552   test_exceptions (test_name, exception);
553   result = check_equal (computed, expected, 0, &diff);
554   output_result (test_name, result,
555                  computed, expected, diff, PRINT, PRINT);
556 }
557
558 /*
559   check that computed and expected values are close enough
560  */
561 static void
562 check_eps (const char *test_name, MATHTYPE computed, MATHTYPE expected,
563            MATHTYPE epsilon)
564 {
565   MATHTYPE diff;
566   int result;
567
568   output_new_test (test_name);
569   test_exceptions (test_name, NO_EXCEPTION);
570   result = check_equal (computed, expected, epsilon, &diff);
571   output_result (test_name, result,
572                  computed, expected, diff, PRINT, PRINT);
573 }
574
575 /*
576   check a boolean condition
577  */
578 static void
579 check_bool (const char *test_name, int computed)
580 {
581   output_new_test (test_name);
582   test_exceptions (test_name, NO_EXCEPTION);
583   output_result_bool (test_name, computed);
584 }
585
586
587
588 /*
589   check that computed and expected values are equal (int values)
590  */
591 static void
592 check_int (const char *test_name, int computed, int expected)
593 {
594   int diff = computed - expected;
595   int result = diff == 0;
596
597   output_new_test (test_name);
598   test_exceptions (test_name, NO_EXCEPTION);
599
600   if (result)
601     {
602       output_pass_value ();
603     }
604   else
605     {
606       output_fail_value (test_name);
607       if (verbose > 1)
608         {
609           printf ("Result:\n");
610           printf (" is:         %d\n", computed);
611           printf (" should be:  %d\n", expected);
612         }
613       noErrors++;
614     }
615
616   fpstack_test (test_name);
617 }
618
619
620 /*
621   check that computed and expected values are equal (long int values)
622  */
623 static void
624 check_long (const char *test_name, long int computed, long int expected)
625 {
626   long int diff = computed - expected;
627   int result = diff == 0;
628
629   ++noTests;
630   output_new_test (test_name);
631   test_exceptions (test_name, NO_EXCEPTION);
632
633   if (result)
634     {
635       output_pass_value ();
636     }
637   else
638     {
639       output_fail_value (test_name);
640       if (verbose > 1)
641         {
642           printf ("Result:\n");
643           printf (" is:         %ld\n", computed);
644           printf (" should be:  %ld\n", expected);
645         }
646       noErrors++;
647     }
648
649   fpstack_test (test_name);
650 }
651
652 /*
653   check that computed and expected values are equal (long long int values)
654  */
655 static void
656 check_longlong (const char *test_name, long long int computed,
657                 long long int expected)
658 {
659   long long int diff = computed - expected;
660   int result = diff == 0;
661
662   ++noTests;
663   output_new_test (test_name);
664   test_exceptions (test_name, NO_EXCEPTION);
665
666   if (result)
667     {
668       output_pass_value ();
669     }
670   else
671     {
672       output_fail_value (test_name);
673       if (verbose > 1)
674         {
675           printf ("Result:\n");
676           printf (" is:         %lld\n", computed);
677           printf (" should be:  %lld\n", expected);
678         }
679       noErrors++;
680     }
681
682   fpstack_test (test_name);
683 }
684
685 /*
686   check that computed value is not-a-number
687  */
688 static void
689 check_isnan (const char *test_name, MATHTYPE computed)
690 {
691   output_new_test (test_name);
692   test_exceptions (test_name, NO_EXCEPTION);
693   output_isvalue (test_name, isnan (computed), computed);
694 }
695
696
697 /*
698   check that computed value is not-a-number and test for exceptions
699  */
700 static void
701 check_isnan_exc (const char *test_name, MATHTYPE computed,
702                  short exception)
703 {
704   output_new_test (test_name);
705   test_exceptions (test_name, exception);
706   output_isvalue (test_name, isnan (computed), computed);
707 }
708
709
710 /*
711   check that computed value is not-a-number and test for exceptions
712  */
713 static void
714 check_isnan_maybe_exc (const char *test_name, MATHTYPE computed,
715                        short exception)
716 {
717   output_new_test (test_name);
718   test_not_exception (test_name, exception);
719   output_isvalue (test_name, isnan (computed), computed);
720 }
721
722 /*
723   check that computed value is not-a-number and supply parameter
724  */
725 #ifndef TEST_INLINE
726 static void
727 check_isnan_ext (const char *test_name, MATHTYPE computed,
728                  MATHTYPE parameter)
729 {
730   output_new_test (test_name);
731   test_exceptions (test_name, NO_EXCEPTION);
732   output_isvalue_ext (test_name, isnan (computed), computed, parameter);
733 }
734 #endif
735
736 /*
737   check that computed value is not-a-number, test for exceptions
738   and supply parameter
739  */
740 static void
741 check_isnan_exc_ext (const char *test_name, MATHTYPE computed,
742                      short exception, MATHTYPE parameter)
743 {
744   output_new_test (test_name);
745   test_exceptions (test_name,exception);
746   output_isvalue_ext (test_name, isnan (computed), computed, parameter);
747 }
748
749
750 /* Tests if computed is +Inf */
751 static void
752 check_isinfp (const char *test_name, MATHTYPE computed)
753 {
754   output_new_test (test_name);
755   test_exceptions (test_name, NO_EXCEPTION);
756   output_isvalue (test_name, (ISINF (computed) == +1), computed);
757 }
758
759
760 static void
761 check_isinfp_ext (const char *test_name, MATHTYPE computed,
762                   MATHTYPE parameter)
763 {
764   output_new_test (test_name);
765   test_exceptions (test_name, NO_EXCEPTION);
766   output_isvalue_ext (test_name, (ISINF (computed) == +1), computed, parameter);
767 }
768
769
770 /* Tests if computed is +Inf */
771 static void
772 check_isinfp_exc (const char *test_name, MATHTYPE computed,
773                   int exception)
774 {
775   output_new_test (test_name);
776   test_exceptions (test_name, exception);
777   output_isvalue (test_name, (ISINF (computed) == +1), computed);
778 }
779
780 /* Tests if computed is -Inf */
781 static void
782 check_isinfn (const char *test_name, MATHTYPE computed)
783 {
784   output_new_test (test_name);
785   test_exceptions (test_name, NO_EXCEPTION);
786   output_isvalue (test_name, (ISINF (computed) == -1), computed);
787 }
788
789
790 #ifndef TEST_INLINE
791 static void
792 check_isinfn_ext (const char *test_name, MATHTYPE computed,
793                   MATHTYPE parameter)
794 {
795   output_new_test (test_name);
796   test_exceptions (test_name, NO_EXCEPTION);
797   output_isvalue_ext (test_name, (ISINF (computed) == -1), computed, parameter);
798 }
799 #endif
800
801
802 /* Tests if computed is -Inf */
803 static void
804 check_isinfn_exc (const char *test_name, MATHTYPE computed,
805                   int exception)
806 {
807   output_new_test (test_name);
808   test_exceptions (test_name, exception);
809   output_isvalue (test_name, (ISINF (computed) == -1), computed);
810 }
811
812
813 /* This is to prevent messages from the SVID libm emulation.  */
814 int
815 matherr (struct exception *x __attribute__ ((unused)))
816 {
817   return 1;
818 }
819
820
821 /****************************************************************************
822   Test for single functions of libm
823 ****************************************************************************/
824
825 static void
826 acos_test (void)
827 {
828 #ifndef TEST_INLINE
829   MATHTYPE x;
830
831   x = random_greater (1);
832   check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
833                    FUNC(acos) (x),
834                    INVALID_EXCEPTION);
835
836   x = random_less (1);
837   check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
838                    FUNC(acos) (x),
839                    INVALID_EXCEPTION);
840 #endif
841   check ("acos (0) == pi/2", FUNC(acos) (0), M_PI_2);
842   check ("acos (-0) == pi/2", FUNC(acos) (minus_zero), M_PI_2);
843
844   check ("acos (1) == 0", FUNC(acos) (1), 0);
845   check ("acos (-1) == pi", FUNC(acos) (-1), M_PI);
846
847   check ("acos (0.5) == pi/3", FUNC(acos) (0.5), M_PI_6 * 2.0);
848   check ("acos (-0.5) == 2*pi/3", FUNC(acos) (-0.5), M_PI_6 * 4.0);
849
850 }
851
852
853 static void
854 acosh_test (void)
855 {
856 #ifndef TEST_INLINE
857   MATHTYPE x;
858
859   check_isinfp ("acosh(+inf) == +inf", FUNC(acosh) (plus_infty));
860
861   x = random_less (1);
862   check_isnan_exc ("acosh(x) == NaN plus invalid exception if x < 1",
863                    FUNC(acosh) (x), INVALID_EXCEPTION);
864 #endif
865
866   check ("acosh(1) == 0", FUNC(acosh) (1), 0);
867 }
868
869
870 static void
871 asin_test (void)
872 {
873 #ifndef TEST_INLINE
874   MATHTYPE x;
875
876   x = random_greater (1);
877   check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
878                    FUNC(asin) (x),
879                    INVALID_EXCEPTION);
880
881   x = random_less (1);
882   check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
883                    FUNC(asin) (x),
884                    INVALID_EXCEPTION);
885 #endif
886
887   check ("asin (0) == 0", FUNC(asin) (0), 0);
888   check ("asin (-0) == -0", FUNC(asin) (minus_zero), minus_zero);
889   check_eps ("asin (0.5) ==  pi/6", FUNC(asin) (0.5), M_PI_6,
890              CHOOSE(3.5e-18, 0, 2e-7));
891   check_eps ("asin (-0.5) ==  -pi/6", FUNC(asin) (-0.5), -M_PI_6,
892              CHOOSE(3.5e-18, 0, 2e-7));
893   check ("asin (1.0) ==  pi/2", FUNC(asin) (1.0), M_PI_2);
894   check ("asin (-1.0) ==  -pi/2", FUNC(asin) (-1.0), -M_PI_2);
895
896 }
897
898
899 static void
900 asinh_test (void)
901 {
902
903   check ("asinh(+0) == +0", FUNC(asinh) (0), 0);
904 #ifndef TEST_INLINE
905   check ("asinh(-0) == -0", FUNC(asinh) (minus_zero), minus_zero);
906   check_isinfp ("asinh(+inf) == +inf", FUNC(asinh) (plus_infty));
907   check_isinfn ("asinh(-inf) == -inf", FUNC(asinh) (minus_infty));
908 #endif
909
910 }
911
912
913 static void
914 atan_test (void)
915 {
916   check ("atan (0) == 0", FUNC(atan) (0), 0);
917   check ("atan (-0) == -0", FUNC(atan) (minus_zero), minus_zero);
918
919   check ("atan (+inf) == pi/2", FUNC(atan) (plus_infty), M_PI_2);
920   check ("atan (-inf) == -pi/2", FUNC(atan) (minus_infty), -M_PI_2);
921
922   check ("atan (1) == pi/4", FUNC(atan) (1), M_PI_4);
923   check ("atan (-1) == -pi/4", FUNC(atan) (1), M_PI_4);
924
925 }
926
927
928 static void
929 atan2_test (void)
930 {
931   MATHTYPE x;
932
933   x = random_greater (0);
934   check ("atan2 (0,x) == 0 for x > 0",
935          FUNC(atan2) (0, x), 0);
936   x = random_greater (0);
937   check ("atan2 (-0,x) == -0 for x > 0",
938          FUNC(atan2) (minus_zero, x), minus_zero);
939
940   check ("atan2 (+0,+0) == +0", FUNC(atan2) (0, 0), 0);
941   check ("atan2 (-0,+0) == -0", FUNC(atan2) (minus_zero, 0), minus_zero);
942
943   x = -random_greater (0);
944   check ("atan2 (+0,x) == +pi for x < 0", FUNC(atan2) (0, x), M_PI);
945
946   x = -random_greater (0);
947   check ("atan2 (-0,x) == -pi for x < 0", FUNC(atan2) (minus_zero, x), -M_PI);
948
949   check ("atan2 (+0,-0) == +pi", FUNC(atan2) (0, minus_zero), M_PI);
950   check ("atan2 (-0,-0) == -pi", FUNC(atan2) (minus_zero, minus_zero), -M_PI);
951
952   x = random_greater (0);
953   check ("atan2 (y,+0) == pi/2 for y > 0", FUNC(atan2) (x, 0), M_PI_2);
954
955   x = random_greater (0);
956   check ("atan2 (y,-0) == pi/2 for y > 0", FUNC(atan2) (x, minus_zero), M_PI_2);
957
958   x = random_less (0);
959   check ("atan2 (y,+0) == -pi/2 for y < 0", FUNC(atan2) (x, 0), -M_PI_2);
960
961   x = random_less (0);
962   check ("atan2 (y,-0) == -pi/2 for y < 0", FUNC(atan2) (x, minus_zero), -M_PI_2);
963
964   x = random_greater (0);
965   check ("atan2 (y,inf) == +0 for finite y > 0",
966          FUNC(atan2) (x, plus_infty), 0);
967
968   x = -random_greater (0);
969   check ("atan2 (y,inf) == -0 for finite y < 0",
970          FUNC(atan2) (x, plus_infty), minus_zero);
971
972   x = random_value (-1e4, 1e4);
973   check ("atan2(+inf, x) == pi/2 for finite x",
974          FUNC(atan2) (plus_infty, x), M_PI_2);
975
976   x = random_value (-1e4, 1e4);
977   check ("atan2(-inf, x) == -pi/2 for finite x",
978          FUNC(atan2) (minus_infty, x), -M_PI_2);
979
980   x = random_greater (0);
981   check ("atan2 (y,-inf) == +pi for finite y > 0",
982          FUNC(atan2) (x, minus_infty), M_PI);
983
984   x = -random_greater (0);
985   check ("atan2 (y,-inf) == -pi for finite y < 0",
986          FUNC(atan2) (x, minus_infty), -M_PI);
987
988   check ("atan2 (+inf,+inf) == +pi/4",
989          FUNC(atan2) (plus_infty, plus_infty), M_PI_4);
990
991   check ("atan2 (-inf,+inf) == -pi/4",
992          FUNC(atan2) (minus_infty, plus_infty), -M_PI_4);
993
994   check ("atan2 (+inf,-inf) == +3*pi/4",
995          FUNC(atan2) (plus_infty, minus_infty), 3 * M_PI_4);
996
997   check ("atan2 (-inf,-inf) == -3*pi/4",
998          FUNC(atan2) (minus_infty, minus_infty), -3 * M_PI_4);
999
1000   /* FIXME: Add some specific tests */
1001 }
1002
1003
1004 static void
1005 atanh_test (void)
1006 {
1007 #ifndef TEST_INLINE
1008   MATHTYPE x;
1009 #endif
1010
1011   check ("atanh(+0) == +0", FUNC(atanh) (0), 0);
1012 #ifndef TEST_INLINE
1013   check ("atanh(-0) == -0", FUNC(atanh) (minus_zero), minus_zero);
1014
1015   check_isinfp_exc ("atanh(+1) == +inf plus divide-by-zero exception",
1016                     FUNC(atanh) (1), DIVIDE_BY_ZERO_EXCEPTION);
1017   check_isinfn_exc ("atanh(-1) == -inf plus divide-by-zero exception",
1018                     FUNC(atanh) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1019
1020   x = random_greater (1.0);
1021   check_isnan_exc_ext ("atanh (x) == NaN plus invalid exception if |x| > 1",
1022                        FUNC(atanh) (x), INVALID_EXCEPTION, x);
1023
1024   x = random_less (1.0);
1025   check_isnan_exc_ext ("atanh (x) == NaN plus invalid exception if |x| > 1",
1026                        FUNC(atanh) (x), INVALID_EXCEPTION, x);
1027
1028 #endif
1029 }
1030
1031
1032 static void
1033 cbrt_test (void)
1034 {
1035   check ("cbrt (+0) == +0", FUNC(cbrt) (0.0), 0.0);
1036   check ("cbrt (-0) == -0", FUNC(cbrt) (minus_zero), minus_zero);
1037
1038 #ifndef TEST_INLINE
1039   check_isinfp ("cbrt (+inf) == +inf", FUNC(cbrt) (plus_infty));
1040   check_isinfn ("cbrt (-inf) == -inf", FUNC(cbrt) (minus_infty));
1041   check_isnan ("cbrt (NaN) == NaN", FUNC(cbrt) (nan_value));
1042 #endif
1043   check_eps ("cbrt (-0.001) == -0.1", FUNC(cbrt) (-0.001), -0.1,
1044              CHOOSE (5e-18L, 0, 0));
1045   check_eps ("cbrt (8) == 2", FUNC(cbrt) (8), 2, CHOOSE (5e-17L, 0, 0));
1046   check_eps ("cbrt (-27) == -3", FUNC(cbrt) (-27.0), -3.0,
1047              CHOOSE (3e-16L, 5e-16, 0));
1048   check_eps ("cbrt (0.970299) == 0.99", FUNC(cbrt) (0.970299), 0.99,
1049              CHOOSE (2e-17L, 0, 0));
1050 }
1051
1052
1053 static void
1054 ceil_test (void)
1055 {
1056   check ("ceil (+0) == +0", FUNC(ceil) (0.0), 0.0);
1057   check ("ceil (-0) == -0", FUNC(ceil) (minus_zero), minus_zero);
1058   check_isinfp ("ceil (+inf) == +inf", FUNC(ceil) (plus_infty));
1059   check_isinfn ("ceil (-inf) == -inf", FUNC(ceil) (minus_infty));
1060
1061   check ("ceil (pi) == 4", FUNC(ceil) (M_PI), 4.0);
1062   check ("ceil (-pi) == -3", FUNC(ceil) (-M_PI), -3.0);
1063 }
1064
1065
1066 static void
1067 cos_test (void)
1068 {
1069
1070   check ("cos (+0) == 1", FUNC(cos) (0), 1);
1071   check ("cos (-0) == 1", FUNC(cos) (minus_zero), 1);
1072   check_isnan_exc ("cos (+inf) == NaN plus invalid exception",
1073                    FUNC(cos) (plus_infty),
1074                    INVALID_EXCEPTION);
1075   check_isnan_exc ("cos (-inf) == NaN plus invalid exception",
1076                    FUNC(cos) (minus_infty),
1077                    INVALID_EXCEPTION);
1078
1079   check_eps ("cos (pi/3) == 0.5", FUNC(cos) (M_PI_6 * 2.0),
1080              0.5, CHOOSE (4e-18L, 1e-15L, 1e-7L));
1081   check_eps ("cos (2*pi/3) == -0.5", FUNC(cos) (M_PI_6 * 4.0),
1082              -0.5, CHOOSE (4e-18L, 1e-15L, 1e-7L));
1083   check_eps ("cos (pi/2) == 0", FUNC(cos) (M_PI_2),
1084              0, CHOOSE (1e-19L, 1e-16L, 1e-7L));
1085
1086 }
1087
1088 static void
1089 cosh_test (void)
1090 {
1091   check ("cosh (+0) == 1", FUNC(cosh) (0), 1);
1092   check ("cosh (-0) == 1", FUNC(cosh) (minus_zero), 1);
1093
1094 #ifndef TEST_INLINE
1095   check_isinfp ("cosh (+inf) == +inf", FUNC(cosh) (plus_infty));
1096   check_isinfp ("cosh (-inf) == +inf", FUNC(cosh) (minus_infty));
1097 #endif
1098 }
1099
1100
1101 static void
1102 erf_test (void)
1103 {
1104   errno = 0;
1105   FUNC(erf) (0);
1106   if (errno == ENOSYS)
1107     /* Function not implemented.  */
1108     return;
1109
1110   check ("erf (+0) == +0", FUNC(erf) (0), 0);
1111   check ("erf (-0) == -0", FUNC(erf) (minus_zero), minus_zero);
1112   check ("erf (+inf) == +1", FUNC(erf) (plus_infty), 1);
1113   check ("erf (-inf) == -1", FUNC(erf) (minus_infty), -1);
1114 }
1115
1116
1117 static void
1118 erfc_test (void)
1119 {
1120   errno = 0;
1121   FUNC(erfc) (0);
1122   if (errno == ENOSYS)
1123     /* Function not implemented.  */
1124     return;
1125
1126   check ("erfc (+inf) == 0", FUNC(erfc) (plus_infty), 0.0);
1127   check ("erfc (-inf) == 2", FUNC(erfc) (minus_infty), 2.0);
1128   check ("erfc (+0) == 1", FUNC(erfc) (0.0), 1.0);
1129   check ("erfc (-0) == 1", FUNC(erfc) (minus_zero), 1.0);
1130 }
1131
1132
1133 static void
1134 exp_test (void)
1135 {
1136   check ("exp (+0) == 1", FUNC(exp) (0), 1);
1137   check ("exp (-0) == 1", FUNC(exp) (minus_zero), 1);
1138
1139 #ifndef TEST_INLINE
1140   check_isinfp ("exp (+inf) == +inf", FUNC(exp) (plus_infty));
1141   check ("exp (-inf) == 0", FUNC(exp) (minus_infty), 0);
1142 #endif
1143   check_eps ("exp (1) == e", FUNC(exp) (1), M_E, CHOOSE (4e-18L, 5e-16, 0));
1144
1145   check ("exp (2) == e^2", FUNC(exp) (2), M_E * M_E);
1146   check ("exp (3) == e^3", FUNC(exp) (3), M_E * M_E * M_E);
1147 }
1148
1149
1150 static void
1151 exp2_test (void)
1152 {
1153   errno = 0;
1154   FUNC(exp2) (0);
1155   if (errno == ENOSYS)
1156     /* Function not implemented.  */
1157     return;
1158
1159   check ("exp2 (+0) == 1", FUNC(exp2) (0), 1);
1160   check ("exp2 (-0) == 1", FUNC(exp2) (minus_zero), 1);
1161
1162   check_isinfp ("exp2 (+inf) == +inf", FUNC(exp2) (plus_infty));
1163   check ("exp2 (-inf) == 0", FUNC(exp2) (minus_infty), 0);
1164   check ("exp2 (10) == 1024", FUNC(exp2) (10), 1024);
1165   check ("exp2 (-1) == 0.5", FUNC(exp2) (-1), 0.5);
1166   check_isinfp ("exp2 (1e6) == +inf", FUNC(exp2) (1e6));
1167   check ("exp2 (-1e6) == 0", FUNC(exp2) (-1e6), 0);
1168 }
1169
1170
1171 static void
1172 expm1_test (void)
1173 {
1174   check ("expm1 (+0) == 0", FUNC(expm1) (0), 0);
1175 #ifndef TEST_INLINE
1176   check ("expm1 (-0) == -0", FUNC(expm1) (minus_zero), minus_zero);
1177
1178   check_isinfp ("expm1 (+inf) == +inf", FUNC(expm1) (plus_infty));
1179   check ("expm1 (-inf) == -1", FUNC(expm1) (minus_infty), -1);
1180 #endif
1181
1182   check_eps ("expm1 (1) == e-1", FUNC(expm1) (1), M_E - 1.0,
1183              CHOOSE (4e-18L, 0, 2e-7));
1184 }
1185
1186
1187
1188
1189 static void
1190 check_frexp (const char *test_name, MATHTYPE computed, MATHTYPE expected,
1191              int comp_int, int exp_int)
1192 {
1193   MATHTYPE diff;
1194   int result;
1195
1196   result = (check_equal (computed, expected, 0, &diff)
1197             && (comp_int == exp_int));
1198
1199   if (result)
1200     {
1201       if (verbose > 2)
1202         printf ("Pass: %s\n", test_name);
1203     }
1204   else
1205     {
1206       if (verbose)
1207         printf ("Fail: %s\n", test_name);
1208       if (verbose > 1)
1209         {
1210           printf ("Result:\n");
1211           printf (" is:         %.20" PRINTF_EXPR " *2^%d  %.20"
1212                   PRINTF_XEXPR "*2^%d\n",
1213                   computed, comp_int, computed, comp_int);
1214           printf (" should be:  %.20" PRINTF_EXPR " *2^%d  %.20"
1215                   PRINTF_XEXPR "*2^%d\n",
1216                   expected, exp_int, expected, exp_int);
1217           printf (" difference: %.20" PRINTF_EXPR "  %.20" PRINTF_XEXPR "\n",
1218                   diff, diff);
1219         }
1220       noErrors++;
1221     }
1222   fpstack_test (test_name);
1223   output_result (test_name, result,
1224                  computed, expected, diff, PRINT, PRINT);
1225 }
1226
1227
1228 static void
1229 frexp_test (void)
1230 {
1231   int x_int;
1232   MATHTYPE result;
1233
1234   result = FUNC(frexp) (plus_infty, &x_int);
1235   check_isinfp ("frexp (+inf, expr) == +inf", result);
1236
1237   result = FUNC(frexp) (minus_infty, &x_int);
1238   check_isinfn ("frexp (-inf, expr) == -inf", result);
1239
1240   result = FUNC(frexp) (nan_value, &x_int);
1241   check_isnan ("frexp (Nan, expr) == NaN", result);
1242
1243   result = FUNC(frexp) (0, &x_int);
1244   check_frexp ("frexp: +0 == 0 * 2^0", result, 0, x_int, 0);
1245
1246   result = FUNC(frexp) (minus_zero, &x_int);
1247   check_frexp ("frexp: -0 == -0 * 2^0", result, minus_zero, x_int, 0);
1248
1249   result = FUNC(frexp) (12.8L, &x_int);
1250   check_frexp ("frexp: 12.8 == 0.8 * 2^4", result, 0.8L, x_int, 4);
1251
1252   result = FUNC(frexp) (-27.34L, &x_int);
1253   check_frexp ("frexp: -27.34 == -0.854375 * 2^5", result, -0.854375L, x_int, 5);
1254
1255 }
1256
1257
1258 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)
1259 /* All floating-point numbers can be put in one of these categories.  */
1260 enum
1261 {
1262   FP_NAN,
1263 #define FP_NAN FP_NAN
1264   FP_INFINITE,
1265 #define FP_INFINITE FP_INFINITE
1266   FP_ZERO,
1267 #define FP_ZERO FP_ZERO
1268   FP_SUBNORMAL,
1269 #define FP_SUBNORMAL FP_SUBNORMAL
1270   FP_NORMAL
1271 #define FP_NORMAL FP_NORMAL
1272 };
1273 #endif
1274
1275
1276 static void
1277 fpclassify_test (void)
1278 {
1279   MATHTYPE x;
1280
1281   /* fpclassify is a macro, don't give it constants as parameter */
1282   check_bool ("fpclassify (NaN) == FP_NAN", fpclassify (nan_value) == FP_NAN);
1283   check_bool ("fpclassify (+inf) == FP_INFINITE",
1284               fpclassify (plus_infty) == FP_INFINITE);
1285   check_bool ("fpclassify (-inf) == FP_INFINITE",
1286               fpclassify (minus_infty) == FP_INFINITE);
1287   check_bool ("fpclassify (+0) == FP_ZERO",
1288               fpclassify (plus_zero) == FP_ZERO);
1289   check_bool ("fpclassify (-0) == FP_ZERO",
1290               fpclassify (minus_zero) == FP_ZERO);
1291
1292   x = 1000.0;
1293   check_bool ("fpclassify (1000) == FP_NORMAL",
1294               fpclassify (x) == FP_NORMAL);
1295 }
1296
1297
1298 static void
1299 isfinite_test (void)
1300 {
1301   check_bool ("isfinite (0) != 0", isfinite (0));
1302   check_bool ("isfinite (-0) != 0", isfinite (minus_zero));
1303   check_bool ("isfinite (10) != 0", isfinite (10));
1304   check_bool ("isfinite (+inf) == 0", isfinite (plus_infty) == 0);
1305   check_bool ("isfinite (-inf) == 0", isfinite (minus_infty) == 0);
1306   check_bool ("isfinite (NaN) == 0", isfinite (nan_value) == 0);
1307 }
1308
1309
1310 static void
1311 isnormal_test (void)
1312 {
1313   check_bool ("isnormal (0) == 0", isnormal (0) == 0);
1314   check_bool ("isnormal (-0) == 0", isnormal (minus_zero) == 0);
1315   check_bool ("isnormal (10) != 0", isnormal (10));
1316   check_bool ("isnormal (+inf) == 0", isnormal (plus_infty) == 0);
1317   check_bool ("isnormal (-inf) == 0", isnormal (minus_infty) == 0);
1318   check_bool ("isnormal (NaN) == 0", isnormal (nan_value) == 0);
1319
1320 }
1321
1322
1323 static void
1324 signbit_test (void)
1325 {
1326   MATHTYPE x;
1327
1328   check_bool ("signbit (+0) == 0", signbit (0) == 0);
1329   check_bool ("signbit (-0) != 0", signbit (minus_zero));
1330   check_bool ("signbit (+inf) == 0", signbit (plus_infty) == 0);
1331   check_bool ("signbit (-inf) != 0", signbit (minus_infty));
1332
1333   x = random_less (0);
1334   check_bool ("signbit (x) != 0 for x < 0", signbit (x));
1335
1336   x = random_greater (0);
1337   check_bool ("signbit (x) == 0 for x > 0", signbit (x) == 0);
1338
1339 }
1340
1341
1342 /*
1343    gamma has different semantics depending on _LIB_VERSION:
1344    if _LIB_VERSION is _SVID, gamma is just an alias for lgamma,
1345    otherwise gamma is the real gamma function as definied in ISO C 9X.
1346 */
1347 static void
1348 gamma_test (void)
1349 {
1350   int save_lib_version = _LIB_VERSION;
1351   errno = 0;
1352   FUNC(gamma) (1);
1353   if (errno == ENOSYS)
1354     /* Function not implemented.  */
1355     return;
1356   feclearexcept (FE_ALL_EXCEPT);
1357
1358
1359   _LIB_VERSION = _SVID_;
1360
1361   check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
1362   check_isinfp_exc ("gamma (0) == +inf plus divide by zero exception",
1363                     FUNC(gamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1364
1365   check_isinfp_exc ("gamma (x) == +inf plus divide by zero exception for integer x <= 0",
1366                     FUNC(gamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1367   check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
1368                    FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
1369
1370   signgam = 0;
1371   check ("gamma (1) == 0", FUNC(gamma) (1), 0);
1372   check_int ("gamma (0) sets signgam to 1", signgam, 1);
1373
1374   signgam = 0;
1375   check ("gamma (3) == M_LN2", FUNC(gamma) (3), M_LN2);
1376   check_int ("gamma (3) sets signgam to 1", signgam, 1);
1377
1378   signgam = 0;
1379   check_eps ("gamma (0.5) == log(sqrt(pi))", FUNC(gamma) (0.5),
1380              FUNC(log) (FUNC(sqrt) (M_PI)), CHOOSE (0, 1e-15, 1e-7));
1381   check_int ("gamma (0.5) sets signgam to 1", signgam, 1);
1382
1383   signgam = 0;
1384   check_eps ("gamma (-0.5) == log(2*sqrt(pi))", FUNC(gamma) (-0.5),
1385              FUNC(log) (2*FUNC(sqrt) (M_PI)), CHOOSE (0, 1e-15, 0));
1386
1387   check_int ("gamma (-0.5) sets signgam to -1", signgam, -1);
1388
1389
1390   _LIB_VERSION = _IEEE_;
1391
1392   check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
1393   check_isnan_exc ("gamma (0) == NaN plus invalid exception",
1394                     FUNC(gamma) (0), INVALID_EXCEPTION);
1395
1396   check_isnan_exc_ext ("gamma (x) == NaN plus invalid exception for integer x <= 0",
1397                         FUNC(gamma) (-2), INVALID_EXCEPTION, -2);
1398   check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
1399                    FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
1400
1401   check_eps ("gamma (0.5) == sqrt(pi)", FUNC(gamma) (0.5), FUNC(sqrt) (M_PI),
1402              CHOOSE (0, 5e-16, 2e-7));
1403   check_eps ("gamma (-0.5) == -2*sqrt(pi)", FUNC(gamma) (-0.5),
1404              -2*FUNC(sqrt) (M_PI), CHOOSE (0, 5e-16, 3e-7));
1405
1406   check ("gamma (1) == 1", FUNC(gamma) (1), 1);
1407   check ("gamma (4) == 6", FUNC(gamma) (4), 6);
1408
1409   _LIB_VERSION = save_lib_version;
1410 }
1411
1412
1413 static void
1414 lgamma_test (void)
1415 {
1416   errno = 0;
1417   FUNC(lgamma) (0);
1418   if (errno == ENOSYS)
1419     /* Function not implemented.  */
1420     return;
1421   feclearexcept (FE_ALL_EXCEPT);
1422
1423   check_isinfp ("lgamma (+inf) == +inf", FUNC(lgamma) (plus_infty));
1424   check_isinfp_exc ("lgamma (0) == +inf plus divide by zero exception",
1425                     FUNC(lgamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1426
1427   check_isinfp_exc ("lgamma (x) == +inf plus divide by zero exception for integer x <= 0",
1428                     FUNC(lgamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1429   check_isnan_exc ("lgamma (-inf) == NaN plus invalid exception",
1430                    FUNC(lgamma) (minus_infty), INVALID_EXCEPTION);
1431
1432   signgam = 0;
1433   check ("lgamma (1) == 0", FUNC(lgamma) (1), 0);
1434   check_int ("lgamma (0) sets signgam to 1", signgam, 1);
1435
1436   signgam = 0;
1437   check ("lgamma (3) == M_LN2", FUNC(lgamma) (3), M_LN2);
1438   check_int ("lgamma (3) sets signgam to 1", signgam, 1);
1439
1440   signgam = 0;
1441   check_eps ("lgamma (0.5) == log(sqrt(pi))", FUNC(lgamma) (0.5),
1442              FUNC(log) (FUNC(sqrt) (M_PI)), CHOOSE (0, 1e-15, 1e-7));
1443   check_int ("lgamma (0.5) sets signgam to 1", signgam, 1);
1444
1445   signgam = 0;
1446   check_eps ("lgamma (-0.5) == log(2*sqrt(pi))", FUNC(lgamma) (-0.5),
1447              FUNC(log) (2*FUNC(sqrt) (M_PI)), CHOOSE (0, 1e-15, 0));
1448
1449   check_int ("lgamma (-0.5) sets signgam to -1", signgam, -1);
1450
1451 }
1452
1453
1454 static void
1455 ilogb_test (void)
1456 {
1457   int i;
1458
1459   check_int ("ilogb (1) == 0", FUNC(ilogb) (1), 0);
1460   check_int ("ilogb (e) == 1", FUNC(ilogb) (M_E), 1);
1461   check_int ("ilogb (1024) == 10", FUNC(ilogb) (1024), 10);
1462   check_int ("ilogb (-2000) == 10", FUNC(ilogb) (-2000), 10);
1463
1464   /* XXX We have a problem here: the standard does not tell us whether
1465      exceptions are allowed/required.  ignore them for now.  */
1466   i = FUNC (ilogb) (0.0);
1467   feclearexcept (FE_ALL_EXCEPT);
1468   check_int ("ilogb (0) == FP_ILOGB0", i, FP_ILOGB0);
1469   i = FUNC(ilogb) (nan_value);
1470   feclearexcept (FE_ALL_EXCEPT);
1471   check_int ("ilogb (NaN) == FP_ILOGBNAN", i, FP_ILOGBNAN);
1472
1473 }
1474
1475
1476 static void
1477 ldexp_test (void)
1478 {
1479   MATHTYPE x;
1480
1481   check ("ldexp (0, 0) == 0", FUNC(ldexp) (0, 0), 0);
1482
1483   check_isinfp ("ldexp (+inf, 1) == +inf", FUNC(ldexp) (plus_infty, 1));
1484   check_isinfn ("ldexp (-inf, 1) == -inf", FUNC(ldexp) (minus_infty, 1));
1485   check_isnan ("ldexp (NaN, 1) == NaN", FUNC(ldexp) (nan_value, 1));
1486
1487   check ("ldexp (0.8, 4) == 12.8", FUNC(ldexp) (0.8L, 4), 12.8L);
1488   check ("ldexp (-0.854375, 5) == -27.34", FUNC(ldexp) (-0.854375L, 5), -27.34L);
1489
1490   x = random_greater (0.0);
1491   check_ext ("ldexp (x, 0) == x", FUNC(ldexp) (x, 0L), x, x);
1492
1493 }
1494
1495
1496 static void
1497 log_test (void)
1498 {
1499   check_isinfn_exc ("log (+0) == -inf plus divide-by-zero exception",
1500                     FUNC(log) (0), DIVIDE_BY_ZERO_EXCEPTION);
1501   check_isinfn_exc ("log (-0) == -inf plus divide-by-zero exception",
1502                     FUNC(log) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1503
1504   check ("log (1) == 0", FUNC(log) (1), 0);
1505
1506   check_isnan_exc ("log (x) == NaN plus invalid exception if x < 0",
1507                    FUNC(log) (-1), INVALID_EXCEPTION);
1508   check_isinfp ("log (+inf) == +inf", FUNC(log) (plus_infty));
1509
1510   check_eps ("log (e) == 1", FUNC(log) (M_E), 1, CHOOSE (1e-18L, 0, 9e-8L));
1511   check_eps ("log (1/e) == -1", FUNC(log) (1.0 / M_E), -1,
1512              CHOOSE (2e-18L, 0, 0));
1513   check ("log (2) == M_LN2", FUNC(log) (2), M_LN2);
1514   check_eps ("log (10) == M_LN10", FUNC(log) (10), M_LN10,
1515              CHOOSE (1e-18L, 0, 0));
1516 }
1517
1518
1519 static void
1520 log10_test (void)
1521 {
1522   check_isinfn_exc ("log10 (+0) == -inf plus divide-by-zero exception",
1523                     FUNC(log10) (0), DIVIDE_BY_ZERO_EXCEPTION);
1524   check_isinfn_exc ("log10 (-0) == -inf plus divide-by-zero exception",
1525                     FUNC(log10) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1526
1527   check ("log10 (1) == +0", FUNC(log10) (1), 0);
1528
1529   check_isnan_exc ("log10 (x) == NaN plus invalid exception if x < 0",
1530                    FUNC(log10) (-1), INVALID_EXCEPTION);
1531
1532   check_isinfp ("log10 (+inf) == +inf", FUNC(log10) (plus_infty));
1533
1534   check_eps ("log10 (0.1) == -1", FUNC(log10) (0.1L), -1,
1535              CHOOSE (1e-18L, 0, 0));
1536   check_eps ("log10 (10) == 1", FUNC(log10) (10.0), 1,
1537              CHOOSE (1e-18L, 0, 0));
1538   check_eps ("log10 (100) == 2", FUNC(log10) (100.0), 2,
1539              CHOOSE (1e-18L, 0, 0));
1540   check ("log10 (10000) == 4", FUNC(log10) (10000.0), 4);
1541   check_eps ("log10 (e) == M_LOG10E", FUNC(log10) (M_E), M_LOG10E,
1542              CHOOSE (1e-18, 0, 9e-8));
1543 }
1544
1545
1546 static void
1547 log1p_test (void)
1548 {
1549   check ("log1p (+0) == +0", FUNC(log1p) (0), 0);
1550   check ("log1p (-0) == -0", FUNC(log1p) (minus_zero), minus_zero);
1551
1552   check_isinfn_exc ("log1p (-1) == -inf plus divide-by-zero exception",
1553                     FUNC(log1p) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1554   check_isnan_exc ("log1p (x) == NaN plus invalid exception if x < -1",
1555                    FUNC(log1p) (-2), INVALID_EXCEPTION);
1556
1557   check_isinfp ("log1p (+inf) == +inf", FUNC(log1p) (plus_infty));
1558
1559   check_eps ("log1p (e-1) == 1", FUNC(log1p) (M_E - 1.0), 1,
1560              CHOOSE (1e-18L, 0, 6e-8));
1561
1562 }
1563
1564
1565 static void
1566 log2_test (void)
1567 {
1568   check_isinfn_exc ("log2 (+0) == -inf plus divide-by-zero exception",
1569                     FUNC(log2) (0), DIVIDE_BY_ZERO_EXCEPTION);
1570   check_isinfn_exc ("log2 (-0) == -inf plus divide-by-zero exception",
1571                     FUNC(log2) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1572
1573   check ("log2 (1) == +0", FUNC(log2) (1), 0);
1574
1575   check_isnan_exc ("log2 (x) == NaN plus invalid exception if x < 0",
1576                    FUNC(log2) (-1), INVALID_EXCEPTION);
1577
1578   check_isinfp ("log2 (+inf) == +inf", FUNC(log2) (plus_infty));
1579
1580   check_eps ("log2 (e) == M_LOG2E", FUNC(log2) (M_E), M_LOG2E,
1581              CHOOSE (1e-18L, 0, 0));
1582   check ("log2 (2) == 1", FUNC(log2) (2.0), 1);
1583   check_eps ("log2 (16) == 4", FUNC(log2) (16.0), 4, CHOOSE (1e-18L, 0, 0));
1584   check ("log2 (256) == 8", FUNC(log2) (256.0), 8);
1585
1586 }
1587
1588
1589 static void
1590 logb_test (void)
1591 {
1592   check_isinfp ("logb (+inf) == +inf", FUNC(logb) (plus_infty));
1593   check_isinfp ("logb (-inf) == +inf", FUNC(logb) (minus_infty));
1594
1595   check_isinfn_exc ("logb (+0) == -inf plus divide-by-zero exception",
1596                     FUNC(logb) (0), DIVIDE_BY_ZERO_EXCEPTION);
1597
1598   check_isinfn_exc ("logb (-0) == -inf plus divide-by-zero exception",
1599                     FUNC(logb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1600
1601   check ("logb (1) == 0", FUNC(logb) (1), 0);
1602   check ("logb (e) == 1", FUNC(logb) (M_E), 1);
1603   check ("logb (1024) == 10", FUNC(logb) (1024), 10);
1604   check ("logb (-2000) == 10", FUNC(logb) (-2000), 10);
1605
1606 }
1607
1608
1609 static void
1610 modf_test (void)
1611 {
1612   MATHTYPE result, intpart;
1613
1614   result = FUNC(modf) (plus_infty, &intpart);
1615   check ("modf (+inf, &x) returns +0", result, 0);
1616   check_isinfp ("modf (+inf, &x) set x to +inf", intpart);
1617
1618   result = FUNC(modf) (minus_infty, &intpart);
1619   check ("modf (-inf, &x) returns -0", result, minus_zero);
1620   check_isinfn ("modf (-inf, &x) sets x to -inf", intpart);
1621
1622   result = FUNC(modf) (nan_value, &intpart);
1623   check_isnan ("modf (NaN, &x) returns NaN", result);
1624   check_isnan ("modf (NaN, &x) sets x to NaN", intpart);
1625
1626   result = FUNC(modf) (0, &intpart);
1627   check ("modf (0, &x) returns 0", result, 0);
1628   check ("modf (0, &x) sets x to 0", intpart, 0);
1629
1630   result = FUNC(modf) (minus_zero, &intpart);
1631   check ("modf (-0, &x) returns -0", result, minus_zero);
1632   check ("modf (-0, &x) sets x to -0", intpart, minus_zero);
1633
1634   result = FUNC(modf) (2.5, &intpart);
1635   check ("modf (2.5, &x) returns 0.5", result, 0.5);
1636   check ("modf (2.5, &x) sets x to 2", intpart, 2);
1637
1638   result = FUNC(modf) (-2.5, &intpart);
1639   check ("modf (-2.5, &x) returns -0.5", result, -0.5);
1640   check ("modf (-2.5, &x) sets x to -2", intpart, -2);
1641
1642 }
1643
1644
1645 static void
1646 scalb_test (void)
1647 {
1648   MATHTYPE x;
1649
1650   check_isnan ("scalb (2, 0.5) == NaN", FUNC(scalb) (2, 0.5));
1651   check_isnan ("scalb (3, -2.5) == NaN", FUNC(scalb) (3, -2.5));
1652
1653   check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1654   check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1655
1656   x = random_greater (0.0);
1657   check ("scalb (x, 0) == 0", FUNC(scalb) (x, 0), x);
1658   x = random_greater (0.0);
1659   check ("scalb (-x, 0) == 0", FUNC(scalb) (-x, 0), -x);
1660
1661   check_isnan_exc ("scalb (+0, +inf) == NaN plus invalid exception",
1662                    FUNC(scalb) (0, plus_infty), INVALID_EXCEPTION);
1663   check_isnan_exc ("scalb (-0, +inf) == NaN plus invalid exception",
1664                    FUNC(scalb) (minus_zero, plus_infty), INVALID_EXCEPTION);
1665
1666   check ("scalb (+0, 2) == +0", FUNC(scalb) (0, 2), 0);
1667   check ("scalb (-0, 4) == -0", FUNC(scalb) (minus_zero, -4), minus_zero);
1668   check ("scalb (+0, 0) == +0", FUNC(scalb) (0, 0), 0);
1669   check ("scalb (-0, 0) == -0", FUNC(scalb) (minus_zero, 0), minus_zero);
1670   check ("scalb (+0, -1) == +0", FUNC(scalb) (0, -1), 0);
1671   check ("scalb (-0, -10) == -0", FUNC(scalb) (minus_zero, -10), minus_zero);
1672   check ("scalb (+0, -inf) == +0", FUNC(scalb) (0, minus_infty), 0);
1673   check ("scalb (-0, -inf) == -0", FUNC(scalb) (minus_zero, minus_infty),
1674          minus_zero);
1675
1676   check_isinfp ("scalb (+inf, -1) == +inf", FUNC(scalb) (plus_infty, -1));
1677   check_isinfn ("scalb (-inf, -10) == -inf", FUNC(scalb) (minus_infty, -10));
1678   check_isinfp ("scalb (+inf, 0) == +inf", FUNC(scalb) (plus_infty, 0));
1679   check_isinfn ("scalb (-inf, 0) == -inf", FUNC(scalb) (minus_infty, 0));
1680   check_isinfp ("scalb (+inf, 2) == +inf", FUNC(scalb) (plus_infty, 2));
1681   check_isinfn ("scalb (-inf, 100) == -inf", FUNC(scalb) (minus_infty, 100));
1682
1683   x = random_greater (0.0);
1684   check ("scalb (x, -inf) == 0", FUNC(scalb) (x, minus_infty), 0.0);
1685   check ("scalb (-x, -inf) == -0", FUNC(scalb) (-x, minus_infty), minus_zero);
1686
1687   x = random_greater (0.0);
1688   check_isinfp ("scalb (x, +inf) == +inf", FUNC(scalb) (x, plus_infty));
1689   x = random_greater (0.0);
1690   check_isinfn ("scalb (-x, +inf) == -inf", FUNC(scalb) (-x, plus_infty));
1691   check_isinfp ("scalb (+inf, +inf) == +inf",
1692                 FUNC(scalb) (plus_infty, plus_infty));
1693   check_isinfn ("scalb (-inf, +inf) == -inf",
1694                 FUNC(scalb) (minus_infty, plus_infty));
1695
1696   check_isnan ("scalb (+inf, -inf) == NaN",
1697                FUNC(scalb) (plus_infty, minus_infty));
1698   check_isnan ("scalb (-inf, -inf) == NaN",
1699                FUNC(scalb) (minus_infty, minus_infty));
1700
1701   check_isnan ("scalb (NaN, 1) == NaN", FUNC(scalb) (nan_value, 1));
1702   check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1703   check_isnan ("scalb (NaN, 0) == NaN", FUNC(scalb) (nan_value, 0));
1704   check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1705   check_isnan ("scalb (NaN, +inf) == NaN",
1706                FUNC(scalb) (nan_value, plus_infty));
1707   check_isnan ("scalb (+inf, NaN) == NaN",
1708                FUNC(scalb) (plus_infty, nan_value));
1709   check_isnan ("scalb (NaN, NaN) == NaN", FUNC(scalb) (nan_value, nan_value));
1710
1711   check ("scalb (0.8, 4) == 12.8", FUNC(scalb) (0.8L, 4), 12.8L);
1712   check ("scalb (-0.854375, 5) == -27.34", FUNC(scalb) (-0.854375L, 5), -27.34L);
1713 }
1714
1715
1716 static void
1717 scalbn_test (void)
1718 {
1719   MATHTYPE x;
1720
1721   check ("scalbn (0, 0) == 0", FUNC(scalbn) (0, 0), 0);
1722
1723   check_isinfp ("scalbn (+inf, 1) == +inf", FUNC(scalbn) (plus_infty, 1));
1724   check_isinfn ("scalbn (-inf, 1) == -inf", FUNC(scalbn) (minus_infty, 1));
1725   check_isnan ("scalbn (NaN, 1) == NaN", FUNC(scalbn) (nan_value, 1));
1726
1727   check ("scalbn (0.8, 4) == 12.8", FUNC(scalbn) (0.8L, 4), 12.8L);
1728   check ("scalbn (-0.854375, 5) == -27.34", FUNC(scalbn) (-0.854375L, 5), -27.34L);
1729
1730   x = random_greater (0.0);
1731   check_ext ("scalbn (x, 0) == x", FUNC(scalbn) (x, 0L), x, x);
1732 }
1733
1734
1735 static void
1736 sin_test (void)
1737 {
1738   check ("sin (+0) == +0", FUNC(sin) (0), 0);
1739   check ("sin (-0) == -0", FUNC(sin) (minus_zero), minus_zero);
1740   check_isnan_exc ("sin (+inf) == NaN plus invalid exception",
1741                    FUNC(sin) (plus_infty),
1742                    INVALID_EXCEPTION);
1743   check_isnan_exc ("sin (-inf) == NaN plus invalid exception",
1744                    FUNC(sin) (minus_infty),
1745                    INVALID_EXCEPTION);
1746
1747   check_eps ("sin (pi/6) == 0.5", FUNC(sin) (M_PI_6),
1748              0.5, CHOOSE (4e-18L, 0, 0));
1749   check_eps ("sin (-pi/6) == -0.5", FUNC(sin) (-M_PI_6),
1750              -0.5, CHOOSE (4e-18L, 0, 0));
1751   check ("sin (pi/2) == 1", FUNC(sin) (M_PI_2), 1);
1752   check ("sin (-pi/2) == -1", FUNC(sin) (-M_PI_2), -1);
1753 }
1754
1755
1756 static void
1757 sinh_test (void)
1758 {
1759   check ("sinh (+0) == +0", FUNC(sinh) (0), 0);
1760
1761 #ifndef TEST_INLINE
1762   check ("sinh (-0) == -0", FUNC(sinh) (minus_zero), minus_zero);
1763
1764   check_isinfp ("sinh (+inf) == +inf", FUNC(sinh) (plus_infty));
1765   check_isinfn ("sinh (-inf) == -inf", FUNC(sinh) (minus_infty));
1766 #endif
1767 }
1768
1769
1770 static void
1771 sincos_test (void)
1772 {
1773   MATHTYPE sin_res, cos_res;
1774   fenv_t fenv;
1775
1776   FUNC(sincos) (0, &sin_res, &cos_res);
1777   fegetenv (&fenv);
1778   check ("sincos (+0, &sin, &cos) puts +0 in sin", sin_res, 0);
1779   fesetenv (&fenv);
1780   check ("sincos (+0, &sin, &cos) puts 1 in cos", cos_res, 1);
1781
1782   FUNC(sincos) (minus_zero, &sin_res, &cos_res);
1783   fegetenv (&fenv);
1784   check ("sincos (-0, &sin, &cos) puts -0 in sin", sin_res, minus_zero);
1785   fesetenv (&fenv);
1786   check ("sincos (-0, &sin, &cos) puts 1 in cos", cos_res, 1);
1787
1788   FUNC(sincos) (plus_infty, &sin_res, &cos_res);
1789   fegetenv (&fenv);
1790   check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in sin plus invalid exception",
1791                    sin_res, INVALID_EXCEPTION);
1792   fesetenv (&fenv);
1793   check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in cos plus invalid exception",
1794                    cos_res, INVALID_EXCEPTION);
1795
1796   FUNC(sincos) (minus_infty, &sin_res, &cos_res);
1797   fegetenv (&fenv);
1798   check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in sin plus invalid exception",
1799                    sin_res, INVALID_EXCEPTION);
1800   fesetenv (&fenv);
1801   check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in cos plus invalid exception",
1802                    cos_res, INVALID_EXCEPTION);
1803
1804   FUNC(sincos) (M_PI_2, &sin_res, &cos_res);
1805   fegetenv (&fenv);
1806   check ("sincos (pi/2, &sin, &cos) puts 1 in sin", sin_res, 1);
1807   fesetenv (&fenv);
1808   check_eps ("sincos (pi/2, &sin, &cos) puts 0 in cos", cos_res, 0,
1809              CHOOSE (1e-18L, 1e-16, 1e-7));
1810
1811   FUNC(sincos) (M_PI_6, &sin_res, &cos_res);
1812   check_eps ("sincos (pi/6, &sin, &cos) puts 0.5 in sin", sin_res, 0.5,
1813              CHOOSE (5e-18L, 0, 0));
1814
1815   FUNC(sincos) (M_PI_6*2.0, &sin_res, &cos_res);
1816   check_eps ("sincos (pi/3, &sin, &cos) puts 0.5 in cos", cos_res, 0.5,
1817              CHOOSE (5e-18L, 1e-15, 1e-7));
1818
1819
1820 }
1821
1822
1823 static void
1824 tan_test (void)
1825 {
1826   check ("tan (+0) == +0", FUNC(tan) (0), 0);
1827   check ("tan (-0) == -0", FUNC(tan) (minus_zero), minus_zero);
1828   check_isnan_exc ("tan (+inf) == NaN plus invalid exception",
1829                    FUNC(tan) (plus_infty), INVALID_EXCEPTION);
1830   check_isnan_exc ("tan (-inf) == NaN plus invalid exception",
1831                    FUNC(tan) (minus_infty), INVALID_EXCEPTION);
1832
1833   check_eps ("tan (pi/4) == 1", FUNC(tan) (M_PI_4), 1,
1834              CHOOSE (2e-18L, 1e-15L, 2e-7));
1835 }
1836
1837
1838 static void
1839 tanh_test (void)
1840 {
1841   check ("tanh (+0) == +0", FUNC(tanh) (0), 0);
1842 #ifndef TEST_INLINE
1843   check ("tanh (-0) == -0", FUNC(tanh) (minus_zero), minus_zero);
1844
1845   check ("tanh (+inf) == +1", FUNC(tanh) (plus_infty), 1);
1846   check ("tanh (-inf) == -1", FUNC(tanh) (minus_infty), -1);
1847 #endif
1848 }
1849
1850
1851 static void
1852 fabs_test (void)
1853 {
1854   check ("fabs (+0) == +0", FUNC(fabs) (0), 0);
1855   check ("fabs (-0) == +0", FUNC(fabs) (minus_zero), 0);
1856
1857   check_isinfp ("fabs (+inf) == +inf", FUNC(fabs) (plus_infty));
1858   check_isinfp ("fabs (-inf) == +inf", FUNC(fabs) (minus_infty));
1859
1860   check ("fabs (+38) == 38", FUNC(fabs) (38.0), 38.0);
1861   check ("fabs (-e) == e", FUNC(fabs) (-M_E), M_E);
1862 }
1863
1864
1865 static void
1866 floor_test (void)
1867 {
1868   check ("floor (+0) == +0", FUNC(floor) (0.0), 0.0);
1869   check ("floor (-0) == -0", FUNC(floor) (minus_zero), minus_zero);
1870   check_isinfp ("floor (+inf) == +inf", FUNC(floor) (plus_infty));
1871   check_isinfn ("floor (-inf) == -inf", FUNC(floor) (minus_infty));
1872
1873   check ("floor (pi) == 3", FUNC(floor) (M_PI), 3.0);
1874   check ("floor (-pi) == -4", FUNC(floor) (-M_PI), -4.0);
1875 }
1876
1877
1878 static void
1879 hypot_test (void)
1880 {
1881   MATHTYPE a;
1882
1883   a = random_greater (0);
1884   check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot) (plus_infty, a), a);
1885   check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot) (minus_infty, a), a);
1886
1887 #ifndef TEST_INLINE
1888   check_isinfp ("hypot (+inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
1889   check_isinfp ("hypot (-inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
1890 #endif
1891
1892   check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot) (nan_value, nan_value));
1893
1894   a = FUNC(hypot) (12.4L, 0.7L);
1895   check ("hypot (x,y) == hypot (y,x)", FUNC(hypot) (0.7L, 12.4L), a);
1896   check ("hypot (x,y) == hypot (-x,y)", FUNC(hypot) (-12.4L, 0.7L), a);
1897   check ("hypot (x,y) == hypot (-y,x)", FUNC(hypot) (-0.7L, 12.4L), a);
1898   check ("hypot (x,y) == hypot (-x,-y)", FUNC(hypot) (-12.4L, -0.7L), a);
1899   check ("hypot (x,y) == hypot (-y,-x)", FUNC(hypot) (-0.7L, -12.4L), a);
1900   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-0.7L, 0), 0.7L);
1901   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (0.7L, 0), 0.7L);
1902   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-1.0L, 0), 1.0L);
1903   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (1.0L, 0), 1.0L);
1904   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-5.7e7L, 0), 5.7e7L);
1905   check ("hypot (x,0) == fabs (x)", FUNC(hypot) (5.7e7L, 0), 5.7e7L);
1906 }
1907
1908
1909 static void
1910 pow_test (void)
1911 {
1912   MATHTYPE x;
1913
1914   check ("pow (+0, +0) == 1", FUNC(pow) (0, 0), 1);
1915   check ("pow (+0, -0) == 1", FUNC(pow) (0, minus_zero), 1);
1916   check ("pow (-0, +0) == 1", FUNC(pow) (minus_zero, 0), 1);
1917   check ("pow (-0, -0) == 1", FUNC(pow) (minus_zero, minus_zero), 1);
1918
1919   check ("pow (+10, +0) == 1", FUNC(pow) (10, 0), 1);
1920   check ("pow (+10, -0) == 1", FUNC(pow) (10, minus_zero), 1);
1921   check ("pow (-10, +0) == 1", FUNC(pow) (-10, 0), 1);
1922   check ("pow (-10, -0) == 1", FUNC(pow) (-10, minus_zero), 1);
1923
1924   check ("pow (NaN, +0) == 1", FUNC(pow) (nan_value, 0), 1);
1925   check ("pow (NaN, -0) == 1", FUNC(pow) (nan_value, minus_zero), 1);
1926
1927 #ifndef TEST_INLINE
1928   check_isinfp ("pow (+1.1, +inf) == +inf", FUNC(pow) (1.1, plus_infty));
1929   check_isinfp ("pow (+inf, +inf) == +inf", FUNC(pow) (plus_infty, plus_infty));
1930   check_isinfp ("pow (-1.1, +inf) == +inf", FUNC(pow) (-1.1, plus_infty));
1931   check_isinfp ("pow (-inf, +inf) == +inf", FUNC(pow) (minus_infty, plus_infty));
1932
1933   check ("pow (0.9, +inf) == +0", FUNC(pow) (0.9L, plus_infty), 0);
1934   check ("pow (1e-7, +inf) == +0", FUNC(pow) (1e-7L, plus_infty), 0);
1935   check ("pow (-0.9, +inf) == +0", FUNC(pow) (-0.9L, plus_infty), 0);
1936   check ("pow (-1e-7, +inf) == +0", FUNC(pow) (-1e-7L, plus_infty), 0);
1937
1938   check ("pow (+1.1, -inf) == 0", FUNC(pow) (1.1, minus_infty), 0);
1939   check ("pow (+inf, -inf) == 0", FUNC(pow) (plus_infty, minus_infty), 0);
1940   check ("pow (-1.1, -inf) == 0", FUNC(pow) (-1.1, minus_infty), 0);
1941   check ("pow (-inf, -inf) == 0", FUNC(pow) (minus_infty, minus_infty), 0);
1942
1943   check_isinfp ("pow (0.9, -inf) == +inf", FUNC(pow) (0.9L, minus_infty));
1944   check_isinfp ("pow (1e-7, -inf) == +inf", FUNC(pow) (1e-7L, minus_infty));
1945   check_isinfp ("pow (-0.9, -inf) == +inf", FUNC(pow) (-0.9L, minus_infty));
1946   check_isinfp ("pow (-1e-7, -inf) == +inf", FUNC(pow) (-1e-7L, minus_infty));
1947
1948   check_isinfp ("pow (+inf, 1e-7) == +inf", FUNC(pow) (plus_infty, 1e-7L));
1949   check_isinfp ("pow (+inf, 1) == +inf", FUNC(pow) (plus_infty, 1));
1950   check_isinfp ("pow (+inf, 1e7) == +inf", FUNC(pow) (plus_infty, 1e7L));
1951
1952   check ("pow (+inf, -1e-7) == 0", FUNC(pow) (plus_infty, -1e-7L), 0);
1953   check ("pow (+inf, -1) == 0", FUNC(pow) (plus_infty, -1), 0);
1954   check ("pow (+inf, -1e7) == 0", FUNC(pow) (plus_infty, -1e7L), 0);
1955
1956   check_isinfn ("pow (-inf, 1) == -inf", FUNC(pow) (minus_infty, 1));
1957   check_isinfn ("pow (-inf, 11) == -inf", FUNC(pow) (minus_infty, 11));
1958   check_isinfn ("pow (-inf, 1001) == -inf", FUNC(pow) (minus_infty, 1001));
1959
1960   check_isinfp ("pow (-inf, 2) == +inf", FUNC(pow) (minus_infty, 2));
1961   check_isinfp ("pow (-inf, 12) == +inf", FUNC(pow) (minus_infty, 12));
1962   check_isinfp ("pow (-inf, 1002) == +inf", FUNC(pow) (minus_infty, 1002));
1963   check_isinfp ("pow (-inf, 0.1) == +inf", FUNC(pow) (minus_infty, 0.1));
1964   check_isinfp ("pow (-inf, 1.1) == +inf", FUNC(pow) (minus_infty, 1.1));
1965   check_isinfp ("pow (-inf, 11.1) == +inf", FUNC(pow) (minus_infty, 11.1));
1966   check_isinfp ("pow (-inf, 1001.1) == +inf", FUNC(pow) (minus_infty, 1001.1));
1967
1968   check ("pow (-inf, -1) == -0", FUNC(pow) (minus_infty, -1), minus_zero);
1969   check ("pow (-inf, -11) == -0", FUNC(pow) (minus_infty, -11), minus_zero);
1970   check ("pow (-inf, -1001) == -0", FUNC(pow) (minus_infty, -1001), minus_zero);
1971
1972   check ("pow (-inf, -2) == +0", FUNC(pow) (minus_infty, -2), 0);
1973   check ("pow (-inf, -12) == +0", FUNC(pow) (minus_infty, -12), 0);
1974   check ("pow (-inf, -1002) == +0", FUNC(pow) (minus_infty, -1002), 0);
1975   check ("pow (-inf, -0.1) == +0", FUNC(pow) (minus_infty, -0.1), 0);
1976   check ("pow (-inf, -1.1) == +0", FUNC(pow) (minus_infty, -1.1), 0);
1977   check ("pow (-inf, -11.1) == +0", FUNC(pow) (minus_infty, -11.1), 0);
1978   check ("pow (-inf, -1001.1) == +0", FUNC(pow) (minus_infty, -1001.1), 0);
1979
1980   check_isnan ("pow (NaN, NaN) == NaN", FUNC(pow) (nan_value, nan_value));
1981   check_isnan ("pow (0, NaN) == NaN", FUNC(pow) (0, nan_value));
1982   check_isnan ("pow (1, NaN) == NaN", FUNC(pow) (1, nan_value));
1983   check_isnan ("pow (-1, NaN) == NaN", FUNC(pow) (-1, nan_value));
1984   check_isnan ("pow (NaN, 1) == NaN", FUNC(pow) (nan_value, 1));
1985   check_isnan ("pow (NaN, -1) == NaN", FUNC(pow) (nan_value, -1));
1986
1987   x = random_greater (0.0);
1988   check_isnan_ext ("pow (x, NaN) == NaN", FUNC(pow) (x, nan_value), x);
1989
1990   check_isnan_exc ("pow (+1, +inf) == NaN plus invalid exception",
1991                    FUNC(pow) (1, plus_infty), INVALID_EXCEPTION);
1992   check_isnan_exc ("pow (-1, +inf) == NaN plus invalid exception",
1993                    FUNC(pow) (-1, plus_infty), INVALID_EXCEPTION);
1994   check_isnan_exc ("pow (+1, -inf) == NaN plus invalid exception",
1995                    FUNC(pow) (1, minus_infty), INVALID_EXCEPTION);
1996   check_isnan_exc ("pow (-1, -inf) == NaN plus invalid exception",
1997                    FUNC(pow) (-1, minus_infty), INVALID_EXCEPTION);
1998
1999   check_isnan_exc ("pow (-0.1, 1.1) == NaN plus invalid exception",
2000                    FUNC(pow) (-0.1, 1.1), INVALID_EXCEPTION);
2001   check_isnan_exc ("pow (-0.1, -1.1) == NaN plus invalid exception",
2002                    FUNC(pow) (-0.1, -1.1), INVALID_EXCEPTION);
2003   check_isnan_exc ("pow (-10.1, 1.1) == NaN plus invalid exception",
2004                    FUNC(pow) (-10.1, 1.1), INVALID_EXCEPTION);
2005   check_isnan_exc ("pow (-10.1, -1.1) == NaN plus invalid exception",
2006                    FUNC(pow) (-10.1, -1.1), INVALID_EXCEPTION);
2007
2008   check_isinfp_exc ("pow (+0, -1) == +inf plus divide-by-zero exception",
2009                     FUNC(pow) (0, -1), DIVIDE_BY_ZERO_EXCEPTION);
2010   check_isinfp_exc ("pow (+0, -11) == +inf plus divide-by-zero exception",
2011                     FUNC(pow) (0, -11), DIVIDE_BY_ZERO_EXCEPTION);
2012   check_isinfn_exc ("pow (-0, -1) == -inf plus divide-by-zero exception",
2013                     FUNC(pow) (minus_zero, -1), DIVIDE_BY_ZERO_EXCEPTION);
2014   check_isinfn_exc ("pow (-0, -11) == -inf plus divide-by-zero exception",
2015                     FUNC(pow) (minus_zero, -11), DIVIDE_BY_ZERO_EXCEPTION);
2016
2017   check_isinfp_exc ("pow (+0, -2) == +inf plus divide-by-zero exception",
2018                     FUNC(pow) (0, -2), DIVIDE_BY_ZERO_EXCEPTION);
2019   check_isinfp_exc ("pow (+0, -11.1) == +inf plus divide-by-zero exception",
2020                     FUNC(pow) (0, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2021   check_isinfp_exc ("pow (-0, -2) == +inf plus divide-by-zero exception",
2022                     FUNC(pow) (minus_zero, -2), DIVIDE_BY_ZERO_EXCEPTION);
2023   check_isinfp_exc ("pow (-0, -11.1) == +inf plus divide-by-zero exception",
2024                     FUNC(pow) (minus_zero, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2025 #endif
2026
2027   check ("pow (+0, 1) == +0", FUNC(pow) (0, 1), 0);
2028   check ("pow (+0, 11) == +0", FUNC(pow) (0, 11), 0);
2029 #ifndef TEST_INLINE
2030   check ("pow (-0, 1) == -0", FUNC(pow) (minus_zero, 1), minus_zero);
2031   check ("pow (-0, 11) == -0", FUNC(pow) (minus_zero, 11), minus_zero);
2032 #endif
2033
2034   check ("pow (+0, 2) == +0", FUNC(pow) (0, 2), 0);
2035   check ("pow (+0, 11.1) == +0", FUNC(pow) (0, 11.1), 0);
2036
2037 #ifndef TEST_INLINE
2038   check ("pow (-0, 2) == +0", FUNC(pow) (minus_zero, 2), 0);
2039   check ("pow (-0, 11.1) == +0", FUNC(pow) (minus_zero, 11.1), 0);
2040
2041   x = random_greater (1.0);
2042   check_isinfp_ext ("pow (x, +inf) == +inf for |x| > 1",
2043                     FUNC(pow) (x, plus_infty), x);
2044
2045   x = random_value (-1.0, 1.0);
2046   check_ext ("pow (x, +inf) == +0 for |x| < 1",
2047              FUNC(pow) (x, plus_infty), 0.0, x);
2048
2049   x = random_greater (1.0);
2050   check_ext ("pow (x, -inf) == +0 for |x| > 1",
2051              FUNC(pow) (x, minus_infty), 0.0, x);
2052
2053   x = random_value (-1.0, 1.0);
2054   check_isinfp_ext ("pow (x, -inf) == +inf for |x| < 1",
2055                     FUNC(pow) (x, minus_infty), x);
2056
2057   x = random_greater (0.0);
2058   check_isinfp_ext ("pow (+inf, y) == +inf for y > 0",
2059                     FUNC(pow) (plus_infty, x), x);
2060
2061   x = random_less (0.0);
2062   check_ext ("pow (+inf, y) == +0 for y < 0",
2063              FUNC(pow) (plus_infty, x), 0.0, x);
2064
2065   x = (rand () % 1000000) * 2.0 + 1;    /* Get random odd integer > 0 */
2066   check_isinfn_ext ("pow (-inf, y) == -inf for y an odd integer > 0",
2067                     FUNC(pow) (minus_infty, x), x);
2068
2069   x = ((rand () % 1000000) + 1) * 2.0;  /* Get random even integer > 1 */
2070   check_isinfp_ext ("pow (-inf, y) == +inf for y > 0 and not an odd integer",
2071                     FUNC(pow) (minus_infty, x), x);
2072
2073   x = -((rand () % 1000000) * 2.0 + 1); /* Get random odd integer < 0 */
2074   check_ext ("pow (-inf, y) == -0 for y an odd integer < 0",
2075              FUNC(pow) (minus_infty, x), minus_zero, x);
2076
2077   x = ((rand () % 1000000) + 1) * -2.0; /* Get random even integer < 0 */
2078   check_ext ("pow (-inf, y) == +0 for y < 0 and not an odd integer",
2079              FUNC(pow) (minus_infty, x), 0.0, x);
2080 #endif
2081
2082   x = (rand () % 1000000) * 2.0 + 1;    /* Get random odd integer > 0 */
2083   check_ext ("pow (+0, y) == +0 for y an odd integer > 0",
2084              FUNC(pow) (0.0, x), 0.0, x);
2085 #ifndef TEST_INLINE
2086   x = (rand () % 1000000) * 2.0 + 1;    /* Get random odd integer > 0 */
2087   check_ext ("pow (-0, y) == -0 for y an odd integer > 0",
2088              FUNC(pow) (minus_zero, x), minus_zero, x);
2089 #endif
2090
2091   x = ((rand () % 1000000) + 1) * 2.0;  /* Get random even integer > 1 */
2092   check_ext ("pow (+0, y) == +0 for y > 0 and not an odd integer",
2093              FUNC(pow) (0.0, x), 0.0, x);
2094
2095   x = ((rand () % 1000000) + 1) * 2.0;  /* Get random even integer > 1 */
2096   check_ext ("pow (-0, y) == +0 for y > 0 and not an odd integer",
2097              FUNC(pow) (minus_zero, x), 0.0, x);
2098 }
2099
2100
2101 static void
2102 fdim_test (void)
2103 {
2104   check ("fdim (+0, +0) = +0", FUNC(fdim) (0, 0), 0);
2105   check ("fdim (9, 0) = 9", FUNC(fdim) (9, 0), 9);
2106   check ("fdim (0, 9) = 0", FUNC(fdim) (0, 9), 0);
2107   check ("fdim (-9, 0) = 9", FUNC(fdim) (-9, 0), 0);
2108   check ("fdim (0, -9) = 9", FUNC(fdim) (0, -9), 9);
2109
2110   check_isinfp ("fdim (+inf, 9) = +inf", FUNC(fdim) (plus_infty, 9));
2111   check_isinfp ("fdim (+inf, -9) = +inf", FUNC(fdim) (plus_infty, -9));
2112   check ("fdim (-inf, 9) = 0", FUNC(fdim) (minus_infty, 9), 0);
2113   check ("fdim (-inf, -9) = 0", FUNC(fdim) (minus_infty, -9), 0);
2114   check_isinfp ("fdim (+9, -inf) = +inf", FUNC(fdim) (9, minus_infty));
2115   check_isinfp ("fdim (-9, -inf) = +inf", FUNC(fdim) (-9, minus_infty));
2116   check ("fdim (9, inf) = 0", FUNC(fdim) (9, plus_infty), 0);
2117   check ("fdim (-9, inf) = 0", FUNC(fdim) (-9, plus_infty), 0);
2118
2119   check_isnan ("fdim (0, NaN) = NaN", FUNC(fdim) (0, nan_value));
2120   check_isnan ("fdim (9, NaN) = NaN", FUNC(fdim) (9, nan_value));
2121   check_isnan ("fdim (-9, NaN) = NaN", FUNC(fdim) (-9, nan_value));
2122   check_isnan ("fdim (NaN, 9) = NaN", FUNC(fdim) (nan_value, 9));
2123   check_isnan ("fdim (NaN, -9) = NaN", FUNC(fdim) (nan_value, -9));
2124   check_isnan ("fdim (+inf, NaN) = NaN", FUNC(fdim) (plus_infty, nan_value));
2125   check_isnan ("fdim (-inf, NaN) = NaN", FUNC(fdim) (minus_infty, nan_value));
2126   check_isnan ("fdim (NaN, +inf) = NaN", FUNC(fdim) (nan_value, plus_infty));
2127   check_isnan ("fdim (NaN, -inf) = NaN", FUNC(fdim) (nan_value, minus_infty));
2128   check_isnan ("fdim (NaN, NaN) = NaN", FUNC(fdim) (nan_value, nan_value));
2129 }
2130
2131
2132 static void
2133 fmin_test (void)
2134 {
2135   check ("fmin (+0, +0) = +0", FUNC(fmin) (0, 0), 0);
2136   check ("fmin (9, 0) = 0", FUNC(fmin) (9, 0), 0);
2137   check ("fmin (0, 9) = 0", FUNC(fmin) (0, 9), 0);
2138   check ("fmin (-9, 0) = -9", FUNC(fmin) (-9, 0), -9);
2139   check ("fmin (0, -9) = -9", FUNC(fmin) (0, -9), -9);
2140
2141   check ("fmin (+inf, 9) = 9", FUNC(fmin) (plus_infty, 9), 9);
2142   check ("fmin (9, +inf) = 9", FUNC(fmin) (9, plus_infty), 9);
2143   check ("fmin (+inf, -9) = -9", FUNC(fmin) (plus_infty, -9), -9);
2144   check ("fmin (-9, +inf) = -9", FUNC(fmin) (-9, plus_infty), -9);
2145   check_isinfn ("fmin (-inf, 9) = -inf", FUNC(fmin) (minus_infty, 9));
2146   check_isinfn ("fmin (-inf, -9) = -inf", FUNC(fmin) (minus_infty, -9));
2147   check_isinfn ("fmin (+9, -inf) = -inf", FUNC(fmin) (9, minus_infty));
2148   check_isinfn ("fmin (-9, -inf) = -inf", FUNC(fmin) (-9, minus_infty));
2149
2150   check ("fmin (0, NaN) = 0", FUNC(fmin) (0, nan_value), 0);
2151   check ("fmin (9, NaN) = 9", FUNC(fmin) (9, nan_value), 9);
2152   check ("fmin (-9, NaN) = 9", FUNC(fmin) (-9, nan_value), -9);
2153   check ("fmin (NaN, 0) = 0", FUNC(fmin) (nan_value, 0), 0);
2154   check ("fmin (NaN, 9) = NaN", FUNC(fmin) (nan_value, 9), 9);
2155   check ("fmin (NaN, -9) = NaN", FUNC(fmin) (nan_value, -9), -9);
2156   check_isinfp ("fmin (+inf, NaN) = +inf", FUNC(fmin) (plus_infty, nan_value));
2157   check_isinfn ("fmin (-inf, NaN) = -inf", FUNC(fmin) (minus_infty, nan_value));
2158   check_isinfp ("fmin (NaN, +inf) = +inf", FUNC(fmin) (nan_value, plus_infty));
2159   check_isinfn ("fmin (NaN, -inf) = -inf", FUNC(fmin) (nan_value, minus_infty));
2160   check_isnan ("fmin (NaN, NaN) = NaN", FUNC(fmin) (nan_value, nan_value));
2161 }
2162
2163
2164 static void
2165 fmax_test (void)
2166 {
2167   check ("fmax (+0, +0) = +0", FUNC(fmax) (0, 0), 0);
2168   check ("fmax (9, 0) = 9", FUNC(fmax) (9, 0), 9);
2169   check ("fmax (0, 9) = 9", FUNC(fmax) (0, 9), 9);
2170   check ("fmax (-9, 0) = 0", FUNC(fmax) (-9, 0), 0);
2171   check ("fmax (0, -9) = 0", FUNC(fmax) (0, -9), 0);
2172
2173   check_isinfp ("fmax (+inf, 9) = +inf", FUNC(fmax) (plus_infty, 9));
2174   check_isinfp ("fmax (9, +inf) = +inf", FUNC(fmax) (0, plus_infty));
2175   check_isinfp ("fmax (-9, +inf) = +inf", FUNC(fmax) (-9, plus_infty));
2176   check_isinfp ("fmax (+inf, -9) = +inf", FUNC(fmax) (plus_infty, -9));
2177   check ("fmax (-inf, 9) = 9", FUNC(fmax) (minus_infty, 9), 9);
2178   check ("fmax (-inf, -9) = -9", FUNC(fmax) (minus_infty, -9), -9);
2179   check ("fmax (+9, -inf) = 9", FUNC(fmax) (9, minus_infty), 9);
2180   check ("fmax (-9, -inf) = -9", FUNC(fmax) (-9, minus_infty), -9);
2181
2182   check ("fmax (0, NaN) = 0", FUNC(fmax) (0, nan_value), 0);
2183   check ("fmax (9, NaN) = 9", FUNC(fmax) (9, nan_value), 9);
2184   check ("fmax (-9, NaN) = 9", FUNC(fmax) (-9, nan_value), -9);
2185   check ("fmax (NaN, 0) = 0", FUNC(fmax) (nan_value, 0), 0);
2186   check ("fmax (NaN, 9) = NaN", FUNC(fmax) (nan_value, 9), 9);
2187   check ("fmax (NaN, -9) = NaN", FUNC(fmax) (nan_value, -9), -9);
2188   check_isinfp ("fmax (+inf, NaN) = +inf", FUNC(fmax) (plus_infty, nan_value));
2189   check_isinfn ("fmax (-inf, NaN) = -inf", FUNC(fmax) (minus_infty, nan_value));
2190   check_isinfp ("fmax (NaN, +inf) = +inf", FUNC(fmax) (nan_value, plus_infty));
2191   check_isinfn ("fmax (NaN, -inf) = -inf", FUNC(fmax) (nan_value, minus_infty));
2192   check_isnan ("fmax (NaN, NaN) = NaN", FUNC(fmax) (nan_value, nan_value));
2193 }
2194
2195
2196 static void
2197 fmod_test (void)
2198 {
2199   MATHTYPE x;
2200
2201   x = random_greater (0);
2202   check_ext ("fmod (+0, y) == +0 for y != 0", FUNC(fmod) (0, x), 0, x);
2203
2204   x = random_greater (0);
2205   check_ext ("fmod (-0, y) == -0 for y != 0", FUNC(fmod) (minus_zero, x),
2206              minus_zero, x);
2207
2208   check_isnan_exc_ext ("fmod (+inf, y) == NaN plus invalid exception",
2209                        FUNC(fmod) (plus_infty, x), INVALID_EXCEPTION, x);
2210   check_isnan_exc_ext ("fmod (-inf, y) == NaN plus invalid exception",
2211                        FUNC(fmod) (minus_infty, x), INVALID_EXCEPTION, x);
2212   check_isnan_exc_ext ("fmod (x, +0) == NaN plus invalid exception",
2213                        FUNC(fmod) (x, 0), INVALID_EXCEPTION, x);
2214   check_isnan_exc_ext ("fmod (x, -0) == NaN plus invalid exception",
2215                        FUNC(fmod) (x, minus_zero), INVALID_EXCEPTION, x);
2216
2217   x = random_greater (0);
2218   check_ext ("fmod (x, +inf) == x for x not infinite",
2219              FUNC(fmod) (x, plus_infty), x, x);
2220   x = random_greater (0);
2221   check_ext ("fmod (x, -inf) == x for x not infinite",
2222              FUNC(fmod) (x, minus_infty), x, x);
2223
2224   check_eps ("fmod (6.5, 2.3) == 1.9", FUNC(fmod) (6.5, 2.3), 1.9,
2225              CHOOSE(5e-16, 1e-15, 2e-7));
2226   check_eps ("fmod (-6.5, 2.3) == -1.9", FUNC(fmod) (-6.5, 2.3), -1.9,
2227              CHOOSE(5e-16, 1e-15, 2e-7));
2228   check_eps ("fmod (6.5, -2.3) == 1.9", FUNC(fmod) (6.5, -2.3), 1.9,
2229              CHOOSE(5e-16, 1e-15, 2e-7));
2230   check_eps ("fmod (-6.5, -2.3) == -1.9", FUNC(fmod) (-6.5, -2.3), -1.9,
2231              CHOOSE(5e-16, 1e-15, 2e-7));
2232
2233
2234 }
2235
2236
2237 static void
2238 nextafter_test (void)
2239 {
2240   MATHTYPE x;
2241
2242   check ("nextafter (+0, +0) = +0", FUNC(nextafter) (0, 0), 0);
2243   check ("nextafter (-0, +0) = +0", FUNC(nextafter) (minus_zero, 0), 0);
2244   check ("nextafter (+0, -0) = -0", FUNC(nextafter) (0, minus_zero),
2245          minus_zero);
2246   check ("nextafter (-0, -0) = -0", FUNC(nextafter) (minus_zero, minus_zero),
2247          minus_zero);
2248
2249   check ("nextafter (9, 9) = 9",  FUNC(nextafter) (9, 9), 9);
2250   check ("nextafter (-9, -9) = -9",  FUNC(nextafter) (-9, -9), -9);
2251   check_isinfp ("nextafter (+inf, +inf) = +inf",
2252                 FUNC(nextafter) (plus_infty, plus_infty));
2253   check_isinfn ("nextafter (-inf, -inf) = -inf",
2254                 FUNC(nextafter) (minus_infty, minus_infty));
2255
2256   x = rand () * 1.1;
2257   check_isnan ("nextafter (NaN, x) = NaN", FUNC(nextafter) (nan_value, x));
2258   check_isnan ("nextafter (x, NaN) = NaN", FUNC(nextafter) (x, nan_value));
2259   check_isnan ("nextafter (NaN, NaN) = NaN", FUNC(nextafter) (nan_value,
2260                                                               nan_value));
2261
2262   /* XXX We need the hexadecimal FP number representation here for further
2263      tests.  */
2264 }
2265
2266
2267 static void
2268 copysign_test (void)
2269 {
2270   check ("copysign (0, 4) = 0", FUNC(copysign) (0, 4), 0);
2271   check ("copysign (0, -4) = -0", FUNC(copysign) (0, -4), minus_zero);
2272   check ("copysign (-0, 4) = 0", FUNC(copysign) (minus_zero, 4), 0);
2273   check ("copysign (-0, -4) = -0", FUNC(copysign) (minus_zero, -4),
2274          minus_zero);
2275
2276   check_isinfp ("copysign (+inf, 0) = +inf", FUNC(copysign) (plus_infty, 0));
2277   check_isinfn ("copysign (+inf, -0) = -inf", FUNC(copysign) (plus_infty,
2278                                                               minus_zero));
2279   check_isinfp ("copysign (-inf, 0) = +inf", FUNC(copysign) (minus_infty, 0));
2280   check_isinfn ("copysign (-inf, -0) = -inf", FUNC(copysign) (minus_infty,
2281                                                               minus_zero));
2282
2283   check ("copysign (0, +inf) = 0", FUNC(copysign) (0, plus_infty), 0);
2284   check ("copysign (0, -inf) = -0", FUNC(copysign) (0, minus_zero),
2285          minus_zero);
2286   check ("copysign (-0, +inf) = 0", FUNC(copysign) (minus_zero, plus_infty),
2287          0);
2288   check ("copysign (-0, -inf) = -0", FUNC(copysign) (minus_zero, minus_zero),
2289          minus_zero);
2290
2291   /* XXX More correctly we would have to check the sign of the NaN.  */
2292   check_isnan ("copysign (+NaN, 0) = +NaN", FUNC(copysign) (nan_value, 0));
2293   check_isnan ("copysign (+NaN, -0) = -NaN", FUNC(copysign) (nan_value,
2294                                                              minus_zero));
2295   check_isnan ("copysign (-NaN, 0) = +NaN", FUNC(copysign) (-nan_value, 0));
2296   check_isnan ("copysign (-NaN, -0) = -NaN", FUNC(copysign) (-nan_value,
2297                                                              minus_zero));
2298 }
2299
2300
2301 static void
2302 trunc_test (void)
2303 {
2304   check ("trunc(0) = 0", FUNC(trunc) (0), 0);
2305   check ("trunc(-0) = -0", FUNC(trunc) (minus_zero), minus_zero);
2306   check ("trunc(0.625) = 0", FUNC(trunc) (0.625), 0);
2307   check ("trunc(-0.625) = -0", FUNC(trunc) (-0.625), minus_zero);
2308   check ("trunc(1) = 1", FUNC(trunc) (1), 1);
2309   check ("trunc(-1) = -1", FUNC(trunc) (-1), -1);
2310   check ("trunc(1.625) = 1", FUNC(trunc) (1.625), 1);
2311   check ("trunc(-1.625) = -1", FUNC(trunc) (-1.625), -1);
2312
2313   check ("trunc(1048580.625) = 1048580", FUNC(trunc) (1048580.625L),
2314          1048580L);
2315   check ("trunc(-1048580.625) = -1048580", FUNC(trunc) (-1048580.625L),
2316          -1048580L);
2317
2318   check ("trunc(8388610.125) = 8388610", FUNC(trunc) (8388610.125L),
2319          8388610.0L);
2320   check ("trunc(-8388610.125) = -8388610", FUNC(trunc) (-8388610.125L),
2321          -8388610.0L);
2322
2323   check ("trunc(4294967296.625) = 4294967296", FUNC(trunc) (4294967296.625L),
2324          4294967296.0L);
2325   check ("trunc(-4294967296.625) = -4294967296",
2326          FUNC(trunc) (-4294967296.625L), -4294967296.0L);
2327
2328   check_isinfp ("trunc(+inf) = +inf", FUNC(trunc) (plus_infty));
2329   check_isinfn ("trunc(-inf) = -inf", FUNC(trunc) (minus_infty));
2330   check_isnan ("trunc(NaN) = NaN", FUNC(trunc) (nan_value));
2331 }
2332
2333
2334 static void
2335 sqrt_test (void)
2336 {
2337   MATHTYPE x;
2338
2339
2340   /* XXX Tests fuer negative x are missing */
2341   check ("sqrt (0) == 0", FUNC(sqrt) (0), 0);
2342   check_isnan ("sqrt (NaN) == NaN", FUNC(sqrt) (nan_value));
2343   check_isinfp ("sqrt (+inf) == +inf", FUNC(sqrt) (plus_infty));
2344
2345   check ("sqrt (-0) == -0", FUNC(sqrt) (0), 0);
2346
2347   x = random_less (0.0);
2348   check_isnan_exc_ext ("sqrt (x) == NaN plus invalid exception for x < 0",
2349                        FUNC(sqrt) (x), INVALID_EXCEPTION, x);
2350
2351   x = random_value (0, 10000);
2352   check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x);
2353   check ("sqrt (4) == 2", FUNC(sqrt) (4), 2);
2354   check ("sqrt (0.25) == 0.5", FUNC(sqrt) (0.25), 0.5);
2355   check ("sqrt (6642.25) == 81.5", FUNC(sqrt) (6642.25), 81.5);
2356   check_eps ("sqrt (15239.903) == 123.45", FUNC(sqrt) (15239.903), 123.45,
2357              CHOOSE (3e-6L, 3e-6, 8e-6));
2358
2359 }
2360
2361 static void
2362 remainder_test (void)
2363 {
2364   MATHTYPE result;
2365
2366   result = FUNC(remainder) (1, 0);
2367   check_isnan_exc ("remainder(1, +0) == NaN plus invalid exception",
2368                    result, INVALID_EXCEPTION);
2369
2370   result = FUNC(remainder) (1, minus_zero);
2371   check_isnan_exc ("remainder(1, -0) == NaN plus invalid exception",
2372                    result, INVALID_EXCEPTION);
2373
2374   result = FUNC(remainder) (plus_infty, 1);
2375   check_isnan_exc ("remainder(+inf, 1) == NaN plus invalid exception",
2376                    result, INVALID_EXCEPTION);
2377
2378   result = FUNC(remainder) (minus_infty, 1);
2379   check_isnan_exc ("remainder(-inf, 1) == NaN plus invalid exception",
2380                    result, INVALID_EXCEPTION);
2381
2382   result = FUNC(remainder) (1.625, 1.0);
2383   check ("remainder(1.625, 1.0) == -0.375", result, -0.375);
2384
2385   result = FUNC(remainder) (-1.625, 1.0);
2386   check ("remainder(-1.625, 1.0) == 0.375", result, 0.375);
2387
2388   result = FUNC(remainder) (1.625, -1.0);
2389   check ("remainder(1.625, -1.0) == -0.375", result, -0.375);
2390
2391   result = FUNC(remainder) (-1.625, -1.0);
2392   check ("remainder(-1.625, -1.0) == 0.375", result, 0.375);
2393
2394   result = FUNC(remainder) (5.0, 2.0);
2395   check ("remainder(5.0, 2.0) == 1.0", result, 1.0);
2396
2397   result = FUNC(remainder) (3.0, 2.0);
2398   check ("remainder(3.0, 2.0) == -1.0", result, -1.0);
2399 }
2400
2401
2402 static void
2403 remquo_test (void)
2404 {
2405   int quo;
2406   MATHTYPE result;
2407
2408   result = FUNC(remquo) (1, 0, &quo);
2409   check_isnan_exc ("remquo(1, +0, &x) == NaN plus invalid exception",
2410                    result, INVALID_EXCEPTION);
2411
2412   result = FUNC(remquo) (1, minus_zero, &quo);
2413   check_isnan_exc ("remquo(1, -0, &x) == NaN plus invalid exception",
2414                    result, INVALID_EXCEPTION);
2415
2416   result = FUNC(remquo) (plus_infty, 1, &quo);
2417   check_isnan_exc ("remquo(+inf, 1, &x) == NaN plus invalid exception",
2418                    result, INVALID_EXCEPTION);
2419
2420   result = FUNC(remquo) (minus_infty, 1, &quo);
2421   check_isnan_exc ("remquo(-inf, 1, &x) == NaN plus invalid exception",
2422                    result, INVALID_EXCEPTION);
2423
2424   result = FUNC(remquo) (1.625, 1.0, &quo);
2425   check ("remquo(1.625, 1.0, &x) == -0.375", result, -0.375);
2426   check_long ("remquo(1.625, 1.0, &x) puts 2 in x", quo, 2);
2427
2428   result = FUNC(remquo) (-1.625, 1.0, &quo);
2429   check ("remquo(-1.625, 1.0, &x) == 0.375", result, 0.375);
2430   check_long ("remquo(-1.625, 1.0, &x) puts -2 in x", quo, -2);
2431
2432   result = FUNC(remquo) (1.625, -1.0, &quo);
2433   check ("remquo(1.625, -1.0, &x) == -0.375", result, -0.375);
2434   check_long ("remquo(1.625, -1.0, &x) puts -2 in x", quo, -2);
2435
2436   result = FUNC(remquo) (-1.625, -1.0, &quo);
2437   check ("remquo(-1.625, -1.0, &x) == 0.375", result, 0.375);
2438   check_long ("remquo(-1.625, -1.0, &x) puts 2 in x", quo, 2);
2439
2440   result = FUNC(remquo) (5.0, 2.0, &quo);
2441   check ("remquo(5.0, 2.0, &x) == 1.0", result, 1.0);
2442   check_long ("remquo (5.0, 2.0, &x) puts 2 in x", quo, 2);
2443
2444   result = FUNC(remquo) (3.0, 2.0, &quo);
2445   check ("remquo(3.0, 2.0, &x) == -1.0", result, -1.0);
2446   check_long ("remquo (3.0, 2.0, &x) puts 2 in x", quo, 2);
2447 }
2448
2449
2450 static void
2451 cexp_test (void)
2452 {
2453   __complex__ MATHTYPE result;
2454
2455   result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, plus_zero));
2456   check ("real(cexp(0 + 0i)) = 1", __real__ result, 1);
2457   check ("imag(cexp(0 + 0i)) = 0", __imag__ result, 0);
2458   result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_zero));
2459   check ("real(cexp(-0 + 0i)) = 1", __real__ result, 1);
2460   check ("imag(cexp(-0 + 0i)) = 0", __imag__ result, 0);
2461   result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, minus_zero));
2462   check ("real(cexp(0 - 0i)) = 1", __real__ result, 1);
2463   check ("imag(cexp(0 - 0i)) = -0", __imag__ result, minus_zero);
2464   result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_zero));
2465   check ("real(cexp(-0 - 0i)) = 1", __real__ result, 1);
2466   check ("imag(cexp(-0 - 0i)) = -0", __imag__ result, minus_zero);
2467
2468   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_zero));
2469   check_isinfp ("real(cexp(+inf + 0i)) = +inf", __real__ result);
2470   check ("imag(cexp(+inf + 0i)) = 0", __imag__ result, 0);
2471   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_zero));
2472   check_isinfp ("real(cexp(+inf - 0i)) = +inf", __real__ result);
2473   check ("imag(cexp(+inf - 0i)) = -0", __imag__ result, minus_zero);
2474
2475   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_zero));
2476   check ("real(cexp(-inf + 0i)) = 0", __real__ result, 0);
2477   check ("imag(cexp(-inf + 0i)) = 0", __imag__ result, 0);
2478   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_zero));
2479   check ("real(cexp(-inf - 0i)) = 0", __real__ result, 0);
2480   check ("imag(cexp(-inf - 0i)) = -0", __imag__ result, minus_zero);
2481
2482
2483   result = FUNC(cexp) (BUILD_COMPLEX (0.0, plus_infty));
2484   check_isnan_exc ("real(cexp(0 + i inf)) = NaN plus invalid exception",
2485                    __real__ result, INVALID_EXCEPTION);
2486   check_isnan ("imag(cexp(0 + i inf)) = NaN plus invalid exception",
2487                __imag__ result);
2488
2489 #if defined __GNUC__ && __GNUC__ <= 2 && __GNUC_MINOR__ <= 7
2490   if (verbose)
2491     printf ("The following test for cexp might fail due to a gcc compiler error!\n");
2492 #endif
2493
2494   result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_infty));
2495   check_isnan_exc ("real(cexp(-0 + i inf)) = NaN plus invalid exception",
2496                    __real__ result, INVALID_EXCEPTION);
2497   check_isnan ("imag(cexp(-0 + i inf)) = NaN plus invalid exception",
2498                __imag__ result);
2499   result = FUNC(cexp) (BUILD_COMPLEX (0.0, minus_infty));
2500   check_isnan_exc ("real(cexp(0 - i inf)) = NaN plus invalid exception",
2501                    __real__ result, INVALID_EXCEPTION);
2502   check_isnan ("imag(cexp(0 - i inf)) = NaN plus invalid exception",
2503                __imag__ result);
2504   result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_infty));
2505   check_isnan_exc ("real(cexp(-0 - i inf)) = NaN plus invalid exception",
2506                    __real__ result, INVALID_EXCEPTION);
2507   check_isnan ("imag(cexp(-0 - i inf)) = NaN plus invalid exception",
2508                __imag__ result);
2509
2510   result = FUNC(cexp) (BUILD_COMPLEX (100.0, plus_infty));
2511   check_isnan_exc ("real(cexp(100.0 + i inf)) = NaN plus invalid exception",
2512                    __real__ result, INVALID_EXCEPTION);
2513   check_isnan ("imag(cexp(100.0 + i inf)) = NaN plus invalid exception",
2514                __imag__ result);
2515   result = FUNC(cexp) (BUILD_COMPLEX (-100.0, plus_infty));
2516   check_isnan_exc ("real(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2517                    __real__ result, INVALID_EXCEPTION);
2518   check_isnan ("imag(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2519                __imag__ result);
2520   result = FUNC(cexp) (BUILD_COMPLEX (100.0, minus_infty));
2521   check_isnan_exc ("real(cexp(100.0 - i inf)) = NaN plus invalid exception",
2522                    __real__ result, INVALID_EXCEPTION);
2523   check_isnan ("imag(cexp(100.0 - i inf)) = NaN plus invalid exception",
2524                __imag__ result);
2525   result = FUNC(cexp) (BUILD_COMPLEX (-100.0, minus_infty));
2526   check_isnan_exc ("real(cexp(-100.0 - i inf)) = NaN plus invalid exception",
2527                    __real__ result, INVALID_EXCEPTION);
2528   check_isnan ("imag(cexp(-100.0 - i inf)) = NaN", __imag__ result);
2529
2530   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 2.0));
2531   check ("real(cexp(-inf + 2.0i)) = -0", __real__ result, minus_zero);
2532   check ("imag(cexp(-inf + 2.0i)) = 0", __imag__ result, 0);
2533   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 4.0));
2534   check ("real(cexp(-inf + 4.0i)) = -0", __real__ result, minus_zero);
2535   check ("imag(cexp(-inf + 4.0i)) = -0", __imag__ result, minus_zero);
2536
2537   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 2.0));
2538   check_isinfn ("real(cexp(+inf + 2.0i)) = -inf", __real__ result);
2539   check_isinfp ("imag(cexp(+inf + 2.0i)) = +inf", __imag__ result);
2540   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 4.0));
2541   check_isinfn ("real(cexp(+inf + 4.0i)) = -inf", __real__ result);
2542   check_isinfn ("imag(cexp(+inf + 4.0i)) = -inf", __imag__ result);
2543
2544   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_infty));
2545   check_isinfp_exc ("real(cexp(+inf + i inf)) = +inf plus invalid exception",
2546                     __real__ result, INVALID_EXCEPTION);
2547   check_isnan ("imag(cexp(+inf + i inf)) = NaN plus invalid exception",
2548                __imag__ result);
2549   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_infty));
2550   check_isinfp_exc ("real(cexp(+inf - i inf)) = +inf plus invalid exception",
2551                     __real__ result, INVALID_EXCEPTION);
2552   check_isnan ("imag(cexp(+inf - i inf)) = NaN plus invalid exception",
2553                __imag__ result);
2554
2555   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_infty));
2556   check ("real(cexp(-inf + i inf)) = 0", __real__ result, 0);
2557   check ("imag(cexp(-inf + i inf)) = 0", __imag__ result, 0);
2558   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_infty));
2559   check ("real(cexp(-inf - i inf)) = 0", __real__ result, 0);
2560   check ("imag(cexp(-inf - i inf)) = -0", __imag__ result, minus_zero);
2561
2562   result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, nan_value));
2563   check ("real(cexp(-inf + i NaN)) = 0", __real__ result, 0);
2564   check ("imag(cexp(-inf + i NaN)) = 0", fabs (__imag__ result), 0);
2565
2566   result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, nan_value));
2567   check_isinfp ("real(cexp(+inf + i NaN)) = +inf", __real__ result);
2568   check_isnan ("imag(cexp(+inf + i NaN)) = NaN", __imag__ result);
2569
2570   result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 0.0));
2571   check_isnan_maybe_exc ("real(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2572                          __real__ result, INVALID_EXCEPTION);
2573   check_isnan ("imag(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2574                __imag__ result);
2575   result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
2576   check_isnan_maybe_exc ("real(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2577                          __real__ result, INVALID_EXCEPTION);
2578   check_isnan ("imag(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2579                __imag__ result);
2580   result = FUNC(cexp) (BUILD_COMPLEX (nan_value, plus_infty));
2581   check_isnan_maybe_exc ("real(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2582                          __real__ result, INVALID_EXCEPTION);
2583   check_isnan ("imag(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2584                __imag__ result);
2585
2586   result = FUNC(cexp) (BUILD_COMPLEX (0, nan_value));
2587   check_isnan_maybe_exc ("real(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2588                          __real__ result, INVALID_EXCEPTION);
2589   check_isnan ("imag(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2590                __imag__ result);
2591   result = FUNC(cexp) (BUILD_COMPLEX (1, nan_value));
2592   check_isnan_maybe_exc ("real(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2593                          __real__ result, INVALID_EXCEPTION);
2594   check_isnan ("imag(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2595                __imag__ result);
2596
2597   result = FUNC(cexp) (BUILD_COMPLEX (nan_value, nan_value));
2598   check_isnan ("real(cexp(NaN + i NaN)) = NaN", __real__ result);
2599   check_isnan ("imag(cexp(NaN + i NaN)) = NaN", __imag__ result);
2600 }
2601
2602
2603 static void
2604 csin_test (void)
2605 {
2606   __complex__ MATHTYPE result;
2607
2608   result = FUNC(csin) (BUILD_COMPLEX (0.0, 0.0));
2609   check ("real(csin(0 + 0i)) = 0", __real__ result, 0);
2610   check ("imag(csin(0 + 0i)) = 0", __imag__ result, 0);
2611   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, 0.0));
2612   check ("real(csin(-0 + 0i)) = -0", __real__ result, minus_zero);
2613   check ("imag(csin(-0 + 0i)) = 0", __imag__ result, 0);
2614   result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_zero));
2615   check ("real(csin(0 - 0i)) = 0", __real__ result, 0);
2616   check ("imag(csin(0 - 0i)) = -0", __imag__ result, minus_zero);
2617   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_zero));
2618   check ("real(csin(-0 - 0i)) = -0", __real__ result, minus_zero);
2619   check ("imag(csin(-0 - 0i)) = -0", __imag__ result, minus_zero);
2620
2621   result = FUNC(csin) (BUILD_COMPLEX (0.0, plus_infty));
2622   check ("real(csin(0 + i Inf)) = 0", __real__ result, 0);
2623   check_isinfp ("imag(csin(0 + i Inf)) = +Inf", __imag__ result);
2624   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, plus_infty));
2625   check ("real(csin(-0 + i Inf)) = -0", __real__ result, minus_zero);
2626   check_isinfp ("imag(csin(-0 + i Inf)) = +Inf", __imag__ result);
2627   result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_infty));
2628   check ("real(csin(0 - i Inf)) = 0", __real__ result, 0);
2629   check_isinfn ("imag(csin(0 - i Inf)) = -Inf", __imag__ result);
2630   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_infty));
2631   check ("real(csin(-0 - i Inf)) = -0", __real__ result, minus_zero);
2632   check_isinfn("imag(csin(-0 - i Inf)) = -Inf", __imag__ result);
2633
2634   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 0.0));
2635   check_isnan_exc ("real(csin(+Inf + 0i)) = NaN plus invalid exception",
2636                    __real__ result, INVALID_EXCEPTION);
2637   check ("imag(csin(+Inf + 0i)) = +-0 plus invalid exception",
2638          FUNC(fabs) (__imag__ result), 0);
2639   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 0.0));
2640   check_isnan_exc ("real(csin(-Inf + 0i)) = NaN plus invalid exception",
2641                    __real__ result, INVALID_EXCEPTION);
2642   check ("imag(csin(-Inf + 0i)) = +-0 plus invalid exception",
2643          FUNC(fabs) (__imag__ result), 0);
2644   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_zero));
2645   check_isnan_exc ("real(csin(+Inf - 0i)) = NaN plus invalid exception",
2646                    __real__ result, INVALID_EXCEPTION);
2647   check ("imag(csin(+Inf - 0i)) = +-0 plus invalid exception",
2648          FUNC(fabs) (__imag__ result), 0.0);
2649   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_zero));
2650   check_isnan_exc ("real(csin(-Inf - 0i)) = NaN plus invalid exception",
2651                    __real__ result, INVALID_EXCEPTION);
2652   check ("imag(csin(-Inf - 0i)) = +-0 plus invalid exception",
2653          FUNC(fabs) (__imag__ result), 0.0);
2654
2655   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, plus_infty));
2656   check_isnan_exc ("real(csin(+Inf + i Inf)) = NaN plus invalid exception",
2657                    __real__ result, INVALID_EXCEPTION);
2658   check_isinfp ("imag(csin(+Inf + i Inf)) = +-Inf plus invalid exception",
2659                 FUNC(fabs) (__imag__ result));
2660   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, plus_infty));
2661   check_isnan_exc ("real(csin(-Inf + i Inf)) = NaN plus invalid exception",
2662                    __real__ result, INVALID_EXCEPTION);
2663   check_isinfp ("imag(csin(-Inf + i Inf)) = +-Inf plus invalid exception",
2664                 FUNC(fabs) (__imag__ result));
2665   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_infty));
2666   check_isnan_exc ("real(csin(Inf - i Inf)) = NaN plus invalid exception",
2667                    __real__ result, INVALID_EXCEPTION);
2668   check_isinfp ("imag(csin(Inf - i Inf)) = +-Inf plus invalid exception",
2669                 FUNC(fabs) (__imag__ result));
2670   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_infty));
2671   check_isnan_exc ("real(csin(-Inf - i Inf)) = NaN plus invalid exception",
2672                    __real__ result, INVALID_EXCEPTION);
2673   check_isinfp ("imag(csin(-Inf - i Inf)) = +-Inf plus invalid exception",
2674                 FUNC(fabs) (__imag__ result));
2675
2676   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 6.75));
2677   check_isnan_exc ("real(csin(+Inf + i 6.75)) = NaN plus invalid exception",
2678                    __real__ result, INVALID_EXCEPTION);
2679   check_isnan ("imag(csin(+Inf + i6.75)) = NaN plus invalid exception",
2680                __imag__ result);
2681   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, -6.75));
2682   check_isnan_exc ("real(csin(+Inf - i 6.75)) = NaN plus invalid exception",
2683                    __real__ result, INVALID_EXCEPTION);
2684   check_isnan ("imag(csin(+Inf - i6.75)) = NaN plus invalid exception",
2685                __imag__ result);
2686   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 6.75));
2687   check_isnan_exc ("real(csin(-Inf + i6.75)) = NaN plus invalid exception",
2688                    __real__ result, INVALID_EXCEPTION);
2689   check_isnan ("imag(csin(-Inf + i6.75)) = NaN plus invalid exception",
2690                __imag__ result);
2691   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, -6.75));
2692   check_isnan_exc ("real(csin(-Inf - i6.75)) = NaN plus invalid exception",
2693                    __real__ result, INVALID_EXCEPTION);
2694   check_isnan ("imag(csin(-Inf - i6.75)) = NaN plus invalid exception",
2695                __imag__ result);
2696
2697   result = FUNC(csin) (BUILD_COMPLEX (4.625, plus_infty));
2698   check_isinfn ("real(csin(4.625 + i Inf)) = -Inf", __real__ result);
2699   check_isinfn ("imag(csin(4.625 + i Inf)) = -Inf", __imag__ result);
2700   result = FUNC(csin) (BUILD_COMPLEX (4.625, minus_infty));
2701   check_isinfn ("real(csin(4.625 - i Inf)) = -Inf", __real__ result);
2702   check_isinfp ("imag(csin(4.625 - i Inf)) = +Inf", __imag__ result);
2703   result = FUNC(csin) (BUILD_COMPLEX (-4.625, plus_infty));
2704   check_isinfp ("real(csin(-4.625 + i Inf)) = +Inf", __real__ result);
2705   check_isinfn ("imag(csin(-4.625 + i Inf)) = -Inf", __imag__ result);
2706   result = FUNC(csin) (BUILD_COMPLEX (-4.625, minus_infty));
2707   check_isinfp ("real(csin(-4.625 - i Inf)) = +Inf", __real__ result);
2708   check_isinfp ("imag(csin(-4.625 - i Inf)) = +Inf", __imag__ result);
2709
2710   result = FUNC(csin) (BUILD_COMPLEX (nan_value, 0.0));
2711   check_isnan ("real(csin(NaN + i0)) = NaN", __real__ result);
2712   check ("imag(csin(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2713   result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_zero));
2714   check_isnan ("real(csin(NaN - i0)) = NaN", __real__ result);
2715   check ("imag(csin(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2716
2717   result = FUNC(csin) (BUILD_COMPLEX (nan_value, plus_infty));
2718   check_isnan ("real(csin(NaN + i Inf)) = NaN", __real__ result);
2719   check_isinfp ("imag(csin(NaN + i Inf)) = +-Inf",
2720                 FUNC(fabs) (__imag__ result));
2721   result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_infty));
2722   check_isnan ("real(csin(NaN - i Inf)) = NaN", __real__ result);
2723   check_isinfp ("real(csin(NaN - i Inf)) = +-Inf",
2724                 FUNC(fabs) (__imag__ result));
2725
2726   result = FUNC(csin) (BUILD_COMPLEX (nan_value, 9.0));
2727   check_isnan_maybe_exc ("real(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2728                          __real__ result, INVALID_EXCEPTION);
2729   check_isnan ("imag(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2730                __imag__ result);
2731   result = FUNC(csin) (BUILD_COMPLEX (nan_value, -9.0));
2732   check_isnan_maybe_exc ("real(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2733                          __real__ result, INVALID_EXCEPTION);
2734   check_isnan ("imag(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2735                __imag__ result);
2736
2737   result = FUNC(csin) (BUILD_COMPLEX (0.0, nan_value));
2738   check ("real(csin(0 + i NaN))", __real__ result, 0.0);
2739   check_isnan ("imag(csin(0 + i NaN)) = NaN", __imag__ result);
2740   result = FUNC(csin) (BUILD_COMPLEX (minus_zero, nan_value));
2741   check ("real(csin(-0 + i NaN)) = -0", __real__ result, minus_zero);
2742   check_isnan ("imag(csin(-0 + NaN)) = NaN", __imag__ result);
2743
2744   result = FUNC(csin) (BUILD_COMPLEX (10.0, nan_value));
2745   check_isnan_maybe_exc ("real(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2746                          __real__ result, INVALID_EXCEPTION);
2747   check_isnan ("imag(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2748                __imag__ result);
2749   result = FUNC(csin) (BUILD_COMPLEX (nan_value, -10.0));
2750   check_isnan_maybe_exc ("real(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2751                          __real__ result, INVALID_EXCEPTION);
2752   check_isnan ("imag(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2753                __imag__ result);
2754
2755   result = FUNC(csin) (BUILD_COMPLEX (plus_infty, nan_value));
2756   check_isnan_maybe_exc ("real(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2757                          __real__ result, INVALID_EXCEPTION);
2758   check_isnan ("imag(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2759                __imag__ result);
2760   result = FUNC(csin) (BUILD_COMPLEX (minus_infty, nan_value));
2761   check_isnan_maybe_exc ("real(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2762                          __real__ result, INVALID_EXCEPTION);
2763   check_isnan ("imag(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2764                __imag__ result);
2765
2766   result = FUNC(csin) (BUILD_COMPLEX (nan_value, nan_value));
2767   check_isnan ("real(csin(NaN + i NaN)) = NaN", __real__ result);
2768   check_isnan ("imag(csin(NaN + i NaN)) = NaN", __imag__ result);
2769 }
2770
2771
2772 static void
2773 csinh_test (void)
2774 {
2775   __complex__ MATHTYPE result;
2776
2777   result = FUNC(csinh) (BUILD_COMPLEX (0.0, 0.0));
2778   check ("real(csinh(0 + 0i)) = 0", __real__ result, 0);
2779   check ("imag(csinh(0 + 0i)) = 0", __imag__ result, 0);
2780   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, 0.0));
2781   check ("real(csinh(-0 + 0i)) = -0", __real__ result, minus_zero);
2782   check ("imag(csinh(-0 + 0i)) = 0", __imag__ result, 0);
2783   result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_zero));
2784   check ("real(csinh(0 - 0i)) = 0", __real__ result, 0);
2785   check ("imag(csinh(0 - 0i)) = -0", __imag__ result, minus_zero);
2786   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_zero));
2787   check ("real(csinh(-0 - 0i)) = -0", __real__ result, minus_zero);
2788   check ("imag(csinh(-0 - 0i)) = -0", __imag__ result, minus_zero);
2789
2790   result = FUNC(csinh) (BUILD_COMPLEX (0.0, plus_infty));
2791   check_exc ("real(csinh(0 + i Inf)) = +-0 plus invalid exception",
2792              FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2793   check_isnan ("imag(csinh(0 + i Inf)) = NaN plus invalid exception",
2794                __imag__ result);
2795   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, plus_infty));
2796   check_exc ("real(csinh(-0 + i Inf)) = +-0 plus invalid exception",
2797              FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2798   check_isnan ("imag(csinh(-0 + i Inf)) = NaN plus invalid exception",
2799                __imag__ result);
2800   result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_infty));
2801   check_exc ("real(csinh(0 - i Inf)) = +-0 plus invalid exception",
2802              FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2803   check_isnan ("imag(csinh(0 - i Inf)) = NaN plus invalid exception",
2804                __imag__ result);
2805   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_infty));
2806   check_exc ("real(csinh(-0 - i Inf)) = +-0 plus invalid exception",
2807              FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2808   check_isnan ("imag(csinh(-0 - i Inf)) = NaN plus invalid exception",
2809                __imag__ result);
2810
2811   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 0.0));
2812   check_isinfp ("real(csinh(+Inf + 0i)) = +Inf", __real__ result);
2813   check ("imag(csinh(+Inf + 0i)) = 0", __imag__ result, 0);
2814   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 0.0));
2815   check_isinfn ("real(csinh(-Inf + 0i)) = -Inf", __real__ result);
2816   check ("imag(csinh(-Inf + 0i)) = 0", __imag__ result, 0);
2817   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_zero));
2818   check_isinfp ("real(csinh(+Inf - 0i)) = +Inf", __real__ result);
2819   check ("imag(csinh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
2820   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_zero));
2821   check_isinfn ("real(csinh(-Inf - 0i)) = -Inf", __real__ result);
2822   check ("imag(csinh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
2823
2824   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, plus_infty));
2825   check_isinfp_exc ("real(csinh(+Inf + i Inf)) = +-Inf plus invalid exception",
2826                     FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2827   check_isnan ("imag(csinh(+Inf + i Inf)) = NaN plus invalid exception",
2828                __imag__ result);
2829   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, plus_infty));
2830   check_isinfp_exc ("real(csinh(-Inf + i Inf)) = +-Inf plus invalid exception",
2831                     FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2832   check_isnan ("imag(csinh(-Inf + i Inf)) = NaN plus invalid exception",
2833                __imag__ result);
2834   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_infty));
2835   check_isinfp_exc ("real(csinh(Inf - i Inf)) = +-Inf plus invalid exception",
2836                     FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2837   check_isnan ("imag(csinh(Inf - i Inf)) = NaN plus invalid exception",
2838                __imag__ result);
2839   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_infty));
2840   check_isinfp_exc ("real(csinh(-Inf - i Inf)) = +-Inf plus invalid exception",
2841                     FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2842   check_isnan ("imag(csinh(-Inf - i Inf)) = NaN plus invalid exception",
2843                __imag__ result);
2844
2845   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 4.625));
2846   check_isinfn ("real(csinh(+Inf + i4.625)) = -Inf", __real__ result);
2847   check_isinfn ("imag(csinh(+Inf + i4.625)) = -Inf", __imag__ result);
2848   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 4.625));
2849   check_isinfp ("real(csinh(-Inf + i4.625)) = +Inf", __real__ result);
2850   check_isinfn ("imag(csinh(-Inf + i4.625)) = -Inf", __imag__ result);
2851   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, -4.625));
2852   check_isinfn ("real(csinh(+Inf - i4.625)) = -Inf", __real__ result);
2853   check_isinfp ("imag(csinh(+Inf - i4.625)) = +Inf", __imag__ result);
2854   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, -4.625));
2855   check_isinfp ("real(csinh(-Inf - i4.625)) = +Inf", __real__ result);
2856   check_isinfp ("imag(csinh(-Inf - i4.625)) = +Inf", __imag__ result);
2857
2858   result = FUNC(csinh) (BUILD_COMPLEX (6.75, plus_infty));
2859   check_isnan_exc ("real(csinh(6.75 + i Inf)) = NaN plus invalid exception",
2860                    __real__ result, INVALID_EXCEPTION);
2861   check_isnan ("imag(csinh(6.75 + i Inf)) = NaN plus invalid exception",
2862                __imag__ result);
2863   result = FUNC(csinh) (BUILD_COMPLEX (-6.75, plus_infty));
2864   check_isnan_exc ("real(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
2865                    __real__ result, INVALID_EXCEPTION);
2866   check_isnan ("imag(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
2867                __imag__ result);
2868   result = FUNC(csinh) (BUILD_COMPLEX (6.75, minus_infty));
2869   check_isnan_exc ("real(csinh(6.75 - i Inf)) = NaN plus invalid exception",
2870                    __real__ result, INVALID_EXCEPTION);
2871   check_isnan ("imag(csinh(6.75 - i Inf)) = NaN plus invalid exception",
2872                __imag__ result);
2873   result = FUNC(csinh) (BUILD_COMPLEX (-6.75, minus_infty));
2874   check_isnan_exc ("real(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
2875                    __real__ result, INVALID_EXCEPTION);
2876   check_isnan ("imag(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
2877                __imag__ result);
2878
2879   result = FUNC(csinh) (BUILD_COMPLEX (0.0, nan_value));
2880   check ("real(csinh(0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
2881   check_isnan ("imag(csinh(0 + i NaN)) = NaN", __imag__ result);
2882   result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, nan_value));
2883   check ("real(csinh(-0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
2884   check_isnan ("imag(csinh(-0 + i NaN)) = NaN", __imag__ result);
2885
2886   result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, nan_value));
2887   check_isinfp ("real(csinh(+Inf + i NaN)) = +-Inf",
2888                 FUNC(fabs) (__real__ result));
2889   check_isnan ("imag(csinh(+Inf + i NaN)) = NaN", __imag__ result);
2890   result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, nan_value));
2891   check_isinfp ("real(csinh(-Inf + i NaN)) = +-Inf",
2892                 FUNC(fabs) (__real__ result));
2893   check_isnan ("imag(csinh(-Inf + i NaN)) = NaN", __imag__ result);
2894
2895   result = FUNC(csinh) (BUILD_COMPLEX (9.0, nan_value));
2896   check_isnan_maybe_exc ("real(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
2897                          __real__ result, INVALID_EXCEPTION);
2898   check_isnan ("imag(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
2899                __imag__ result);
2900   result = FUNC(csinh) (BUILD_COMPLEX (-9.0, nan_value));
2901   check_isnan_maybe_exc ("real(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
2902                          __real__ result, INVALID_EXCEPTION);
2903   check_isnan ("imag(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
2904                __imag__ result);
2905
2906   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 0.0));
2907   check_isnan ("real(csinh(NaN + i0)) = NaN", __real__ result);
2908   check ("imag(csinh(NaN + i0)) = 0", __imag__ result, 0.0);
2909   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_zero));
2910   check_isnan ("real(csinh(NaN - i0)) = NaN", __real__ result);
2911   check ("imag(csinh(NaN - i0)) = -0", __imag__ result, minus_zero);
2912
2913   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 10.0));
2914   check_isnan_maybe_exc ("real(csinh(NaN + i10)) = NaN plus maybe invalid exception",
2915                          __real__ result, INVALID_EXCEPTION);
2916   check_isnan ("imag(csinh(NaN + i10)) = NaN plus maybe invalid exception",
2917                __imag__ result);
2918   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, -10.0));
2919   check_isnan_maybe_exc ("real(csinh(NaN - i10)) = NaN plus maybe invalid exception",
2920                          __real__ result, INVALID_EXCEPTION);
2921   check_isnan ("imag(csinh(NaN - i10)) = NaN plus maybe invalid exception",
2922                __imag__ result);
2923
2924   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, plus_infty));
2925   check_isnan_maybe_exc ("real(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
2926                          __real__ result, INVALID_EXCEPTION);
2927   check_isnan ("imag(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
2928                __imag__ result);
2929   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_infty));
2930   check_isnan_maybe_exc ("real(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
2931                          __real__ result, INVALID_EXCEPTION);
2932   check_isnan ("imag(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
2933                __imag__ result);
2934
2935   result = FUNC(csinh) (BUILD_COMPLEX (nan_value, nan_value));
2936   check_isnan ("real(csinh(NaN + i NaN)) = NaN", __real__ result);
2937   check_isnan ("imag(csinh(NaN + i NaN)) = NaN", __imag__ result);
2938 }
2939
2940
2941 static void
2942 ccos_test (void)
2943 {
2944   __complex__ MATHTYPE result;
2945
2946   result = FUNC(ccos) (BUILD_COMPLEX (0.0, 0.0));
2947   check ("real(ccos(0 + 0i)) = 1.0", __real__ result, 1.0);
2948   check ("imag(ccos(0 + 0i)) = -0", __imag__ result, minus_zero);
2949   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, 0.0));
2950   check ("real(ccos(-0 + 0i)) = 1.0", __real__ result, 1.0);
2951   check ("imag(ccos(-0 + 0i)) = 0", __imag__ result, 0.0);
2952   result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_zero));
2953   check ("real(ccos(0 - 0i)) = 1.0", __real__ result, 1.0);
2954   check ("imag(ccos(0 - 0i)) = 0", __imag__ result, 0.0);
2955   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_zero));
2956   check ("real(ccos(-0 - 0i)) = 1.0", __real__ result, 1.0);
2957   check ("imag(ccos(-0 - 0i)) = -0", __imag__ result, minus_zero);
2958
2959   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 0.0));
2960   check_isnan_exc ("real(ccos(+Inf + i0)) = NaN plus invalid exception",
2961                    __real__ result, INVALID_EXCEPTION);
2962   check ("imag(ccos(Inf + i0)) = +-0 plus invalid exception",
2963          FUNC(fabs) (__imag__ result), 0);
2964   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_zero));
2965   check_isnan_exc ("real(ccos(Inf - i0)) = NaN plus invalid exception",
2966                    __real__ result, INVALID_EXCEPTION);
2967   check ("imag(ccos(Inf - i0)) = +-0 plus invalid exception",
2968          FUNC(fabs) (__imag__ result), 0);
2969   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 0.0));
2970   check_isnan_exc ("real(ccos(-Inf + i0)) = NaN plus invalid exception",
2971                    __real__ result, INVALID_EXCEPTION);
2972   check ("imag(ccos(-Inf + i0)) = +-0 plus invalid exception",
2973          FUNC(fabs) (__imag__ result), 0);
2974   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_zero));
2975   check_isnan_exc ("real(ccos(-Inf - i0)) = NaN plus invalid exception",
2976                    __real__ result, INVALID_EXCEPTION);
2977   check ("imag(ccos(-Inf - i0)) = +-0 plus invalid exception",
2978          FUNC(fabs) (__imag__ result), 0);
2979
2980   result = FUNC(ccos) (BUILD_COMPLEX (0.0, plus_infty));
2981   check_isinfp ("real(ccos(0 + i Inf)) = +Inf", __real__ result);
2982   check ("imag(ccos(0 + i Inf)) = -0", __imag__ result, minus_zero);
2983   result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_infty));
2984   check_isinfp ("real(ccos(0 - i Inf)) = +Inf", __real__ result);
2985   check ("imag(ccos(0 - i Inf)) = 0", __imag__ result, 0);
2986   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, plus_infty));
2987   check_isinfp ("real(ccos(-0 + i Inf)) = +Inf", __real__ result);
2988   check ("imag(ccos(-0 + i Inf)) = 0", __imag__ result, 0.0);
2989   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_infty));
2990   check_isinfp ("real(ccos(-0 - i Inf)) = +Inf", __real__ result);
2991   check ("imag(ccos(-0 - i Inf)) = -0", __imag__ result, minus_zero);
2992
2993   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, plus_infty));
2994   check_isinfp_exc ("real(ccos(+Inf + i Inf)) = +Inf plus invalid exception",
2995                     __real__ result, INVALID_EXCEPTION);
2996   check_isnan ("imag(ccos(+Inf + i Inf)) = NaN plus invalid exception",
2997                __imag__ result);
2998   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, plus_infty));
2999   check_isinfp_exc ("real(ccos(-Inf + i Inf)) = +Inf plus invalid exception",
3000                     __real__ result, INVALID_EXCEPTION);
3001   check_isnan ("imag(ccos(-Inf + i Inf)) = NaN plus invalid exception",
3002                __imag__ result);
3003   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_infty));
3004   check_isinfp_exc ("real(ccos(Inf - i Inf)) = +Inf plus invalid exception",
3005                     __real__ result, INVALID_EXCEPTION);
3006   check_isnan ("imag(ccos(Inf - i Inf)) = NaN plus invalid exception",
3007                __imag__ result);
3008   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_infty));
3009   check_isinfp_exc ("real(ccos(-Inf - i Inf)) = +Inf plus invalid exception",
3010                     __real__ result, INVALID_EXCEPTION);
3011   check_isnan ("imag(ccos(-Inf - i Inf)) = NaN plus invalid exception",
3012                __imag__ result);
3013
3014   result = FUNC(ccos) (BUILD_COMPLEX (4.625, plus_infty));
3015   check_isinfn ("real(ccos(4.625 + i Inf)) = -Inf", __real__ result);
3016   check_isinfp ("imag(ccos(4.625 + i Inf)) = +Inf", __imag__ result);
3017   result = FUNC(ccos) (BUILD_COMPLEX (4.625, minus_infty));
3018   check_isinfn ("real(ccos(4.625 - i Inf)) = -Inf", __real__ result);
3019   check_isinfn ("imag(ccos(4.625 - i Inf)) = -Inf", __imag__ result);
3020   result = FUNC(ccos) (BUILD_COMPLEX (-4.625, plus_infty));
3021   check_isinfn ("real(ccos(-4.625 + i Inf)) = -Inf", __real__ result);
3022   check_isinfn ("imag(ccos(-4.625 + i Inf)) = -Inf", __imag__ result);
3023   result = FUNC(ccos) (BUILD_COMPLEX (-4.625, minus_infty));
3024   check_isinfn ("real(ccos(-4.625 - i Inf)) = -Inf", __real__ result);
3025   check_isinfp ("imag(ccos(-4.625 - i Inf)) = +Inf", __imag__ result);
3026
3027   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 6.75));
3028   check_isnan_exc ("real(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3029                    __real__ result, INVALID_EXCEPTION);
3030   check_isnan ("imag(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3031                __imag__ result);
3032   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, -6.75));
3033   check_isnan_exc ("real(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3034                    __real__ result, INVALID_EXCEPTION);
3035   check_isnan ("imag(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3036                __imag__ result);
3037   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 6.75));
3038   check_isnan_exc ("real(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3039                    __real__ result, INVALID_EXCEPTION);
3040   check_isnan ("imag(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3041                __imag__ result);
3042   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, -6.75));
3043   check_isnan_exc ("real(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3044                    __real__ result, INVALID_EXCEPTION);
3045   check_isnan ("imag(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3046                __imag__ result);
3047
3048   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 0.0));
3049   check_isnan ("real(ccos(NaN + i0)) = NaN", __real__ result);
3050   check ("imag(ccos(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3051   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_zero));
3052   check_isnan ("real(ccos(NaN - i0)) = NaN", __real__ result);
3053   check ("imag(ccos(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3054
3055   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, plus_infty));
3056   check_isinfp ("real(ccos(NaN + i Inf)) = +Inf", __real__ result);
3057   check_isnan ("imag(ccos(NaN + i Inf)) = NaN", __imag__ result);
3058   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_infty));
3059   check_isinfp ("real(ccos(NaN - i Inf)) = +Inf", __real__ result);
3060   check_isnan ("imag(ccos(NaN - i Inf)) = NaN", __imag__ result);
3061
3062   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 9.0));
3063   check_isnan_maybe_exc ("real(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3064                          __real__ result, INVALID_EXCEPTION);
3065   check_isnan ("imag(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3066                __imag__ result);
3067   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, -9.0));
3068   check_isnan_maybe_exc ("real(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3069                          __real__ result, INVALID_EXCEPTION);
3070   check_isnan ("imag(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3071                __imag__ result);
3072
3073   result = FUNC(ccos) (BUILD_COMPLEX (0.0, nan_value));
3074   check_isnan ("real(ccos(0 + i NaN)) = NaN", __real__ result);
3075   check ("imag(ccos(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3076   result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, nan_value));
3077   check_isnan ("real(ccos(-0 + i NaN)) = NaN", __real__ result);
3078   check ("imag(ccos(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3079
3080   result = FUNC(ccos) (BUILD_COMPLEX (10.0, nan_value));
3081   check_isnan_maybe_exc ("real(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3082                          __real__ result, INVALID_EXCEPTION);
3083   check_isnan ("imag(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3084                __imag__ result);
3085   result = FUNC(ccos) (BUILD_COMPLEX (-10.0, nan_value));
3086   check_isnan_maybe_exc ("real(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3087                          __real__ result, INVALID_EXCEPTION);
3088   check_isnan ("imag(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3089                __imag__ result);
3090
3091   result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, nan_value));
3092   check_isnan_maybe_exc ("real(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3093                          __real__ result, INVALID_EXCEPTION);
3094   check_isnan ("imag(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3095                __imag__ result);
3096   result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, nan_value));
3097   check_isnan_maybe_exc ("real(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3098                          __real__ result, INVALID_EXCEPTION);
3099   check_isnan ("imag(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3100                __imag__ result);
3101
3102   result = FUNC(ccos) (BUILD_COMPLEX (nan_value, nan_value));
3103   check_isnan ("real(ccos(NaN + i NaN)) = NaN", __real__ result);
3104   check_isnan ("imag(ccos(NaN + i NaN)) = NaN", __imag__ result);
3105 }
3106
3107
3108 static void
3109 ccosh_test (void)
3110 {
3111   __complex__ MATHTYPE result;
3112
3113   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, 0.0));
3114   check ("real(ccosh(0 + 0i)) = 1.0", __real__ result, 1.0);
3115   check ("imag(ccosh(0 + 0i)) = 0", __imag__ result, 0);
3116   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, 0.0));
3117   check ("real(ccosh(-0 + 0i)) = 1.0", __real__ result, 1.0);
3118   check ("imag(ccosh(-0 + 0i)) = -0", __imag__ result, minus_zero);
3119   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_zero));
3120   check ("real(ccosh(0 - 0i)) = 1.0", __real__ result, 1.0);
3121   check ("imag(ccosh(0 - 0i)) = -0", __imag__ result, minus_zero);
3122   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3123   check ("real(ccosh(-0 - 0i)) = 1.0", __real__ result, 1.0);
3124   check ("imag(ccosh(-0 - 0i)) = 0", __imag__ result, 0.0);
3125
3126   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, plus_infty));
3127   check_isnan_exc ("real(ccosh(0 + i Inf)) = NaN plus invalid exception",
3128                    __real__ result, INVALID_EXCEPTION);
3129   check ("imag(ccosh(0 + i Inf)) = +-0 plus invalid exception",
3130          FUNC(fabs) (__imag__ result), 0);
3131   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, plus_infty));
3132   check_isnan_exc ("real(ccosh(-0 + i Inf)) = NaN plus invalid exception",
3133                    __real__ result, INVALID_EXCEPTION);
3134   check ("imag(ccosh(-0 + i Inf)) = +-0 plus invalid exception",
3135          FUNC(fabs) (__imag__ result), 0);
3136   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_infty));
3137   check_isnan_exc ("real(ccosh(0 - i Inf)) = NaN plus invalid exception",
3138                    __real__ result, INVALID_EXCEPTION);
3139   check ("imag(ccosh(0 - i Inf)) = +-0 plus invalid exception",
3140          FUNC(fabs) (__imag__ result), 0);
3141   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_infty));
3142   check_isnan_exc ("real(ccosh(-0 - i Inf)) = NaN plus invalid exception",
3143                    __real__ result, INVALID_EXCEPTION);
3144   check ("imag(ccosh(-0 - i Inf)) = +-0 plus invalid exception",
3145          FUNC(fabs) (__imag__ result), 0);
3146
3147   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 0.0));
3148   check_isinfp ("real(ccosh(+Inf + 0i)) = +Inf", __real__ result);
3149   check ("imag(ccosh(+Inf + 0i)) = 0", __imag__ result, 0);
3150   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 0.0));
3151   check_isinfp ("real(ccosh(-Inf + 0i)) = +Inf", __real__ result);
3152   check ("imag(ccosh(-Inf + 0i)) = -0", __imag__ result, minus_zero);
3153   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3154   check_isinfp ("real(ccosh(+Inf - 0i)) = +Inf", __real__ result);
3155   check ("imag(ccosh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
3156   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3157   check_isinfp ("real(ccosh(-Inf - 0i)) = +Inf", __real__ result);
3158   check ("imag(ccosh(-Inf - 0i)) = 0", __imag__ result, 0.0);
3159
3160   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3161   check_isinfp_exc ("real(ccosh(+Inf + i Inf)) = +Inf plus invalid exception",
3162                     __real__ result, INVALID_EXCEPTION);
3163   check_isnan ("imag(ccosh(+Inf + i Inf)) = NaN plus invalid exception",
3164                __imag__ result);
3165   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3166   check_isinfp_exc ("real(ccosh(-Inf + i Inf)) = +Inf plus invalid exception",
3167                     __real__ result, INVALID_EXCEPTION);
3168   check_isnan ("imag(ccosh(-Inf + i Inf)) = NaN plus invalid exception",
3169                __imag__ result);
3170   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3171   check_isinfp_exc ("real(ccosh(Inf - i Inf)) = +Inf plus invalid exception",
3172                     __real__ result, INVALID_EXCEPTION);
3173   check_isnan ("imag(ccosh(Inf - i Inf)) = NaN plus invalid exception",
3174                __imag__ result);
3175   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3176   check_isinfp_exc ("real(ccosh(-Inf - i Inf)) = +Inf plus invalid exception",
3177                     __real__ result, INVALID_EXCEPTION);
3178   check_isnan ("imag(ccosh(-Inf - i Inf)) = NaN plus invalid exception",
3179                __imag__ result);
3180
3181   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 4.625));
3182   check_isinfn ("real(ccosh(+Inf + i4.625)) = -Inf", __real__ result);
3183   check_isinfn ("imag(ccosh(+Inf + i4.625)) = -Inf", __imag__ result);
3184   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 4.625));
3185   check_isinfn ("real(ccosh(-Inf + i4.625)) = -Inf", __real__ result);
3186   check_isinfp ("imag(ccosh(-Inf + i4.625)) = Inf", __imag__ result);
3187   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, -4.625));
3188   check_isinfn ("real(ccosh(+Inf - i4.625)) = -Inf", __real__ result);
3189   check_isinfp ("imag(ccosh(+Inf - i4.625)) = +Inf", __imag__ result);
3190   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, -4.625));
3191   check_isinfn ("real(ccosh(-Inf - i4.625)) = -Inf", __real__ result);
3192   check_isinfn ("imag(ccosh(-Inf - i4.625)) = -Inf", __imag__ result);
3193
3194   result = FUNC(ccosh) (BUILD_COMPLEX (6.75, plus_infty));
3195   check_isnan_exc ("real(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3196                    __real__ result, INVALID_EXCEPTION);
3197   check_isnan ("imag(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3198                __imag__ result);
3199   result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, plus_infty));
3200   check_isnan_exc ("real(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3201                    __real__ result, INVALID_EXCEPTION);
3202   check_isnan ("imag(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3203                __imag__ result);
3204   result = FUNC(ccosh) (BUILD_COMPLEX (6.75, minus_infty));
3205   check_isnan_exc ("real(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3206                    __real__ result, INVALID_EXCEPTION);
3207   check_isnan ("imag(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3208                __imag__ result);
3209   result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, minus_infty));
3210   check_isnan_exc ("real(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3211                    __real__ result, INVALID_EXCEPTION);
3212   check_isnan ("imag(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3213                __imag__ result);
3214
3215   result = FUNC(ccosh) (BUILD_COMPLEX (0.0, nan_value));
3216   check_isnan ("real(ccosh(0 + i NaN)) = NaN", __real__ result);
3217   check ("imag(ccosh(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3218   result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, nan_value));
3219   check_isnan ("real(ccosh(-0 + i NaN)) = NaN", __real__ result);
3220   check ("imag(ccosh(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3221
3222   result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, nan_value));
3223   check_isinfp ("real(ccosh(+Inf + i NaN)) = +Inf", __real__ result);
3224   check_isnan ("imag(ccosh(+Inf + i NaN)) = NaN", __imag__ result);
3225   result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, nan_value));
3226   check_isinfp ("real(ccosh(-Inf + i NaN)) = +Inf", __real__ result);
3227   check_isnan ("imag(ccosh(-Inf + i NaN)) = NaN", __imag__ result);
3228
3229   result = FUNC(ccosh) (BUILD_COMPLEX (9.0, nan_value));
3230   check_isnan_maybe_exc ("real(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3231                          __real__ result, INVALID_EXCEPTION);
3232   check_isnan ("imag(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3233                __imag__ result);
3234   result = FUNC(ccosh) (BUILD_COMPLEX (-9.0, nan_value));
3235   check_isnan_maybe_exc ("real(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3236                          __real__ result, INVALID_EXCEPTION);
3237   check_isnan ("imag(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3238                __imag__ result);
3239
3240   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 0.0));
3241   check_isnan ("real(ccosh(NaN + i0)) = NaN", __real__ result);
3242   check ("imag(ccosh(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3243   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_zero));
3244   check_isnan ("real(ccosh(NaN - i0)) = NaN", __real__ result);
3245   check ("imag(ccosh(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3246
3247   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 10.0));
3248   check_isnan_maybe_exc ("real(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3249                          __real__ result, INVALID_EXCEPTION);
3250   check_isnan ("imag(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3251                __imag__ result);
3252   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, -10.0));
3253   check_isnan_maybe_exc ("real(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3254                          __real__ result, INVALID_EXCEPTION);
3255   check_isnan ("imag(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3256                __imag__ result);
3257
3258   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, plus_infty));
3259   check_isnan_maybe_exc ("real(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3260                          __real__ result, INVALID_EXCEPTION);
3261   check_isnan ("imag(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3262                __imag__ result);
3263   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_infty));
3264   check_isnan_maybe_exc ("real(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3265                          __real__ result, INVALID_EXCEPTION);
3266   check_isnan ("imag(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3267                __imag__ result);
3268
3269   result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, nan_value));
3270   check_isnan ("real(ccosh(NaN + i NaN)) = NaN", __real__ result);
3271   check_isnan ("imag(ccosh(NaN + i NaN)) = NaN", __imag__ result);
3272 }
3273
3274
3275 static void
3276 cacos_test (void)
3277 {
3278   __complex__ MATHTYPE result;
3279
3280   result = FUNC(cacos) (BUILD_COMPLEX (0, 0));
3281   check ("real(cacos(0 + i0)) = pi/2", __real__ result, M_PI_2);
3282   check ("imag(cacos(0 + i0)) = -0", __imag__ result, minus_zero);
3283   result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, 0));
3284   check ("real(cacos(-0 + i0)) = pi/2", __real__ result, M_PI_2);
3285   check ("imag(cacos(-0 + i0)) = -0", __imag__ result, minus_zero);
3286   result = FUNC(cacos) (BUILD_COMPLEX (0, minus_zero));
3287   check ("real(cacos(0 - i0)) = pi/2", __real__ result, M_PI_2);
3288   check ("imag(cacos(0 - i0)) = 0", __imag__ result, 0);
3289   result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, minus_zero));
3290   check ("real(cacos(-0 - i0)) = pi/2", __real__ result, M_PI_2);
3291   check ("imag(cacos(-0 - i0)) = 0", __imag__ result, 0);
3292
3293   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, plus_infty));
3294   check ("real(cacos(-Inf + i Inf)) = 3*pi/4", __real__ result, M_PI - M_PI_4);
3295   check_isinfn ("imag(cacos(-Inf + i Inf)) = -Inf", __imag__ result);
3296   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_infty));
3297   check ("real(cacos(-Inf - i Inf)) = 3*pi/4", __real__ result, M_PI - M_PI_4);
3298   check_isinfp ("imag(cacos(-Inf - i Inf)) = +Inf", __imag__ result);
3299
3300   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, plus_infty));
3301   check ("real(cacos(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4);
3302   check_isinfn ("imag(cacos(+Inf + i Inf)) = -Inf", __imag__ result);
3303   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_infty));
3304   check ("real(cacos(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4);
3305   check_isinfp ("imag(cacos(+Inf - i Inf)) = +Inf", __imag__ result);
3306
3307   result = FUNC(cacos) (BUILD_COMPLEX (-10.0, plus_infty));
3308   check ("real(cacos(-10.0 + i Inf)) = pi/2", __real__ result, M_PI_2);
3309   check_isinfn ("imag(cacos(-10.0 + i Inf)) = -Inf", __imag__ result);
3310   result = FUNC(cacos) (BUILD_COMPLEX (-10.0, minus_infty));
3311   check ("real(cacos(-10.0 - i Inf)) = pi/2", __real__ result, M_PI_2);
3312   check_isinfp ("imag(cacos(-10.0 - i Inf)) = +Inf", __imag__ result);
3313   result = FUNC(cacos) (BUILD_COMPLEX (0, plus_infty));
3314   check ("real(cacos(0 + i Inf)) = pi/2", __real__ result, M_PI_2);
3315   check_isinfn ("imag(cacos(0 + i Inf)) = -Inf", __imag__ result);
3316   result = FUNC(cacos) (BUILD_COMPLEX (0, minus_infty));
3317   check ("real(cacos(0 - i Inf)) = pi/2", __real__ result, M_PI_2);
3318   check_isinfp ("imag(cacos(0 - i Inf)) = +Inf", __imag__ result);
3319   result = FUNC(cacos) (BUILD_COMPLEX (0.1, plus_infty));
3320   check ("real(cacos(0.1 + i Inf)) = pi/2", __real__ result, M_PI_2);
3321   check_isinfn ("imag(cacos(0.1 + i Inf)) = -Inf", __imag__ result);
3322   result = FUNC(cacos) (BUILD_COMPLEX (0.1, minus_infty));
3323   check ("real(cacos(0.1 - i Inf)) = pi/2", __real__ result, M_PI_2);
3324   check_isinfp ("imag(cacos(0.1 - i Inf)) = +Inf", __imag__ result);
3325
3326   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 0));
3327   check ("real(cacos(-Inf + i0)) = pi", __real__ result, M_PI);
3328   check_isinfn ("imag(cacos(-Inf + i0)) = -Inf", __imag__ result);
3329   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_zero));
3330   check ("real(cacos(-Inf - i0)) = pi", __real__ result, M_PI);
3331   check_isinfp ("imag(cacos(-Inf - i0)) = +Inf", __imag__ result);
3332   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 100));
3333   check ("real(cacos(-Inf + i100)) = pi", __real__ result, M_PI);
3334   check_isinfn ("imag(cacos(-Inf + i100)) = -Inf", __imag__ result);
3335   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, -100));
3336   check ("real(cacos(-Inf - i100)) = pi", __real__ result, M_PI);
3337   check_isinfp ("imag(cacos(-Inf - i100)) = +Inf", __imag__ result);
3338
3339   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0));
3340   check ("real(cacos(+Inf + i0)) = 0", __real__ result, 0);
3341   check_isinfn ("imag(cacos(+Inf + i0)) = -Inf", __imag__ result);
3342   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_zero));
3343   check ("real(cacos(+Inf - i0)) = 0", __real__ result, 0);
3344   check_isinfp ("imag(cacos(+Inf - i0)) = +Inf", __imag__ result);
3345   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0.5));
3346   check ("real(cacos(+Inf + i0.5)) = 0", __real__ result, 0);
3347   check_isinfn ("imag(cacos(+Inf + i0.5)) = -Inf", __imag__ result);
3348   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, -0.5));
3349   check ("real(cacos(+Inf - i0.5)) = 0", __real__ result, 0);
3350   check_isinfp ("imag(cacos(+Inf - i0.5)) = +Inf", __imag__ result);
3351
3352   result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, nan_value));
3353   check_isnan ("real(cacos(+Inf + i NaN)) = NaN", __real__ result);
3354   check_isinfp ("imag(cacos(+Inf + i NaN)) = +-Inf",
3355                 FUNC(fabs) (__imag__ result));
3356   result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, nan_value));
3357   check_isnan ("real(cacos(-Inf + i NaN)) = NaN", __real__ result);
3358   check_isinfp ("imag(cacos(-Inf + i NaN)) = +-Inf",
3359                 FUNC(fabs) (__imag__ result));
3360
3361   result = FUNC(cacos) (BUILD_COMPLEX (0, nan_value));
3362   check ("real(cacos(0 + i NaN)) = pi/2", __real__ result, M_PI_2);
3363   check_isnan ("imag(cacos(0 + i NaN)) = NaN", __imag__ result);
3364   result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, nan_value));
3365   check ("real(cacos(-0 + i NaN)) = pi/2", __real__ result, M_PI_2);
3366   check_isnan ("imag(cacos(-0 + i NaN)) = NaN", __imag__ result);
3367
3368   result = FUNC(cacos) (BUILD_COMPLEX (nan_value, plus_infty));
3369   check_isnan ("real(cacos(NaN + i Inf)) = NaN", __real__ result);
3370   check_isinfn ("imag(cacos(NaN + i Inf)) = -Inf", __imag__ result);
3371   result = FUNC(cacos) (BUILD_COMPLEX (nan_value, minus_infty));
3372   check_isnan ("real(cacos(NaN - i Inf)) = NaN", __real__ result);
3373   check_isinfp ("imag(cacos(NaN - i Inf)) = +Inf", __imag__ result);
3374
3375   result = FUNC(cacos) (BUILD_COMPLEX (10.5, nan_value));
3376   check_isnan_maybe_exc ("real(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3377                          __real__ result, INVALID_EXCEPTION);
3378   check_isnan ("imag(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3379                __imag__ result);
3380   result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3381   check_isnan_maybe_exc ("real(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3382                          __real__ result, INVALID_EXCEPTION);
3383   check_isnan ("imag(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3384                __imag__ result);
3385
3386   result = FUNC(cacos) (BUILD_COMPLEX (nan_value, 0.75));
3387   check_isnan_maybe_exc ("real(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3388                          __real__ result, INVALID_EXCEPTION);
3389   check_isnan ("imag(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3390                __imag__ result);
3391   result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3392   check_isnan_maybe_exc ("real(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3393                          __real__ result, INVALID_EXCEPTION);
3394   check_isnan ("imag(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3395                __imag__ result);
3396
3397   result = FUNC(cacos) (BUILD_COMPLEX (nan_value, nan_value));
3398   check_isnan ("real(cacos(NaN + i NaN)) = NaN", __real__ result);
3399   check_isnan ("imag(cacos(NaN + i NaN)) = NaN", __imag__ result);
3400 }
3401
3402
3403 static void
3404 cacosh_test (void)
3405 {
3406   __complex__ MATHTYPE result;
3407
3408   result = FUNC(cacosh) (BUILD_COMPLEX (0, 0));
3409   check ("real(cacosh(0 + i0)) = 0", __real__ result, 0);
3410   check ("imag(cacosh(0 + i0)) = pi/2", __imag__ result, M_PI_2);
3411   result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, 0));
3412   check ("real(cacosh(-0 + i0)) = 0", __real__ result, 0);
3413   check ("imag(cacosh(-0 + i0)) = pi/2", __imag__ result, M_PI_2);
3414   result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_zero));
3415   check ("real(cacosh(0 - i0)) = 0", __real__ result, 0);
3416   check ("imag(cacosh(0 - i0)) = -pi/2", __imag__ result, -M_PI_2);
3417   result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3418   check ("real(cacosh(-0 - i0)) = 0", __real__ result, 0);
3419   check ("imag(cacosh(-0 - i0)) = -pi/2", __imag__ result, -M_PI_2);
3420
3421   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3422   check_isinfp ("real(cacosh(-Inf + i Inf)) = +Inf", __real__ result);
3423   check ("imag(cacosh(-Inf + i Inf)) = 3*pi/4", __imag__ result,
3424          M_PI - M_PI_4);
3425   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3426   check_isinfp ("real(cacosh(-Inf - i Inf)) = +Inf", __real__ result);
3427   check ("imag(cacosh(-Inf - i Inf)) = -3*pi/4", __imag__ result,
3428          M_PI_4 - M_PI);
3429
3430   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3431   check_isinfp ("real(cacosh(+Inf + i Inf)) = +Inf", __real__ result);
3432   check ("imag(cacosh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
3433   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3434   check_isinfp ("real(cacosh(+Inf - i Inf)) = +Inf", __real__ result);
3435   check ("imag(cacosh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
3436
3437   result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, plus_infty));
3438   check_isinfp ("real(cacosh(-10.0 + i Inf)) = +Inf", __real__ result);
3439   check ("imag(cacosh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3440   result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, minus_infty));
3441   check_isinfp ("real(cacosh(-10.0 - i Inf)) = +Inf", __real__ result);
3442   check ("imag(cacosh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3443   result = FUNC(cacosh) (BUILD_COMPLEX (0, plus_infty));
3444   check_isinfp ("real(cacosh(0 + i Inf)) = +Inf", __real__ result);
3445   check ("imag(cacosh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3446   result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_infty));
3447   check_isinfp ("real(cacosh(0 - i Inf)) = +Inf", __real__ result);
3448   check ("imag(cacosh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3449   result = FUNC(cacosh) (BUILD_COMPLEX (0.1, plus_infty));
3450   check_isinfp ("real(cacosh(0.1 + i Inf)) = +Inf", __real__ result);
3451   check ("imag(cacosh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3452   result = FUNC(cacosh) (BUILD_COMPLEX (0.1, minus_infty));
3453   check_isinfp ("real(cacosh(0.1 - i Inf)) = +Inf", __real__ result);
3454   check ("imag(cacosh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3455
3456   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 0));
3457   check_isinfp ("real(cacosh(-Inf + i0)) = +Inf", __real__ result);
3458   check ("imag(cacosh(-Inf + i0)) = pi", __imag__ result, M_PI);
3459   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3460   check_isinfp ("real(cacosh(-Inf - i0)) = +Inf", __real__ result);
3461   check ("imag(cacosh(-Inf - i0)) = -pi", __imag__ result, -M_PI);
3462   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 100));
3463   check_isinfp ("real(cacosh(-Inf + i100)) = +Inf", __real__ result);
3464   check ("imag(cacosh(-Inf + i100)) = pi", __imag__ result, M_PI);
3465   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, -100));
3466   check_isinfp ("real(cacosh(-Inf - i100)) = +Inf", __real__ result);
3467   check ("imag(cacosh(-Inf - i100)) = -pi", __imag__ result, -M_PI);
3468
3469   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0));
3470   check_isinfp ("real(cacosh(+Inf + i0)) = +Inf", __real__ result);
3471   check ("imag(cacosh(+Inf + i0)) = 0", __imag__ result, 0);
3472   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3473   check_isinfp ("real(cacosh(+Inf - i0)) = +Inf", __real__ result);
3474   check ("imag(cacosh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3475   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0.5));
3476   check_isinfp ("real(cacosh(+Inf + i0.5)) = +Inf", __real__ result);
3477   check ("imag(cacosh(+Inf + i0.5)) = 0", __imag__ result, 0);
3478   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, -0.5));
3479   check_isinfp ("real(cacosh(+Inf - i0.5)) = +Inf", __real__ result);
3480   check ("imag(cacosh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3481
3482   result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, nan_value));
3483   check_isinfp ("real(cacosh(+Inf + i NaN)) = +Inf", __real__ result);
3484   check_isnan ("imag(cacosh(+Inf + i NaN)) = NaN", __imag__ result);
3485   result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, nan_value));
3486   check_isinfp ("real(cacosh(-Inf + i NaN)) = +Inf", __real__ result);
3487   check_isnan ("imag(cacosh(-Inf + i NaN)) = NaN", __imag__ result);
3488
3489   result = FUNC(cacosh) (BUILD_COMPLEX (0, nan_value));
3490   check_isnan ("real(cacosh(0 + i NaN)) = NaN", __real__ result);
3491   check_isnan ("imag(cacosh(0 + i NaN)) = NaN", __imag__ result);
3492   result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, nan_value));
3493   check_isnan ("real(cacosh(-0 + i NaN)) = NaN", __real__ result);
3494   check_isnan ("imag(cacosh(-0 + i NaN)) = NaN", __imag__ result);
3495
3496   result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, plus_infty));
3497   check_isinfp ("real(cacosh(NaN + i Inf)) = +Inf", __real__ result);
3498   check_isnan ("imag(cacosh(NaN + i Inf)) = NaN", __imag__ result);
3499   result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, minus_infty));
3500   check_isinfp ("real(cacosh(NaN - i Inf)) = +Inf", __real__ result);
3501   check_isnan ("imag(cacosh(NaN - i Inf)) = NaN", __imag__ result);
3502
3503   result = FUNC(cacosh) (BUILD_COMPLEX (10.5, nan_value));
3504   check_isnan_maybe_exc ("real(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3505                          __real__ result, INVALID_EXCEPTION);
3506   check_isnan ("imag(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3507                __imag__ result);
3508   result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3509   check_isnan_maybe_exc ("real(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3510                          __real__ result, INVALID_EXCEPTION);
3511   check_isnan ("imag(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3512                __imag__ result);
3513
3514   result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, 0.75));
3515   check_isnan_maybe_exc ("real(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3516                          __real__ result, INVALID_EXCEPTION);
3517   check_isnan ("imag(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3518                __imag__ result);
3519   result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3520   check_isnan_maybe_exc ("real(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3521                          __real__ result, INVALID_EXCEPTION);
3522   check_isnan ("imag(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3523                __imag__ result);
3524
3525   result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, nan_value));
3526   check_isnan ("real(cacosh(NaN + i NaN)) = NaN", __real__ result);
3527   check_isnan ("imag(cacosh(NaN + i NaN)) = NaN", __imag__ result);
3528 }
3529
3530
3531 static void
3532 casin_test (void)
3533 {
3534   __complex__ MATHTYPE result;
3535
3536   result = FUNC(casin) (BUILD_COMPLEX (0, 0));
3537   check ("real(casin(0 + i0)) = 0", __real__ result, 0);
3538   check ("imag(casin(0 + i0)) = 0", __imag__ result, 0);
3539   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, 0));
3540   check ("real(casin(-0 + i0)) = -0", __real__ result, minus_zero);
3541   check ("imag(casin(-0 + i0)) = 0", __imag__ result, 0);
3542   result = FUNC(casin) (BUILD_COMPLEX (0, minus_zero));
3543   check ("real(casin(0 - i0)) = 0", __real__ result, 0);
3544   check ("imag(casin(0 - i0)) = -0", __imag__ result, minus_zero);
3545   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_zero));
3546   check ("real(casin(-0 - i0)) = -0", __real__ result, minus_zero);
3547   check ("imag(casin(-0 - i0)) = -0", __imag__ result, minus_zero);
3548
3549   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, plus_infty));
3550   check ("real(casin(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4);
3551   check_isinfp ("imag(casin(+Inf + i Inf)) = +Inf", __imag__ result);
3552   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_infty));
3553   check ("real(casin(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4);
3554   check_isinfn ("imag(casin(+Inf - i Inf)) = -Inf", __imag__ result);
3555   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, plus_infty));
3556   check ("real(casin(-Inf + i Inf)) = -pi/4", __real__ result, -M_PI_4);
3557   check_isinfp ("imag(casin(-Inf + i Inf)) = +Inf", __imag__ result);
3558   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_infty));
3559   check ("real(casin(-Inf - i Inf)) = -pi/4", __real__ result, -M_PI_4);
3560   check_isinfn ("imag(casin(-Inf - i Inf)) = -Inf", __imag__ result);
3561
3562   result = FUNC(casin) (BUILD_COMPLEX (-10.0, plus_infty));
3563   check ("real(casin(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
3564   check_isinfp ("imag(casin(-10.0 + i Inf)) = +Inf", __imag__ result);
3565   result = FUNC(casin) (BUILD_COMPLEX (-10.0, minus_infty));
3566   check ("real(casin(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
3567   check_isinfn ("imag(casin(-10.0 - i Inf)) = -Inf", __imag__ result);
3568   result = FUNC(casin) (BUILD_COMPLEX (0, plus_infty));
3569   check ("real(casin(0 + i Inf)) = 0", __real__ result, 0.0);
3570   check_isinfp ("imag(casin(0 + i Inf)) = +Inf", __imag__ result);
3571   result = FUNC(casin) (BUILD_COMPLEX (0, minus_infty));
3572   check ("real(casin(0 - i Inf)) = 0", __real__ result, 0.0);
3573   check_isinfn ("imag(casin(0 - i Inf)) = -Inf", __imag__ result);
3574   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, plus_infty));
3575   check ("real(casin(-0 + i Inf)) = -0", __real__ result, minus_zero);
3576   check_isinfp ("imag(casin(-0 + i Inf)) = +Inf", __imag__ result);
3577   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_infty));
3578   check ("real(casin(-0 - i Inf)) = -0", __real__ result, minus_zero);
3579   check_isinfn ("imag(casin(-0 - i Inf)) = -Inf", __imag__ result);
3580   result = FUNC(casin) (BUILD_COMPLEX (0.1, plus_infty));
3581   check ("real(casin(0.1 + i Inf)) = 0", __real__ result, 0);
3582   check_isinfp ("imag(casin(0.1 + i Inf)) = +Inf", __imag__ result);
3583   result = FUNC(casin) (BUILD_COMPLEX (0.1, minus_infty));
3584   check ("real(casin(0.1 - i Inf)) = 0", __real__ result, 0);
3585   check_isinfn ("imag(casin(0.1 - i Inf)) = -Inf", __imag__ result);
3586
3587   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 0));
3588   check ("real(casin(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2);
3589   check_isinfp ("imag(casin(-Inf + i0)) = +Inf", __imag__ result);
3590   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_zero));
3591   check ("real(casin(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2);
3592   check_isinfn ("imag(casin(-Inf - i0)) = -Inf", __imag__ result);
3593   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 100));
3594   check ("real(casin(-Inf + i100)) = -pi/2", __real__ result, -M_PI_2);
3595   check_isinfp ("imag(casin(-Inf + i100)) = +Inf", __imag__ result);
3596   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, -100));
3597   check ("real(casin(-Inf - i100)) = -pi/2", __real__ result, -M_PI_2);
3598   check_isinfn ("imag(casin(-Inf - i100)) = -Inf", __imag__ result);
3599
3600   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0));
3601   check ("real(casin(+Inf + i0)) = pi/2", __real__ result, M_PI_2);
3602   check_isinfp ("imag(casin(+Inf + i0)) = +Inf", __imag__ result);
3603   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_zero));
3604   check ("real(casin(+Inf - i0)) = pi/2", __real__ result, M_PI_2);
3605   check_isinfn ("imag(casin(+Inf - i0)) = -Inf", __imag__ result);
3606   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0.5));
3607   check ("real(casin(+Inf + i0.5)) = pi/2", __real__ result, M_PI_2);
3608   check_isinfp ("imag(casin(+Inf + i0.5)) = +Inf", __imag__ result);
3609   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, -0.5));
3610   check ("real(casin(+Inf - i0.5)) = pi/2", __real__ result, M_PI_2);
3611   check_isinfn ("imag(casin(+Inf - i0.5)) = -Inf", __imag__ result);
3612
3613   result = FUNC(casin) (BUILD_COMPLEX (nan_value, plus_infty));
3614   check_isnan ("real(casin(NaN + i Inf)) = NaN", __real__ result);
3615   check_isinfp ("imag(casin(NaN + i Inf)) = +Inf", __imag__ result);
3616   result = FUNC(casin) (BUILD_COMPLEX (nan_value, minus_infty));
3617   check_isnan ("real(casin(NaN - i Inf)) = NaN", __real__ result);
3618   check_isinfn ("imag(casin(NaN - i Inf)) = -Inf", __imag__ result);
3619
3620   result = FUNC(casin) (BUILD_COMPLEX (0.0, nan_value));
3621   check ("real(casin(0 + i NaN)) = 0", __real__ result, 0.0);
3622   check_isnan ("imag(casin(0 + i NaN)) = NaN", __imag__ result);
3623   result = FUNC(casin) (BUILD_COMPLEX (minus_zero, nan_value));
3624   check ("real(casin(-0 + i NaN)) = -0", __real__ result, minus_zero);
3625   check_isnan ("imag(casin(-0 + i NaN)) = NaN", __imag__ result);
3626
3627   result = FUNC(casin) (BUILD_COMPLEX (plus_infty, nan_value));
3628   check_isnan ("real(casin(+Inf + i NaN)) = NaN", __real__ result);
3629   check_isinfp ("imag(casin(+Inf + i NaN)) = +-Inf",
3630                 FUNC(fabs) (__imag__ result));
3631   result = FUNC(casin) (BUILD_COMPLEX (minus_infty, nan_value));
3632   check_isnan ("real(casin(-Inf + i NaN)) = NaN", __real__ result);
3633   check_isinfp ("imag(casin(-Inf + NaN)) = +-Inf",
3634                 FUNC(fabs) (__imag__ result));
3635
3636   result = FUNC(casin) (BUILD_COMPLEX (nan_value, 10.5));
3637   check_isnan_maybe_exc ("real(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3638                          __real__ result, INVALID_EXCEPTION);
3639   check_isnan ("imag(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3640                __imag__ result);
3641   result = FUNC(casin) (BUILD_COMPLEX (nan_value, -10.5));
3642   check_isnan_maybe_exc ("real(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3643                          __real__ result, INVALID_EXCEPTION);
3644   check_isnan ("imag(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3645                __imag__ result);
3646
3647   result = FUNC(casin) (BUILD_COMPLEX (0.75, nan_value));
3648   check_isnan_maybe_exc ("real(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3649                          __real__ result, INVALID_EXCEPTION);
3650   check_isnan ("imag(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3651                __imag__ result);
3652   result = FUNC(casin) (BUILD_COMPLEX (-0.75, nan_value));
3653   check_isnan_maybe_exc ("real(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3654                          __real__ result, INVALID_EXCEPTION);
3655   check_isnan ("imag(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3656                __imag__ result);
3657
3658   result = FUNC(casin) (BUILD_COMPLEX (nan_value, nan_value));
3659   check_isnan ("real(casin(NaN + i NaN)) = NaN", __real__ result);
3660   check_isnan ("imag(casin(NaN + i NaN)) = NaN", __imag__ result);
3661 }
3662
3663
3664 static void
3665 casinh_test (void)
3666 {
3667   __complex__ MATHTYPE result;
3668
3669   result = FUNC(casinh) (BUILD_COMPLEX (0, 0));
3670   check ("real(casinh(0 + i0)) = 0", __real__ result, 0);
3671   check ("imag(casinh(0 + i0)) = 0", __imag__ result, 0);
3672   result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, 0));
3673   check ("real(casinh(-0 + i0)) = -0", __real__ result, minus_zero);
3674   check ("imag(casinh(-0 + i0)) = 0", __imag__ result, 0);
3675   result = FUNC(casinh) (BUILD_COMPLEX (0, minus_zero));
3676   check ("real(casinh(0 - i0)) = 0", __real__ result, 0);
3677   check ("imag(casinh(0 - i0)) = -0", __imag__ result, minus_zero);
3678   result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_zero));
3679   check ("real(casinh(-0 - i0)) = -0", __real__ result, minus_zero);
3680   check ("imag(casinh(-0 - i0)) = -0", __imag__ result, minus_zero);
3681
3682   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, plus_infty));
3683   check_isinfp ("real(casinh(+Inf + i Inf)) = +Inf", __real__ result);
3684   check ("imag(casinh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
3685   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_infty));
3686   check_isinfp ("real(casinh(+Inf - i Inf)) = +Inf", __real__ result);
3687   check ("imag(casinh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
3688   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, plus_infty));
3689   check_isinfn ("real(casinh(-Inf + i Inf)) = -Inf", __real__ result);
3690   check ("imag(casinh(-Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
3691   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_infty));
3692   check_isinfn ("real(casinh(-Inf - i Inf)) = -Inf", __real__ result);
3693   check ("imag(casinh(-Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
3694
3695   result = FUNC(casinh) (BUILD_COMPLEX (-10.0, plus_infty));
3696   check_isinfn ("real(casinh(-10.0 + i Inf)) = -Inf", __real__ result);
3697   check ("imag(casinh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3698   result = FUNC(casinh) (BUILD_COMPLEX (-10.0, minus_infty));
3699   check_isinfn ("real(casinh(-10.0 - i Inf)) = -Inf", __real__ result);
3700   check ("imag(casinh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3701   result = FUNC(casinh) (BUILD_COMPLEX (0, plus_infty));
3702   check_isinfp ("real(casinh(0 + i Inf)) = +Inf", __real__ result);
3703   check ("imag(casinh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3704   result = FUNC(casinh) (BUILD_COMPLEX (0, minus_infty));
3705   check_isinfp ("real(casinh(0 - i Inf)) = +Inf", __real__ result);
3706   check ("imag(casinh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3707   result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, plus_infty));
3708   check_isinfn ("real(casinh(-0 + i Inf)) = -Inf", __real__ result);
3709   check ("imag(casinh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3710   result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_infty));
3711   check_isinfn ("real(casinh(-0 - i Inf)) = -Inf", __real__ result);
3712   check ("imag(casinh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3713   result = FUNC(casinh) (BUILD_COMPLEX (0.1, plus_infty));
3714   check_isinfp ("real(casinh(0.1 + i Inf)) = +Inf", __real__ result);
3715   check ("imag(casinh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3716   result = FUNC(casinh) (BUILD_COMPLEX (0.1, minus_infty));
3717   check_isinfp ("real(casinh(0.1 - i Inf)) = +Inf", __real__ result);
3718   check ("imag(casinh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3719
3720   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 0));
3721   check_isinfn ("real(casinh(-Inf + i0)) = -Inf", __real__ result);
3722   check ("imag(casinh(-Inf + i0)) = 0", __imag__ result, 0);
3723   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_zero));
3724   check_isinfn ("real(casinh(-Inf - i0)) = -Inf", __real__ result);
3725   check ("imag(casinh(-Inf - i0)) = -0", __imag__ result, minus_zero);
3726   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 100));
3727   check_isinfn ("real(casinh(-Inf + i100)) = -Inf", __real__ result);
3728   check ("imag(casinh(-Inf + i100)) = 0", __imag__ result, 0);
3729   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, -100));
3730   check_isinfn ("real(casinh(-Inf - i100)) = -Inf", __real__ result);
3731   check ("imag(casinh(-Inf - i100)) = -0", __imag__ result, minus_zero);
3732
3733   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0));
3734   check_isinfp ("real(casinh(+Inf + i0)) = +Inf", __real__ result);
3735   check ("imag(casinh(+Inf + i0)) = 0", __imag__ result, 0);
3736   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_zero));
3737   check_isinfp ("real(casinh(+Inf - i0)) = +Inf", __real__ result);
3738   check ("imag(casinh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3739   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0.5));
3740   check_isinfp ("real(casinh(+Inf + i0.5)) = +Inf", __real__ result);
3741   check ("imag(casinh(+Inf + i0.5)) = 0", __imag__ result, 0);
3742   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, -0.5));
3743   check_isinfp ("real(casinh(+Inf - i0.5)) = +Inf", __real__ result);
3744   check ("imag(casinh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3745
3746   result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, nan_value));
3747   check_isinfp ("real(casinh(+Inf + i NaN)) = +Inf", __real__ result);
3748   check_isnan ("imag(casinh(+Inf + i NaN)) = NaN", __imag__ result);
3749   result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, nan_value));
3750   check_isinfn ("real(casinh(-Inf + i NaN)) = -Inf", __real__ result);
3751   check_isnan ("imag(casinh(-Inf + i NaN)) = NaN", __imag__ result);
3752
3753   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0));
3754   check_isnan ("real(casinh(NaN + i0)) = NaN", __real__ result);
3755   check ("imag(casinh(NaN + i0)) = 0", __imag__ result, 0);
3756   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_zero));
3757   check_isnan ("real(casinh(NaN - i0)) = NaN", __real__ result);
3758   check ("imag(casinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3759
3760   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, plus_infty));
3761   check_isinfp ("real(casinh(NaN + i Inf)) = +-Inf",
3762                 FUNC(fabs) (__real__ result));
3763   check_isnan ("imag(casinh(NaN + i Inf)) = NaN", __imag__ result);
3764   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_infty));
3765   check_isinfp ("real(casinh(NaN - i Inf)) = +-Inf",
3766                 FUNC(fabs) (__real__ result));
3767   check_isnan ("imag(casinh(NaN - i Inf)) = NaN", __imag__ result);
3768
3769   result = FUNC(casinh) (BUILD_COMPLEX (10.5, nan_value));
3770   check_isnan_maybe_exc ("real(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3771                          __real__ result, INVALID_EXCEPTION);
3772   check_isnan ("imag(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3773                __imag__ result);
3774   result = FUNC(casinh) (BUILD_COMPLEX (-10.5, nan_value));
3775   check_isnan_maybe_exc ("real(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3776                          __real__ result, INVALID_EXCEPTION);
3777   check_isnan ("imag(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3778                __imag__ result);
3779
3780   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0.75));
3781   check_isnan_maybe_exc ("real(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
3782                          __real__ result, INVALID_EXCEPTION);
3783   check_isnan ("imag(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
3784                __imag__ result);
3785   result = FUNC(casinh) (BUILD_COMPLEX (-0.75, nan_value));
3786   check_isnan_maybe_exc ("real(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
3787                          __real__ result, INVALID_EXCEPTION);
3788   check_isnan ("imag(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
3789                __imag__ result);
3790
3791   result = FUNC(casinh) (BUILD_COMPLEX (nan_value, nan_value));
3792   check_isnan ("real(casinh(NaN + i NaN)) = NaN", __real__ result);
3793   check_isnan ("imag(casinh(NaN + i NaN)) = NaN", __imag__ result);
3794 }
3795
3796
3797 static void
3798 catan_test (void)
3799 {
3800   __complex__ MATHTYPE result;
3801
3802   result = FUNC(catan) (BUILD_COMPLEX (0, 0));
3803   check ("real(catan(0 + i0)) = 0", __real__ result, 0);
3804   check ("imag(catan(0 + i0)) = 0", __imag__ result, 0);
3805   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, 0));
3806   check ("real(catan(-0 + i0)) = -0", __real__ result, minus_zero);
3807   check ("imag(catan(-0 + i0)) = 0", __imag__ result, 0);
3808   result = FUNC(catan) (BUILD_COMPLEX (0, minus_zero));
3809   check ("real(catan(0 - i0)) = 0", __real__ result, 0);
3810   check ("imag(catan(0 - i0)) = -0", __imag__ result, minus_zero);
3811   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_zero));
3812   check ("real(catan(-0 - i0)) = -0", __real__ result, minus_zero);
3813   check ("imag(catan(-0 - i0)) = -0", __imag__ result, minus_zero);
3814
3815   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, plus_infty));
3816   check ("real(catan(+Inf + i Inf)) = pi/2", __real__ result, M_PI_2);
3817   check ("imag(catan(+Inf + i Inf)) = 0", __imag__ result, 0);
3818   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_infty));
3819   check ("real(catan(+Inf - i Inf)) = pi/2", __real__ result, M_PI_2);
3820   check ("imag(catan(+Inf - i Inf)) = -0", __imag__ result, minus_zero);
3821   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, plus_infty));
3822   check ("real(catan(-Inf + i Inf)) = -pi/2", __real__ result, -M_PI_2);
3823   check ("imag(catan(-Inf + i Inf)) = 0", __imag__ result, 0.0);
3824   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_infty));
3825   check ("real(catan(-Inf - i Inf)) = -pi/2", __real__ result, -M_PI_2);
3826   check ("imag(catan(-Inf - i Inf)) = -0", __imag__ result, minus_zero);
3827
3828   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, -10.0));
3829   check ("real(catan(+Inf - i10.0)) = pi/2", __real__ result, M_PI_2);
3830   check ("imag(catan(+Inf - i10.0)) = -0", __imag__ result, minus_zero);
3831   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, -10.0));
3832   check ("real(catan(-Inf - i10.0)) = -pi/2", __real__ result, -M_PI_2);
3833   check ("imag(catan(-Inf - i10.0)) = -0", __imag__ result, minus_zero);
3834   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_zero));
3835   check ("real(catan(Inf - i0)) = pi/2", __real__ result, M_PI_2);
3836   check ("imag(catan(Inf - i0)) = -0", __imag__ result, minus_zero);
3837   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_zero));
3838   check ("real(catan(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2);
3839   check ("imag(catan(-Inf - i0)) = -0", __imag__ result, minus_zero);
3840   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.0));
3841   check ("real(catan(Inf + i0)) = pi/2", __real__ result, M_PI_2);
3842   check ("imag(catan(Inf + i0)) = 0", __imag__ result, 0.0);
3843   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.0));
3844   check ("real(catan(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2);
3845   check ("imag(catan(-Inf + i0)) = 0", __imag__ result, 0.0);
3846   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.1));
3847   check ("real(catan(+Inf + i0.1)) = pi/2", __real__ result, M_PI_2);
3848   check ("imag(catan(+Inf + i0.1)) = 0", __imag__ result, 0);
3849   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.1));
3850   check ("real(catan(-Inf + i0.1)) = -pi/2", __real__ result, -M_PI_2);
3851   check ("imag(catan(-Inf + i0.1)) = 0", __imag__ result, 0);
3852
3853   result = FUNC(catan) (BUILD_COMPLEX (0.0, minus_infty));
3854   check ("real(catan(0 - i Inf)) = pi/2", __real__ result, M_PI_2);
3855   check ("imag(catan(0 - i Inf)) = -0", __imag__ result, minus_zero);
3856   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_infty));
3857   check ("real(catan(-0 - i Inf)) = -pi/2", __real__ result, -M_PI_2);
3858   check ("imag(catan(-0 - i Inf)) = -0", __imag__ result, minus_zero);
3859   result = FUNC(catan) (BUILD_COMPLEX (100.0, minus_infty));
3860   check ("real(catan(100 - i Inf)) = pi/2", __real__ result, M_PI_2);
3861   check ("imag(catan(100 - i Inf)) = -0", __imag__ result, minus_zero);
3862   result = FUNC(catan) (BUILD_COMPLEX (-100.0, minus_infty));
3863   check ("real(catan(-100 - i Inf)) = -pi/2", __real__ result, -M_PI_2);
3864   check ("imag(catan(-100 - i Inf)) = -0", __imag__ result, minus_zero);
3865
3866   result = FUNC(catan) (BUILD_COMPLEX (0.0, plus_infty));
3867   check ("real(catan(0 + i Inf)) = pi/2", __real__ result, M_PI_2);
3868   check ("imag(catan(0 + i Inf)) = 0", __imag__ result, 0);
3869   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, plus_infty));
3870   check ("real(catan(-0 + i Inf)) = -pi/2", __real__ result, -M_PI_2);
3871   check ("imag(catan(-0 + i Inf)) = 0", __imag__ result, 0);
3872   result = FUNC(catan) (BUILD_COMPLEX (0.5, plus_infty));
3873   check ("real(catan(0.5 + i Inf)) = pi/2", __real__ result, M_PI_2);
3874   check ("imag(catan(0.5 + i Inf)) = 0", __imag__ result, 0);
3875   result = FUNC(catan) (BUILD_COMPLEX (-0.5, plus_infty));
3876   check ("real(catan(-0.5 + i Inf)) = -pi/2", __real__ result, -M_PI_2);
3877   check ("imag(catan(-0.5 + i Inf)) = 0", __imag__ result, 0);
3878
3879   result = FUNC(catan) (BUILD_COMPLEX (nan_value, 0.0));
3880   check_isnan ("real(catan(NaN + i0)) = NaN", __real__ result);
3881   check ("imag(catan(NaN + i0)) = 0", __imag__ result, 0.0);
3882   result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_zero));
3883   check_isnan ("real(catan(NaN - i0)) = NaN", __real__ result);
3884   check ("imag(catan(NaN - i0)) = -0", __imag__ result, minus_zero);
3885
3886   result = FUNC(catan) (BUILD_COMPLEX (nan_value, plus_infty));
3887   check_isnan ("real(catan(NaN + i Inf)) = NaN", __real__ result);
3888   check ("imag(catan(NaN + i Inf)) = 0", __imag__ result, 0);
3889   result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_infty));
3890   check_isnan ("real(catan(NaN - i Inf)) = NaN", __real__ result);
3891   check ("imag(catan(NaN - i Inf)) = -0", __imag__ result, minus_zero);
3892
3893   result = FUNC(catan) (BUILD_COMPLEX (0.0, nan_value));
3894   check_isnan ("real(catan(0 + i NaN)) = NaN", __real__ result);
3895   check_isnan ("imag(catan(0 + i NaN)) = NaN", __imag__ result);
3896   result = FUNC(catan) (BUILD_COMPLEX (minus_zero, nan_value));
3897   check_isnan ("real(catan(-0 + i NaN)) = NaN", __real__ result);
3898   check_isnan ("imag(catan(-0 + i NaN)) = NaN", __imag__ result);
3899
3900   result = FUNC(catan) (BUILD_COMPLEX (plus_infty, nan_value));
3901   check ("real(catan(+Inf + i NaN)) = pi/2", __real__ result, M_PI_2);
3902   check ("imag(catan(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3903   result = FUNC(catan) (BUILD_COMPLEX (minus_infty, nan_value));
3904   check ("real(catan(-Inf + i NaN)) = -pi/2", __real__ result, -M_PI_2);
3905   check ("imag(catan(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3906
3907   result = FUNC(catan) (BUILD_COMPLEX (nan_value, 10.5));
3908   check_isnan_maybe_exc ("real(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
3909                          __real__ result, INVALID_EXCEPTION);
3910   check_isnan ("imag(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
3911                __imag__ result);
3912   result = FUNC(catan) (BUILD_COMPLEX (nan_value, -10.5));
3913   check_isnan_maybe_exc ("real(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
3914                          __real__ result, INVALID_EXCEPTION);
3915   check_isnan ("imag(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
3916                __imag__ result);
3917
3918   result = FUNC(catan) (BUILD_COMPLEX (0.75, nan_value));
3919   check_isnan_maybe_exc ("real(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
3920                          __real__ result, INVALID_EXCEPTION);
3921   check_isnan ("imag(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
3922                __imag__ result);
3923   result = FUNC(catan) (BUILD_COMPLEX (-0.75, nan_value));
3924   check_isnan_maybe_exc ("real(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3925                          __real__ result, INVALID_EXCEPTION);
3926   check_isnan ("imag(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3927                __imag__ result);
3928
3929   result = FUNC(catan) (BUILD_COMPLEX (nan_value, nan_value));
3930   check_isnan ("real(catan(NaN + i NaN)) = NaN", __real__ result);
3931   check_isnan ("imag(catan(NaN + i NaN)) = NaN", __imag__ result);
3932 }
3933
3934
3935 static void
3936 catanh_test (void)
3937 {
3938   __complex__ MATHTYPE result;
3939
3940   result = FUNC(catanh) (BUILD_COMPLEX (0, 0));
3941   check ("real(catanh(0 + i0)) = 0", __real__ result, 0);
3942   check ("imag(catanh(0 + i0)) = 0", __imag__ result, 0);
3943   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, 0));
3944   check ("real(catanh(-0 + i0)) = -0", __real__ result, minus_zero);
3945   check ("imag(catanh(-0 + i0)) = 0", __imag__ result, 0);
3946   result = FUNC(catanh) (BUILD_COMPLEX (0, minus_zero));
3947   check ("real(catanh(0 - i0)) = 0", __real__ result, 0);
3948   check ("imag(catanh(0 - i0)) = -0", __imag__ result, minus_zero);
3949   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_zero));
3950   check ("real(catanh(-0 - i0)) = -0", __real__ result, minus_zero);
3951   check ("imag(catanh(-0 - i0)) = -0", __imag__ result, minus_zero);
3952
3953   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, plus_infty));
3954   check ("real(catanh(+Inf + i Inf)) = 0", __real__ result, 0);
3955   check ("imag(catanh(+Inf + i Inf)) = pi/2", __imag__ result, M_PI_2);
3956   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_infty));
3957   check ("real(catanh(+Inf - i Inf)) = 0", __real__ result, 0);
3958   check ("imag(catanh(+Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3959   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, plus_infty));
3960   check ("real(catanh(-Inf + i Inf)) = -0", __real__ result, minus_zero);
3961   check ("imag(catanh(-Inf + i Inf)) = pi/2", __imag__ result, M_PI_2);
3962   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_infty));
3963   check ("real(catanh(-Inf - i Inf)) = -0", __real__ result, minus_zero);
3964   check ("imag(catanh(-Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3965
3966   result = FUNC(catanh) (BUILD_COMPLEX (-10.0, plus_infty));
3967   check ("real(catanh(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
3968   check ("imag(catanh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3969   result = FUNC(catanh) (BUILD_COMPLEX (-10.0, minus_infty));
3970   check ("real(catanh(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
3971   check ("imag(catanh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3972   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, plus_infty));
3973   check ("real(catanh(-0 + i Inf)) = -0", __real__ result, minus_zero);
3974   check ("imag(catanh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3975   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_infty));
3976   check ("real(catanh(-0 - i Inf)) = -0", __real__ result, minus_zero);
3977   check ("imag(catanh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3978   result = FUNC(catanh) (BUILD_COMPLEX (0, plus_infty));
3979   check ("real(catanh(0 + i Inf)) = 0", __real__ result, 0);
3980   check ("imag(catanh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3981   result = FUNC(catanh) (BUILD_COMPLEX (0, minus_infty));
3982   check ("real(catanh(0 - i Inf)) = 0", __real__ result, 0);
3983   check ("imag(catanh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3984   result = FUNC(catanh) (BUILD_COMPLEX (0.1, plus_infty));
3985   check ("real(catanh(0.1 + i Inf)) = 0", __real__ result, 0);
3986   check ("imag(catanh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
3987   result = FUNC(catanh) (BUILD_COMPLEX (0.1, minus_infty));
3988   check ("real(catanh(0.1 - i Inf)) = 0", __real__ result, 0);
3989   check ("imag(catanh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
3990
3991   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 0));
3992   check ("real(catanh(-Inf + i0)) = -0", __real__ result, minus_zero);
3993   check ("imag(catanh(-Inf + i0)) = pi/2", __imag__ result, M_PI_2);
3994   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_zero));
3995   check ("real(catanh(-Inf - i0)) = -0", __real__ result, minus_zero);
3996   check ("imag(catanh(-Inf - i0)) = -pi/2", __imag__ result, -M_PI_2);
3997   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 100));
3998   check ("real(catanh(-Inf + i100)) = -0", __real__ result, minus_zero);
3999   check ("imag(catanh(-Inf + i100)) = pi/2", __imag__ result, M_PI_2);
4000   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, -100));
4001   check ("real(catanh(-Inf - i100)) = -0", __real__ result, minus_zero);
4002   check ("imag(catanh(-Inf - i100)) = -pi/2", __imag__ result, -M_PI_2);
4003
4004   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0));
4005   check ("real(catanh(+Inf + i0)) = 0", __real__ result, 0);
4006   check ("imag(catanh(+Inf + i0)) = pi/2", __imag__ result, M_PI_2);
4007   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4008   check ("real(catanh(+Inf - i0)) = 0", __real__ result, 0);
4009   check ("imag(catanh(+Inf - i0)) = -pi/2", __imag__ result, -M_PI_2);
4010   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0.5));
4011   check ("real(catanh(+Inf + i0.5)) = 0", __real__ result, 0);
4012   check ("imag(catanh(+Inf + i0.5)) = pi/2", __imag__ result, M_PI_2);
4013   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, -0.5));
4014   check ("real(catanh(+Inf - i0.5)) = 0", __real__ result, 0);
4015   check ("imag(catanh(+Inf - i0.5)) = -pi/2", __imag__ result, -M_PI_2);
4016
4017   result = FUNC(catanh) (BUILD_COMPLEX (0, nan_value));
4018   check ("real(catanh(0 + i NaN)) = 0", __real__ result, 0);
4019   check_isnan ("imag(catanh(0 + i NaN)) = NaN", __imag__ result);
4020   result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, nan_value));
4021   check ("real(catanh(-0 + i NaN)) = -0", __real__ result, minus_zero);
4022   check_isnan ("imag(catanh(-0 + i NaN)) = NaN", __imag__ result);
4023
4024   result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, nan_value));
4025   check ("real(catanh(+Inf + i NaN)) = 0", __real__ result, 0);
4026   check_isnan ("imag(catanh(+Inf + i NaN)) = NaN", __imag__ result);
4027   result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, nan_value));
4028   check ("real(catanh(-Inf + i NaN)) = -0", __real__ result, minus_zero);
4029   check_isnan ("imag(catanh(-Inf + i NaN)) = NaN", __imag__ result);
4030
4031   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0));
4032   check_isnan ("real(catanh(NaN + i0)) = NaN", __real__ result);
4033   check_isnan ("imag(catanh(NaN + i0)) = NaN", __imag__ result);
4034   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_zero));
4035   check_isnan ("real(catanh(NaN - i0)) = NaN", __real__ result);
4036   check_isnan ("imag(catanh(NaN - i0)) = NaN", __imag__ result);
4037
4038   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, plus_infty));
4039   check ("real(catanh(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4040   check ("imag(catanh(NaN + i Inf)) = pi/2", __imag__ result, M_PI_2);
4041   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_infty));
4042   check ("real(catanh(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4043   check ("imag(catanh(NaN - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4044
4045   result = FUNC(catanh) (BUILD_COMPLEX (10.5, nan_value));
4046   check_isnan_maybe_exc ("real(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4047                          __real__ result, INVALID_EXCEPTION);
4048   check_isnan ("imag(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4049                __imag__ result);
4050   result = FUNC(catanh) (BUILD_COMPLEX (-10.5, nan_value));
4051   check_isnan_maybe_exc ("real(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4052                          __real__ result, INVALID_EXCEPTION);
4053   check_isnan ("imag(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4054                __imag__ result);
4055
4056   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0.75));
4057   check_isnan_maybe_exc ("real(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4058                          __real__ result, INVALID_EXCEPTION);
4059   check_isnan ("imag(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4060                __imag__ result);
4061   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, -0.75));
4062   check_isnan_maybe_exc ("real(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4063                          __real__ result, INVALID_EXCEPTION);
4064   check_isnan ("imag(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4065                __imag__ result);
4066
4067   result = FUNC(catanh) (BUILD_COMPLEX (nan_value, nan_value));
4068   check_isnan ("real(catanh(NaN + i NaN)) = NaN", __real__ result);
4069   check_isnan ("imag(catanh(NaN + i NaN)) = NaN", __imag__ result);
4070 }
4071
4072
4073 static void
4074 ctan_test (void)
4075 {
4076   __complex__ MATHTYPE result;
4077
4078   result = FUNC(ctan) (BUILD_COMPLEX (0, 0));
4079   check ("real(ctan(0 + i0)) = 0", __real__ result, 0);
4080   check ("imag(ctan(0 + i0)) = 0", __imag__ result, 0);
4081   result = FUNC(ctan) (BUILD_COMPLEX (0, minus_zero));
4082   check ("real(ctan(0 - i0)) = 0", __real__ result, 0);
4083   check ("imag(ctan(0 - i0)) = -0", __imag__ result, minus_zero);
4084   result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, 0));
4085   check ("real(ctan(-0 + i0)) = -0", __real__ result, minus_zero);
4086   check ("imag(ctan(-0 + i0)) = 0", __imag__ result, 0);
4087   result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_zero));
4088   check ("real(ctan(-0 - i0)) = -0", __real__ result, minus_zero);
4089   check ("imag(ctan(-0 - i0)) = -0", __imag__ result, minus_zero);
4090
4091
4092   result = FUNC(ctan) (BUILD_COMPLEX (0, plus_infty));
4093   check ("real(ctan(0 + i Inf)) = 0", __real__ result, 0);
4094   check ("imag(ctan(0 + i Inf)) = 1", __imag__ result, 1);
4095   result = FUNC(ctan) (BUILD_COMPLEX (1, plus_infty));
4096   check ("real(ctan(1 + i Inf)) = 0", __real__ result, 0);
4097   check ("imag(ctan(1 + i Inf)) = 1", __imag__ result, 1);
4098   result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, plus_infty));
4099   check ("real(ctan(-0 + i Inf)) = -0", __real__ result, minus_zero);
4100   check ("imag(ctan(-0 + i Inf)) = 1", __imag__ result, 1);
4101   result = FUNC(ctan) (BUILD_COMPLEX (-1, plus_infty));
4102   check ("real(ctan(-1 + i Inf)) = -0", __real__ result, minus_zero);
4103   check ("imag(ctan(-1 + i Inf)) = 1", __imag__ result, 1);
4104
4105   result = FUNC(ctan) (BUILD_COMPLEX (0, minus_infty));
4106   check ("real(ctan(0 - i Inf)) = 0", __real__ result, 0);
4107   check ("imag(ctan(0 - i Inf)) = -1", __imag__ result, -1);
4108   result = FUNC(ctan) (BUILD_COMPLEX (1, minus_infty));
4109   check ("real(ctan(1 - i Inf)) = 0", __real__ result, 0);
4110   check ("imag(ctan(1 - i Inf)) = -1", __imag__ result, -1);
4111   result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_infty));
4112   check ("real(ctan(-0 - i Inf)) = -0", __real__ result, minus_zero);
4113   check ("imag(ctan(-0 - i Inf)) = -1", __imag__ result, -1);
4114   result = FUNC(ctan) (BUILD_COMPLEX (-1, minus_infty));
4115   check ("real(ctan(-1 - i Inf)) = -0", __real__ result, minus_zero);
4116   check ("imag(ctan(-1 - i Inf)) = -1", __imag__ result, -1);
4117
4118   result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 0));
4119   check_isnan_exc ("real(ctan(Inf + i 0)) = NaN plus invalid exception",
4120                    __real__ result, INVALID_EXCEPTION);
4121   check_isnan ("imag(ctan(Inf + i 0)) = NaN plus invalid exception",
4122                __imag__ result);
4123   result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 2));
4124   check_isnan_exc ("real(ctan(Inf + i 2)) = NaN plus invalid exception",
4125                    __real__ result, INVALID_EXCEPTION);
4126   check_isnan ("imag(ctan(Inf + i 2)) = NaN plus invalid exception",
4127                __imag__ result);
4128   result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 0));
4129   check_isnan_exc ("real(ctan(-Inf + i 0)) = NaN plus invalid exception",
4130                    __real__ result, INVALID_EXCEPTION);
4131   check_isnan ("imag(ctan(-Inf + i 0)) = NaN plus invalid exception",
4132                __imag__ result);
4133   result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 2));
4134   check_isnan_exc ("real(ctan(- Inf + i 2)) = NaN plus invalid exception",
4135                    __real__ result, INVALID_EXCEPTION);
4136   check_isnan ("imag(ctan(- Inf + i 2)) = NaN plus invalid exception",
4137                __imag__ result);
4138   result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, minus_zero));
4139   check_isnan_exc ("real(ctan(Inf - i 0)) = NaN plus invalid exception",
4140                    __real__ result, INVALID_EXCEPTION);
4141   check_isnan ("imag(ctan(Inf - i 0)) = NaN plus invalid exception",
4142                __imag__ result);
4143   result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, -2));
4144   check_isnan_exc ("real(ctan(Inf - i 2)) = NaN plus invalid exception",
4145                    __real__ result, INVALID_EXCEPTION);
4146   check_isnan ("imag(ctan(Inf - i 2)) = NaN plus invalid exception",
4147                __imag__ result);
4148   result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, minus_zero));
4149   check_isnan_exc ("real(ctan(-Inf - i 0)) = NaN plus invalid exception",
4150                    __real__ result, INVALID_EXCEPTION);
4151   check_isnan ("imag(ctan(-Inf - i 0)) = NaN plus invalid exception",
4152                __imag__ result);
4153   result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, -2));
4154   check_isnan_exc ("real(ctan(-Inf - i 2)) = NaN plus invalid exception",
4155                    __real__ result, INVALID_EXCEPTION);
4156   check_isnan ("imag(ctan(-Inf - i 2)) = NaN plus invalid exception",
4157                __imag__ result);
4158
4159   result = FUNC(ctan) (BUILD_COMPLEX (nan_value, plus_infty));
4160   check ("real(ctan(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4161   check ("imag(ctan(NaN + i Inf)) = 1", __imag__ result, 1);
4162   result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_infty));
4163   check ("real(ctan(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4164   check ("imag(ctan(NaN - i Inf)) = -1", __imag__ result, -1);
4165
4166   result = FUNC(ctan) (BUILD_COMPLEX (0, nan_value));
4167   check ("real(ctan(0 + i NaN)) = 0", __real__ result, 0);
4168   check_isnan ("imag(ctan(0 + i NaN)) = NaN", __imag__ result);
4169   result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, nan_value));
4170   check ("real(ctan(-0 + i NaN)) = -0", __real__ result, minus_zero);
4171   check_isnan ("imag(ctan(-0 + i NaN)) = NaN", __imag__ result);
4172
4173   result = FUNC(ctan) (BUILD_COMPLEX (0.5, nan_value));
4174   check_isnan_maybe_exc ("real(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4175                          __real__ result, INVALID_EXCEPTION);
4176   check_isnan ("imag(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4177                __imag__ result);
4178   result = FUNC(ctan) (BUILD_COMPLEX (-4.5, nan_value));
4179   check_isnan_maybe_exc ("real(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4180                          __real__ result, INVALID_EXCEPTION);
4181   check_isnan ("imag(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4182                __imag__ result);
4183
4184   result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 0));
4185   check_isnan_maybe_exc ("real(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4186                          __real__ result, INVALID_EXCEPTION);
4187   check_isnan ("imag(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4188                __imag__ result);
4189   result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 5));
4190   check_isnan_maybe_exc ("real(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4191                          __real__ result, INVALID_EXCEPTION);
4192   check_isnan ("imag(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4193                __imag__ result);
4194   result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_zero));
4195   check_isnan_maybe_exc ("real(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4196                          __real__ result, INVALID_EXCEPTION);
4197   check_isnan ("imag(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4198                __imag__ result);
4199   result = FUNC(ctan) (BUILD_COMPLEX (nan_value, -0.25));
4200   check_isnan_maybe_exc ("real(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4201                          __real__ result, INVALID_EXCEPTION);
4202   check_isnan ("imag(ctanh(NaN -i 0.25)) = NaN plus maybe invalid exception",
4203                __imag__ result);
4204
4205   result = FUNC(ctan) (BUILD_COMPLEX (nan_value, nan_value));
4206   check_isnan ("real(ctan(NaN + i NaN)) = NaN", __real__ result);
4207   check_isnan ("imag(ctan(NaN + i NaN)) = NaN", __imag__ result);
4208
4209 }
4210
4211
4212 static void
4213 ctanh_test (void)
4214 {
4215   __complex__ MATHTYPE result;
4216
4217   result = FUNC(ctanh) (BUILD_COMPLEX (0, 0));
4218   check ("real(ctanh(0 + i0)) = 0", __real__ result, 0);
4219   check ("imag(ctanh(0 + i0)) = 0", __imag__ result, 0);
4220   result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_zero));
4221   check ("real(ctanh(0 - i0)) = 0", __real__ result, 0);
4222   check ("imag(ctanh(0 - i0)) = -0", __imag__ result, minus_zero);
4223   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, 0));
4224   check ("real(ctanh(-0 + i0)) = -0", __real__ result, minus_zero);
4225   check ("imag(ctanh(-0 + i0)) = 0", __imag__ result, 0);
4226   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4227   check ("real(ctanh(-0 - i0)) = -0", __real__ result, minus_zero);
4228   check ("imag(ctanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4229
4230   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 0));
4231   check ("real(ctanh(+Inf + i0)) = 1", __real__ result, 1);
4232   check ("imag(ctanh(+Inf + i0)) = 0", __imag__ result, 0);
4233   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 1));
4234   check ("real(ctanh(+Inf + i1)) = 1", __real__ result, 1);
4235   check ("imag(ctanh(+Inf + i1)) = 0", __imag__ result, 0);
4236   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4237   check ("real(ctanh(+Inf - i0)) = 1", __real__ result, 1);
4238   check ("imag(ctanh(+Inf - i0)) = -0", __imag__ result, minus_zero);
4239   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, -1));
4240   check ("real(ctanh(+Inf - i1)) = 1", __real__ result, 1);
4241   check ("imag(ctanh(+Inf - i1)) = -0", __imag__ result, minus_zero);
4242   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 0));
4243   check ("real(ctanh(-Inf + i0)) = -1", __real__ result, -1);
4244   check ("imag(ctanh(-Inf + i0)) = 0", __imag__ result, 0);
4245   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 1));
4246   check ("real(ctanh(-Inf + i1)) = -1", __real__ result, -1);
4247   check ("imag(ctanh(-Inf + i1)) = 0", __imag__ result, 0);
4248   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4249   check ("real(ctanh(-Inf - i0)) = -1", __real__ result, -1);
4250   check ("imag(ctanh(-Inf - i0)) = -0", __imag__ result, minus_zero);
4251   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, -1));
4252   check ("real(ctanh(-Inf - i1)) = -1", __real__ result, -1);
4253   check ("imag(ctanh(-Inf - i1)) = -0", __imag__ result, minus_zero);
4254
4255   result = FUNC(ctanh) (BUILD_COMPLEX (0, plus_infty));
4256   check_isnan_exc ("real(ctanh(0 + i Inf)) = NaN plus invalid exception",
4257                    __real__ result, INVALID_EXCEPTION);
4258   check_isnan ("imag(ctanh(0 + i Inf)) = NaN plus invalid exception",
4259                __imag__ result);
4260   result = FUNC(ctanh) (BUILD_COMPLEX (2, plus_infty));
4261   check_isnan_exc ("real(ctanh(2 + i Inf)) = NaN plus invalid exception",
4262                    __real__ result, INVALID_EXCEPTION);
4263   check_isnan ("imag(ctanh(2 + i Inf)) = NaN plus invalid exception",
4264                __imag__ result);
4265   result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_infty));
4266   check_isnan_exc ("real(ctanh(0 - i Inf)) = NaN plus invalid exception",
4267                    __real__ result, INVALID_EXCEPTION);
4268   check_isnan ("imag(ctanh(0 - i Inf)) = NaN plus invalid exception",
4269                __imag__ result);
4270   result = FUNC(ctanh) (BUILD_COMPLEX (2, minus_infty));
4271   check_isnan_exc ("real(ctanh(2 - i Inf)) = NaN plus invalid exception",
4272                    __real__ result, INVALID_EXCEPTION);
4273   check_isnan ("imag(ctanh(2 - i Inf)) = NaN plus invalid exception",
4274                __imag__ result);
4275   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4276   check_isnan_exc ("real(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4277                    __real__ result, INVALID_EXCEPTION);
4278   check_isnan ("imag(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4279                __imag__ result);
4280   result = FUNC(ctanh) (BUILD_COMPLEX (-2, plus_infty));
4281   check_isnan_exc ("real(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4282                    __real__ result, INVALID_EXCEPTION);
4283   check_isnan ("imag(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4284                __imag__ result);
4285   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4286   check_isnan_exc ("real(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4287                    __real__ result, INVALID_EXCEPTION);
4288   check_isnan ("imag(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4289                __imag__ result);
4290   result = FUNC(ctanh) (BUILD_COMPLEX (-2, minus_infty));
4291   check_isnan_exc ("real(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4292                    __real__ result, INVALID_EXCEPTION);
4293   check_isnan ("imag(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4294                __imag__ result);
4295
4296   result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, nan_value));
4297   check ("real(ctanh(+Inf + i NaN)) = 1", __real__ result, 1);
4298   check ("imag(ctanh(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4299   result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, nan_value));
4300   check ("real(ctanh(-Inf + i NaN)) = -1", __real__ result, -1);
4301   check ("imag(ctanh(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4302
4303   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0));
4304   check_isnan ("real(ctanh(NaN + i0)) = NaN", __real__ result);
4305   check ("imag(ctanh(NaN + i0)) = 0", __imag__ result, 0);
4306   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, minus_zero));
4307   check_isnan ("real(ctanh(NaN - i0)) = NaN", __real__ result);
4308   check ("imag(ctanh(NaN - i0)) = -0", __imag__ result, minus_zero);
4309
4310   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0.5));
4311   check_isnan_maybe_exc ("real(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4312                          __real__ result, INVALID_EXCEPTION);
4313   check_isnan ("imag(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4314                __imag__ result);
4315   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, -4.5));
4316   check_isnan_maybe_exc ("real(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4317                          __real__ result, INVALID_EXCEPTION);
4318   check_isnan ("imag(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4319                __imag__ result);
4320
4321   result = FUNC(ctanh) (BUILD_COMPLEX (0, nan_value));
4322   check_isnan_maybe_exc ("real(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4323                          __real__ result, INVALID_EXCEPTION);
4324   check_isnan ("imag(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4325                __imag__ result);
4326   result = FUNC(ctanh) (BUILD_COMPLEX (5, nan_value));
4327   check_isnan_maybe_exc ("real(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4328                          __real__ result, INVALID_EXCEPTION);
4329   check_isnan ("imag(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4330                __imag__ result);
4331   result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, nan_value));
4332   check_isnan_maybe_exc ("real(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4333                          __real__ result, INVALID_EXCEPTION);
4334   check_isnan ("imag(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4335                __imag__ result);
4336   result = FUNC(ctanh) (BUILD_COMPLEX (-0.25, nan_value));
4337   check_isnan_maybe_exc ("real(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4338                          __real__ result, INVALID_EXCEPTION);
4339   check_isnan ("imag(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4340                __imag__ result);
4341
4342   result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, nan_value));
4343   check_isnan ("real(ctanh(NaN + i NaN)) = NaN", __real__ result);
4344   check_isnan ("imag(ctanh(NaN + i NaN)) = NaN", __imag__ result);
4345
4346   result = FUNC(ctanh) (BUILD_COMPLEX (0, M_PI_4));
4347   check ("real(ctanh (0 + i pi/4)) == 0", __real__ result, 0);
4348   check_eps ("imag(ctanh (0 + i pi/4)) == 1", __imag__ result, 1,
4349              CHOOSE (0, 0, 2e-7));
4350 }
4351
4352
4353 static void
4354 clog_test (void)
4355 {
4356   __complex__ MATHTYPE result;
4357
4358   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, 0));
4359   check_isinfn_exc ("real(clog(-0 + i0)) = -Inf plus divide-by-zero exception",
4360                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4361   check ("imag(clog(-0 + i0)) = pi plus divide-by-zero exception",
4362          __imag__ result, M_PI);
4363   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_zero));
4364   check_isinfn_exc ("real(clog(-0 - i0)) = -Inf plus divide-by-zero exception",
4365                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4366   check ("imag(clog(-0 - i0)) = -pi plus divide-by-zero exception",
4367          __imag__ result, -M_PI);
4368
4369   result = FUNC(clog) (BUILD_COMPLEX (0, 0));
4370   check_isinfn_exc ("real(clog(0 + i0)) = -Inf plus divide-by-zero exception",
4371                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4372   check ("imag(clog(0 + i0)) = 0 plus divide-by-zero exception",
4373          __imag__ result, 0);
4374   result = FUNC(clog) (BUILD_COMPLEX (0, minus_zero));
4375   check_isinfn_exc ("real(clog(0 - i0)) = -Inf plus divide-by-zero exception",
4376                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4377   check ("imag(clog(0 - i0)) = -0 plus divide-by-zero exception",
4378          __imag__ result, minus_zero);
4379
4380   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, plus_infty));
4381   check_isinfp ("real(clog(-Inf + i Inf)) = +Inf", __real__ result);
4382   check ("imag(clog(-Inf + i Inf)) = 3*pi/4", __imag__ result, M_PI - M_PI_4);
4383   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_infty));
4384   check_isinfp ("real(clog(-Inf - i Inf)) = +Inf", __real__ result);
4385   check ("imag(clog(-Inf - i Inf)) = -3*pi/4", __imag__ result, M_PI_4 - M_PI);
4386
4387   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, plus_infty));
4388   check_isinfp ("real(clog(+Inf + i Inf)) = +Inf", __real__ result);
4389   check ("imag(clog(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
4390   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_infty));
4391   check_isinfp ("real(clog(+Inf - i Inf)) = +Inf", __real__ result);
4392   check ("imag(clog(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
4393
4394   result = FUNC(clog) (BUILD_COMPLEX (0, plus_infty));
4395   check_isinfp ("real(clog(0 + i Inf)) = +Inf", __real__ result);
4396   check ("imag(clog(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
4397   result = FUNC(clog) (BUILD_COMPLEX (3, plus_infty));
4398   check_isinfp ("real(clog(3 + i Inf)) = +Inf", __real__ result);
4399   check ("imag(clog(3 + i Inf)) = pi/2", __imag__ result, M_PI_2);
4400   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, plus_infty));
4401   check_isinfp ("real(clog(-0 + i Inf)) = +Inf", __real__ result);
4402   check ("imag(clog(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
4403   result = FUNC(clog) (BUILD_COMPLEX (-3, plus_infty));
4404   check_isinfp ("real(clog(-3 + i Inf)) = +Inf", __real__ result);
4405   check ("imag(clog(-3 + i Inf)) = pi/2", __imag__ result, M_PI_2);
4406   result = FUNC(clog) (BUILD_COMPLEX (0, minus_infty));
4407   check_isinfp ("real(clog(0 - i Inf)) = +Inf", __real__ result);
4408   check ("imag(clog(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4409   result = FUNC(clog) (BUILD_COMPLEX (3, minus_infty));
4410   check_isinfp ("real(clog(3 - i Inf)) = +Inf", __real__ result);
4411   check ("imag(clog(3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4412   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_infty));
4413   check_isinfp ("real(clog(-0 - i Inf)) = +Inf", __real__ result);
4414   check ("imag(clog(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4415   result = FUNC(clog) (BUILD_COMPLEX (-3, minus_infty));
4416   check_isinfp ("real(clog(-3 - i Inf)) = +Inf", __real__ result);
4417   check ("imag(clog(-3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4418
4419   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 0));
4420   check_isinfp ("real(clog(-Inf + i0)) = +Inf", __real__ result);
4421   check ("imag(clog(-Inf + i0)) = pi", __imag__ result, M_PI);
4422   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 1));
4423   check_isinfp ("real(clog(-Inf + i1)) = +Inf", __real__ result);
4424   check ("imag(clog(-Inf + i1)) = pi", __imag__ result, M_PI);
4425   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_zero));
4426   check_isinfp ("real(clog(-Inf - i0)) = +Inf", __real__ result);
4427   check ("imag(clog(-Inf - i0)) = -pi", __imag__ result, -M_PI);
4428   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, -1));
4429   check_isinfp ("real(clog(-Inf - i1)) = +Inf", __real__ result);
4430   check ("imag(clog(-Inf - i1)) = -pi", __imag__ result, -M_PI);
4431
4432   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 0));
4433   check_isinfp ("real(clog(+Inf + i0)) = +Inf", __real__ result);
4434   check ("imag(clog(+Inf + i0)) = 0", __imag__ result, 0);
4435   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 1));
4436   check_isinfp ("real(clog(+Inf + i1)) = +Inf", __real__ result);
4437   check ("imag(clog(+Inf + i1)) = 0", __imag__ result, 0);
4438   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_zero));
4439   check_isinfp ("real(clog(+Inf - i0)) = +Inf", __real__ result);
4440   check ("imag(clog(+Inf - i0)) = -0", __imag__ result, minus_zero);
4441   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, -1));
4442   check_isinfp ("real(clog(+Inf - i1)) = +Inf", __real__ result);
4443   check ("imag(clog(+Inf - i1)) = -0", __imag__ result, minus_zero);
4444
4445   result = FUNC(clog) (BUILD_COMPLEX (plus_infty, nan_value));
4446   check_isinfp ("real(clog(+Inf + i NaN)) = +Inf", __real__ result);
4447   check_isnan ("imag(clog(+Inf + i NaN)) = NaN", __imag__ result);
4448   result = FUNC(clog) (BUILD_COMPLEX (minus_infty, nan_value));
4449   check_isinfp ("real(clog(-Inf + i NaN)) = +Inf", __real__ result);
4450   check_isnan ("imag(clog(-Inf + i NaN)) = NaN", __imag__ result);
4451
4452   result = FUNC(clog) (BUILD_COMPLEX (nan_value, plus_infty));
4453   check_isinfp ("real(clog(NaN + i Inf)) = +Inf", __real__ result);
4454   check_isnan ("imag(clog(NaN + i Inf)) = NaN", __imag__ result);
4455   result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_infty));
4456   check_isinfp ("real(clog(NaN - i Inf)) = +Inf", __real__ result);
4457   check_isnan ("imag(clog(NaN - i Inf)) = NaN", __imag__ result);
4458
4459   result = FUNC(clog) (BUILD_COMPLEX (0, nan_value));
4460   check_isnan_maybe_exc ("real(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4461                          __real__ result, INVALID_EXCEPTION);
4462   check_isnan ("imag(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4463                __imag__ result);
4464   result = FUNC(clog) (BUILD_COMPLEX (3, nan_value));
4465   check_isnan_maybe_exc ("real(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4466                          __real__ result, INVALID_EXCEPTION);
4467   check_isnan ("imag(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4468                __imag__ result);
4469   result = FUNC(clog) (BUILD_COMPLEX (minus_zero, nan_value));
4470   check_isnan_maybe_exc ("real(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4471                          __real__ result, INVALID_EXCEPTION);
4472   check_isnan ("imag(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4473                __imag__ result);
4474   result = FUNC(clog) (BUILD_COMPLEX (-3, nan_value));
4475   check_isnan_maybe_exc ("real(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4476                          __real__ result, INVALID_EXCEPTION);
4477   check_isnan ("imag(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4478                __imag__ result);
4479
4480   result = FUNC(clog) (BUILD_COMPLEX (nan_value, 0));
4481   check_isnan_maybe_exc ("real(clog(NaN + i0)) = NaN plus maybe invalid exception",
4482                          __real__ result, INVALID_EXCEPTION);
4483   check_isnan ("imag(clog(NaN + i0)) = NaN plus maybe invalid exception",
4484                __imag__ result);
4485   result = FUNC(clog) (BUILD_COMPLEX (nan_value, 5));
4486   check_isnan_maybe_exc ("real(clog(NaN + i5)) = NaN plus maybe invalid exception",
4487                          __real__ result, INVALID_EXCEPTION);
4488   check_isnan ("imag(clog(NaN + i5)) = NaN plus maybe invalid exception",
4489                __imag__ result);
4490   result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_zero));
4491   check_isnan_maybe_exc ("real(clog(NaN - i0)) = NaN plus maybe invalid exception",
4492                          __real__ result, INVALID_EXCEPTION);
4493   check_isnan ("imag(clog(NaN - i0)) = NaN plus maybe invalid exception",
4494                __imag__ result);
4495   result = FUNC(clog) (BUILD_COMPLEX (nan_value, -5));
4496   check_isnan_maybe_exc ("real(clog(NaN - i5)) = NaN plus maybe invalid exception",
4497                          __real__ result, INVALID_EXCEPTION);
4498   check_isnan ("imag(clog(NaN - i5)) = NaN plus maybe invalid exception",
4499                __imag__ result);
4500
4501   result = FUNC(clog) (BUILD_COMPLEX (nan_value, nan_value));
4502   check_isnan ("real(clog(NaN + i NaN)) = NaN", __real__ result);
4503   check_isnan ("imag(clog(NaN + i NaN)) = NaN", __imag__ result);
4504 }
4505
4506
4507 static void
4508 clog10_test (void)
4509 {
4510   __complex__ MATHTYPE result;
4511
4512   result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, 0));
4513   check_isinfn_exc ("real(clog10(-0 + i0)) = -Inf plus divide-by-zero exception",
4514                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4515   check ("imag(clog10(-0 + i0)) = pi plus divide-by-zero exception",
4516          __imag__ result, M_PI);
4517   result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_zero));
4518   check_isinfn_exc ("real(clog10(-0 - i0)) = -Inf plus divide-by-zero exception",
4519                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4520   check ("imag(clog10(-0 - i0)) = -pi plus divide-by-zero exception",
4521          __imag__ result, -M_PI);
4522
4523   result = FUNC(clog10) (BUILD_COMPLEX (0, 0));
4524   check_isinfn_exc ("real(clog10(0 + i0)) = -Inf plus divide-by-zero exception",
4525                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4526   check ("imag(clog10(0 + i0)) = 0 plus divide-by-zero exception",
4527          __imag__ result, 0);
4528   result = FUNC(clog10) (BUILD_COMPLEX (0, minus_zero));
4529   check_isinfn_exc ("real(clog10(0 - i0)) = -Inf plus divide-by-zero exception",
4530                     __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4531   check ("imag(clog10(0 - i0)) = -0 plus divide-by-zero exception",
4532          __imag__ result, minus_zero);
4533
4534   result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, plus_infty));
4535   check_isinfp ("real(clog10(-Inf + i Inf)) = +Inf", __real__ result);
4536   check ("imag(clog10(-Inf + i Inf)) = 3*pi/4", __imag__ result, M_PI - M_PI_4);
4537   result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_infty));
4538   check_isinfp ("real(clog10(-Inf - i Inf)) = +Inf", __real__ result);
4539   check ("imag(clog10(-Inf - i Inf)) = -3*pi/4", __imag__ result, M_PI_4 - M_PI);
4540
4541   result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, plus_infty));
4542   check_isinfp ("real(clog10(+Inf + i Inf)) = +Inf", __real__ result);
4543   check ("imag(clog10(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
4544   result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_infty));
4545   check_isinfp ("real(clog10(+Inf - i Inf)) = +Inf", __real__ result);
4546   check ("imag(clog10(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
4547
4548   result = FUNC(clog10) (BUILD_COMPLEX (0, plus_infty));
4549   check_isinfp ("real(clog10(0 + i Inf)) = +Inf", __real__ result);
4550   check ("imag(clog10(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
4551   result = FUNC(clog10) (BUILD_COMPLEX (3, plus_infty));
4552   check_isinfp ("real(clog10(3 + i Inf)) = +Inf", __real__ result);
4553   check ("imag(clog10(3 + i Inf)) = pi/2", __imag__ result, M_PI_2);
4554   result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, plus_infty));
4555   check_isinfp ("real(clog10(-0 + i Inf)) = +Inf", __real__ result);
4556   check ("imag(clog10(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
4557   result = FUNC(clog10) (BUILD_COMPLEX (-3, plus_infty));
4558   check_isinfp ("real(clog10(-3 + i Inf)) = +Inf", __real__ result);
4559   check ("imag(clog10(-3 + i Inf)) = pi/2", __imag__ result, M_PI_2);
4560   result = FUNC(clog10) (BUILD_COMPLEX (0, minus_infty));
4561   check_isinfp ("real(clog10(0 - i Inf)) = +Inf", __real__ result);
4562   check ("imag(clog10(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4563   result = FUNC(clog10) (BUILD_COMPLEX (3, minus_infty));
4564   check_isinfp ("real(clog10(3 - i Inf)) = +Inf", __real__ result);
4565   check ("imag(clog10(3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4566   result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_infty));
4567   check_isinfp ("real(clog10(-0 - i Inf)) = +Inf", __real__ result);
4568   check ("imag(clog10(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4569   result = FUNC(clog10) (BUILD_COMPLEX (-3, minus_infty));
4570   check_isinfp ("real(clog10(-3 - i Inf)) = +Inf", __real__ result);
4571   check ("imag(clog10(-3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
4572
4573   result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 0));
4574   check_isinfp ("real(clog10(-Inf + i0)) = +Inf", __real__ result);
4575   check ("imag(clog10(-Inf + i0)) = pi", __imag__ result, M_PI);
4576   result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 1));
4577   check_isinfp ("real(clog10(-Inf + i1)) = +Inf", __real__ result);
4578   check ("imag(clog10(-Inf + i1)) = pi", __imag__ result, M_PI);
4579   result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_zero));
4580   check_isinfp ("real(clog10(-Inf - i0)) = +Inf", __real__ result);
4581   check ("imag(clog10(-Inf - i0)) = -pi", __imag__ result, -M_PI);
4582   result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, -1));
4583   check_isinfp ("real(clog10(-Inf - i1)) = +Inf", __real__ result);
4584   check ("imag(clog10(-Inf - i1)) = -pi", __imag__ result, -M_PI);
4585
4586   result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 0));
4587   check_isinfp ("real(clog10(+Inf + i0)) = +Inf", __real__ result);
4588   check ("imag(clog10(+Inf + i0)) = 0", __imag__ result, 0);
4589   result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 1));
4590   check_isinfp ("real(clog10(+Inf + i1)) = +Inf", __real__ result);
4591   check ("imag(clog10(+Inf + i1)) = 0", __imag__ result, 0);
4592   result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_zero));
4593   check_isinfp ("real(clog10(+Inf - i0)) = +Inf", __real__ result);
4594   check ("imag(clog10(+Inf - i0)) = -0", __imag__ result, minus_zero);
4595   result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, -1));
4596   check_isinfp ("real(clog10(+Inf - i1)) = +Inf", __real__ result);
4597   check ("imag(clog10(+Inf - i1)) = -0", __imag__ result, minus_zero);
4598
4599   result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, nan_value));
4600   check_isinfp ("real(clog10(+Inf + i NaN)) = +Inf", __real__ result);
4601   check_isnan ("imag(clog10(+Inf + i NaN)) = NaN", __imag__ result);
4602   result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, nan_value));
4603   check_isinfp ("real(clog10(-Inf + i NaN)) = +Inf", __real__ result);
4604   check_isnan ("imag(clog10(-Inf + i NaN)) = NaN", __imag__ result);
4605
4606   result = FUNC(clog10) (BUILD_COMPLEX (nan_value, plus_infty));
4607   check_isinfp ("real(clog10(NaN + i Inf)) = +Inf", __real__ result);
4608   check_isnan ("imag(clog10(NaN + i Inf)) = NaN", __imag__ result);
4609   result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_infty));
4610   check_isinfp ("real(clog10(NaN - i Inf)) = +Inf", __real__ result);
4611   check_isnan ("imag(clog10(NaN - i Inf)) = NaN", __imag__ result);
4612
4613   result = FUNC(clog10) (BUILD_COMPLEX (0, nan_value));
4614   check_isnan_maybe_exc ("real(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4615                          __real__ result, INVALID_EXCEPTION);
4616   check_isnan ("imag(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4617                __imag__ result);
4618   result = FUNC(clog10) (BUILD_COMPLEX (3, nan_value));
4619   check_isnan_maybe_exc ("real(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4620                          __real__ result, INVALID_EXCEPTION);
4621   check_isnan ("imag(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4622                __imag__ result);
4623   result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, nan_value));
4624   check_isnan_maybe_exc ("real(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4625                          __real__ result, INVALID_EXCEPTION);
4626   check_isnan ("imag(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4627                __imag__ result);
4628   result = FUNC(clog10) (BUILD_COMPLEX (-3, nan_value));
4629   check_isnan_maybe_exc ("real(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4630                          __real__ result, INVALID_EXCEPTION);
4631   check_isnan ("imag(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4632                __imag__ result);
4633
4634   result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 0));
4635   check_isnan_maybe_exc ("real(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4636                          __real__ result, INVALID_EXCEPTION);
4637   check_isnan ("imag(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4638                __imag__ result);
4639   result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 5));
4640   check_isnan_maybe_exc ("real(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4641                          __real__ result, INVALID_EXCEPTION);
4642   check_isnan ("imag(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4643                __imag__ result);
4644   result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_zero));
4645   check_isnan_maybe_exc ("real(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4646                          __real__ result, INVALID_EXCEPTION);
4647   check_isnan ("imag(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4648                __imag__ result);
4649   result = FUNC(clog10) (BUILD_COMPLEX (nan_value, -5));
4650   check_isnan_maybe_exc ("real(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4651                          __real__ result, INVALID_EXCEPTION);
4652   check_isnan ("imag(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4653                __imag__ result);
4654
4655   result = FUNC(clog10) (BUILD_COMPLEX (nan_value, nan_value));
4656   check_isnan ("real(clog10(NaN + i NaN)) = NaN", __real__ result);
4657   check_isnan ("imag(clog10(NaN + i NaN)) = NaN", __imag__ result);
4658 }
4659
4660
4661 static void
4662 csqrt_test (void)
4663 {
4664   __complex__ MATHTYPE result;
4665
4666   result = FUNC(csqrt) (BUILD_COMPLEX (0, 0));
4667   check ("real(csqrt(0 + i0)) = 0", __real__ result, 0);
4668   check ("imag(csqrt(0 + i0)) = 0", __imag__ result, 0);
4669   result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_zero));
4670   check ("real(csqrt(0 - i0)) = 0", __real__ result, 0);
4671   check ("imag(csqrt(0 - i0)) = -0", __imag__ result, minus_zero);
4672   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, 0));
4673   check ("real(csqrt(-0 + i0)) = 0", __real__ result, 0);
4674   check ("imag(csqrt(-0 + i0)) = 0", __imag__ result, 0);
4675   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_zero));
4676   check ("real(csqrt(-0 - i0)) = 0", __real__ result, 0);
4677   check ("imag(csqrt(-0 - i0)) = -0", __imag__ result, minus_zero);
4678
4679   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 0));
4680   check ("real(csqrt(-Inf + i0)) = 0", __real__ result, 0);
4681   check_isinfp ("imag(csqrt(-Inf + i0)) = +Inf", __imag__ result);
4682   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 6));
4683   check ("real(csqrt(-Inf + i6)) = 0", __real__ result, 0);
4684   check_isinfp ("imag(csqrt(-Inf + i6)) = +Inf", __imag__ result);
4685   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_zero));
4686   check ("real(csqrt(-Inf - i0)) = 0", __real__ result, 0);
4687   check_isinfn ("imag(csqrt(-Inf - i0)) = -Inf", __imag__ result);
4688   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, -6));
4689   check ("real(csqrt(-Inf - i6)) = 0", __real__ result, 0);
4690   check_isinfn ("imag(csqrt(-Inf - i6)) = -Inf", __imag__ result);
4691
4692   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 0));
4693   check_isinfp ("real(csqrt(+Inf + i0)) = +Inf", __real__ result);
4694   check ("imag(csqrt(+Inf + i0)) = 0", __imag__ result, 0);
4695   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 6));
4696   check_isinfp ("real(csqrt(+Inf + i6)) = +Inf", __real__ result);
4697   check ("imag(csqrt(+Inf + i6)) = 0", __imag__ result, 0);
4698   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_zero));
4699   check_isinfp ("real(csqrt(+Inf - i0)) = +Inf", __real__ result);
4700   check ("imag(csqrt(+Inf - i0)) = -0", __imag__ result, minus_zero);
4701   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, -6));
4702   check_isinfp ("real(csqrt(+Inf - i6)) = +Inf", __real__ result);
4703   check ("imag(csqrt(+Inf - i6)) = -0", __imag__ result, minus_zero);
4704
4705   result = FUNC(csqrt) (BUILD_COMPLEX (0, plus_infty));
4706   check_isinfp ("real(csqrt(0 + i Inf)) = +Inf", __real__ result);
4707   check_isinfp ("imag(csqrt(0 + i Inf)) = +Inf", __imag__ result);
4708   result = FUNC(csqrt) (BUILD_COMPLEX (4, plus_infty));
4709   check_isinfp ("real(csqrt(4 + i Inf)) = +Inf", __real__ result);
4710   check_isinfp ("imag(csqrt(4 + i Inf)) = +Inf", __imag__ result);
4711   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, plus_infty));
4712   check_isinfp ("real(csqrt(+Inf + i Inf)) = +Inf", __real__ result);
4713   check_isinfp ("imag(csqrt(+Inf + i Inf)) = +Inf", __imag__ result);
4714   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, plus_infty));
4715   check_isinfp ("real(csqrt(-0 + i Inf)) = +Inf", __real__ result);
4716   check_isinfp ("imag(csqrt(-0 + i Inf)) = +Inf", __imag__ result);
4717   result = FUNC(csqrt) (BUILD_COMPLEX (-4, plus_infty));
4718   check_isinfp ("real(csqrt(-4 + i Inf)) = +Inf", __real__ result);
4719   check_isinfp ("imag(csqrt(-4 + i Inf)) = +Inf", __imag__ result);
4720   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, plus_infty));
4721   check_isinfp ("real(csqrt(-Inf + i Inf)) = +Inf", __real__ result);
4722   check_isinfp ("imag(csqrt(-Inf + i Inf)) = +Inf", __imag__ result);
4723   result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_infty));
4724   check_isinfp ("real(csqrt(0 - i Inf)) = +Inf", __real__ result);
4725   check_isinfn ("imag(csqrt(0 - i Inf)) = -Inf", __imag__ result);
4726   result = FUNC(csqrt) (BUILD_COMPLEX (4, minus_infty));
4727   check_isinfp ("real(csqrt(4 - i Inf)) = +Inf", __real__ result);
4728   check_isinfn ("imag(csqrt(4 - i Inf)) = -Inf", __imag__ result);
4729   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_infty));
4730   check_isinfp ("real(csqrt(+Inf - i Inf)) = +Inf", __real__ result);
4731   check_isinfn ("imag(csqrt(+Inf - i Inf)) = -Inf", __imag__ result);
4732   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_infty));
4733   check_isinfp ("real(csqrt(-0 - i Inf)) = +Inf", __real__ result);
4734   check_isinfn ("imag(csqrt(-0 - i Inf)) = -Inf", __imag__ result);
4735   result = FUNC(csqrt) (BUILD_COMPLEX (-4, minus_infty));
4736   check_isinfp ("real(csqrt(-4 - i Inf)) = +Inf", __real__ result);
4737   check_isinfn ("imag(csqrt(-4 - i Inf)) = -Inf", __imag__ result);
4738   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_infty));
4739   check_isinfp ("real(csqrt(-Inf - i Inf)) = +Inf", __real__ result);
4740   check_isinfn ("imag(csqrt(-Inf - i Inf)) = -Inf", __imag__ result);
4741
4742   result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, nan_value));
4743   check_isnan ("real(csqrt(-Inf + i NaN)) = NaN", __real__ result);
4744   check_isinfp ("imag(csqrt(-Inf + i NaN)) = +-Inf",
4745                 FUNC(fabs) (__imag__ result));
4746
4747   result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, nan_value));
4748   check_isinfp ("real(csqrt(+Inf + i NaN)) = +Inf", __real__ result);
4749   check_isnan ("imag(csqrt(+Inf + i NaN)) = NaN", __imag__ result);
4750
4751   result = FUNC(csqrt) (BUILD_COMPLEX (0, nan_value));
4752   check_isnan_maybe_exc ("real(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
4753                          __real__ result, INVALID_EXCEPTION);
4754   check_isnan ("imag(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
4755                __imag__ result);
4756   result = FUNC(csqrt) (BUILD_COMPLEX (1, nan_value));
4757   check_isnan_maybe_exc ("real(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
4758                          __real__ result, INVALID_EXCEPTION);
4759   check_isnan ("imag(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
4760                __imag__ result);
4761   result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, nan_value));
4762   check_isnan_maybe_exc ("real(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
4763                          __real__ result, INVALID_EXCEPTION);
4764   check_isnan ("imag(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
4765                __imag__ result);
4766   result = FUNC(csqrt) (BUILD_COMPLEX (-1, nan_value));
4767   check_isnan_maybe_exc ("real(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
4768                          __real__ result, INVALID_EXCEPTION);
4769   check_isnan ("imag(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
4770                __imag__ result);
4771
4772   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 0));
4773   check_isnan_maybe_exc ("real(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
4774                          __real__ result, INVALID_EXCEPTION);
4775   check_isnan ("imag(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
4776                __imag__ result);
4777   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 8));
4778   check_isnan_maybe_exc ("real(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
4779                          __real__ result, INVALID_EXCEPTION);
4780   check_isnan ("imag(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
4781                __imag__ result);
4782   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, minus_zero));
4783   check_isnan_maybe_exc ("real(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
4784                          __real__ result, INVALID_EXCEPTION);
4785   check_isnan ("imag(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
4786                __imag__ result);
4787   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, -8));
4788   check_isnan_maybe_exc ("real(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
4789                          __real__ result, INVALID_EXCEPTION);
4790   check_isnan ("imag(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
4791                __imag__ result);
4792
4793   result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, nan_value));
4794   check_isnan ("real(csqrt(NaN + i NaN)) = NaN", __real__ result);
4795   check_isnan ("imag(csqrt(NaN + i NaN)) = NaN", __imag__ result);
4796
4797   result = FUNC(csqrt) (BUILD_COMPLEX (16.0, -30.0));
4798   check ("real(csqrt(16 - 30i)) = 5", __real__ result, 5.0);
4799   check ("imag(csqrt(16 - 30i)) = -3", __imag__ result, -3.0);
4800
4801   result = FUNC(csqrt) (BUILD_COMPLEX (-1, 0));
4802   check ("real(csqrt(1 + i0) = 0", __real__ result, 0);
4803   check ("imag(csqrt(1 + i0) = 1", __imag__ result, 1);
4804
4805   result = FUNC(csqrt) (BUILD_COMPLEX (0, 2));
4806   check ("real(csqrt(0 + i 2) = 1", __real__ result, 1);
4807   check ("imag(csqrt(0 + i 2) = 1", __imag__ result, 1);
4808
4809   result = FUNC(csqrt) (BUILD_COMPLEX (119, 120));
4810   check ("real(csqrt(119 + i 120) = 12", __real__ result, 12);
4811   check ("imag(csqrt(119 + i 120) = 5", __imag__ result, 5);
4812 }
4813
4814
4815 static void
4816 cpow_test (void)
4817 {
4818   __complex__ MATHTYPE result;
4819
4820   result = FUNC (cpow) (BUILD_COMPLEX (1, 0), BUILD_COMPLEX (0, 0));
4821   check ("real(cpow (1 + i0), (0 + i0)) == 0", __real__ result, 1);
4822   check ("imag(cpow (1 + i0), (0 + i0)) == 0", __imag__ result, 0);
4823
4824   result = FUNC (cpow) (BUILD_COMPLEX (2, 0), BUILD_COMPLEX (10, 0));
4825   check_eps ("real(cpow (2 + i0), (10 + i0)) == 1024", __real__ result, 1024,
4826              CHOOSE (2e-16L, 0, 0));
4827   check ("imag(cpow (2 + i0), (10 + i0)) == 0", __imag__ result, 0);
4828
4829   result = FUNC (cpow) (BUILD_COMPLEX (M_E, 0), BUILD_COMPLEX (0, 2*M_PI));
4830   check ("real(cpow (e + i0), (0 + i 2*PI)) == 1", __real__ result, 1);
4831   check_eps ("imag(cpow (e + i0), (0 + i 2*PI)) == 0", __imag__ result, 0,
4832              CHOOSE (1e-18L, 3e-16, 4e-7));
4833
4834   result = FUNC (cpow) (BUILD_COMPLEX (2, 3), BUILD_COMPLEX (4, 0));
4835   check_eps ("real(cpow (2 + i3), (4 + i0)) == -119", __real__ result, -119,
4836              CHOOSE (2e-17L, 2e-14, 4e-5));
4837   check_eps ("imag(cpow (2 + i3), (4 + i0)) == -120", __imag__ result, -120,
4838              CHOOSE (4e-17L, 0, 8e-6));
4839 }
4840
4841
4842 static void
4843 cabs_test (void)
4844 {
4845   /* cabs (x + iy) is specified as hypot (x,y) */
4846   MATHTYPE a;
4847   a = random_greater (0);
4848   check_isinfp_ext ("cabs (+inf + i x) == +inf",
4849                     FUNC(cabs) (BUILD_COMPLEX (plus_infty, a)), a);
4850   check_isinfp_ext ("cabs (-inf + i x) == +inf",
4851                     FUNC(cabs) (BUILD_COMPLEX (minus_infty, a)), a);
4852
4853   check_isinfp ("cabs (+inf+ iNaN) == +inf",
4854                 FUNC(cabs) (BUILD_COMPLEX(minus_infty, nan_value)));
4855   check_isinfp ("cabs (-inf+ iNaN) == +inf",
4856                 FUNC(cabs) (BUILD_COMPLEX(minus_infty, nan_value)));
4857
4858   check_isnan ("cabs (NaN+ iNaN) == NaN",
4859                FUNC(cabs) (BUILD_COMPLEX(nan_value, nan_value)));
4860
4861   a = FUNC(cabs) (BUILD_COMPLEX (12.4L, 0.7L));
4862   check ("cabs (x,y) == cabs (y,x)",
4863          FUNC(cabs) (BUILD_COMPLEX(0.7L, 12.4L)), a);
4864   check ("cabs (x,y) == cabs (-x,y)",
4865          FUNC(cabs) (BUILD_COMPLEX(-12.4L, 0.7L)), a);
4866   check ("cabs (x,y) == cabs (-y,x)",
4867          FUNC(cabs) (BUILD_COMPLEX(-0.7L, 12.4L)), a);
4868   check ("cabs (x,y) == cabs (-x,-y)",
4869          FUNC(cabs) (BUILD_COMPLEX(-12.4L, -0.7L)), a);
4870   check ("cabs (x,y) == cabs (-y,-x)",
4871          FUNC(cabs) (BUILD_COMPLEX(-0.7L, -12.4L)), a);
4872   check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-0.7L, 0)), 0.7L);
4873   check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(0.7L, 0)), 0.7L);
4874   check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-1.0L, 0)), 1.0L);
4875   check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(1.0L, 0)), 1.0L);
4876   check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-5.7e7L, 0)),
4877          5.7e7L);
4878   check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(5.7e7L, 0)),
4879          5.7e7L);
4880
4881 }
4882
4883
4884 static void
4885 carg_test (void)
4886 {
4887   /* carg (x + iy) is specified as atan2 (y, x) */
4888   MATHTYPE x;
4889
4890   x = random_greater (0);
4891   check ("carg (x + i 0) == 0 for x > 0",
4892          FUNC(carg) (BUILD_COMPLEX(x, 0)), 0);
4893   x = random_greater (0);
4894   check ("carg (x - i 0) == -0 for x > 0",
4895          FUNC(carg) (BUILD_COMPLEX(x, minus_zero)), minus_zero);
4896
4897   check ("carg (+0 + i 0) == +0", FUNC(carg) (BUILD_COMPLEX(0, 0)), 0);
4898   check ("carg (+0 - i 0) == -0", FUNC(carg) (BUILD_COMPLEX(0, minus_zero)),
4899          minus_zero);
4900
4901   x = -random_greater (0);
4902   check ("carg (x + i 0) == +pi for x < 0", FUNC(carg) (BUILD_COMPLEX(x, 0)),
4903          M_PI);
4904
4905   x = -random_greater (0);
4906   check ("carg (x - i 0) == -pi for x < 0",
4907          FUNC(carg) (BUILD_COMPLEX(x, minus_zero)), -M_PI);
4908
4909   check ("carg (-0 + i 0) == +pi", FUNC(carg) (BUILD_COMPLEX(minus_zero, 0)),
4910          M_PI);
4911   check ("carg (-0 - i 0) == -pi",
4912          FUNC(carg) (BUILD_COMPLEX(minus_zero, minus_zero)), -M_PI);
4913
4914   x = random_greater (0);
4915   check ("carg (+0 + i y) == pi/2 for y > 0", FUNC(carg) (BUILD_COMPLEX(0, x)),
4916          M_PI_2);
4917
4918   x = random_greater (0);
4919   check ("carg (-0 + i y) == pi/2 for y > 0",
4920          FUNC(carg) (BUILD_COMPLEX(minus_zero, x)), M_PI_2);
4921
4922   x = random_less (0);
4923   check ("carg (+0 + i y) == -pi/2 for y < 0", FUNC(carg) (BUILD_COMPLEX(0, x)),
4924          -M_PI_2);
4925
4926   x = random_less (0);
4927   check ("carg (-0 + i y) == -pi/2 for y < 0",
4928          FUNC(carg) (BUILD_COMPLEX(minus_zero, x)), -M_PI_2);
4929
4930   x = random_greater (0);
4931   check ("carg (inf + i y) == +0 for finite y > 0",
4932          FUNC(carg) (BUILD_COMPLEX(plus_infty, x)), 0);
4933
4934   x = -random_greater (0);
4935   check ("carg (inf + i y) == -0 for finite y < 0",
4936          FUNC(carg) (BUILD_COMPLEX(plus_infty, x)), minus_zero);
4937
4938   x = random_value (-1e4, 1e4);
4939   check ("carg(x + i inf) == pi/2 for finite x",
4940          FUNC(carg) (BUILD_COMPLEX(x, plus_infty)), M_PI_2);
4941
4942   x = random_value (-1e4, 1e4);
4943   check ("carg(x - i inf) == -pi/2 for finite x",
4944          FUNC(carg) (BUILD_COMPLEX(x, minus_infty)), -M_PI_2);
4945
4946   x = random_greater (0);
4947   check ("carg (-inf + i y) == +pi for finite y > 0",
4948          FUNC(carg) (BUILD_COMPLEX(minus_infty, x)), M_PI);
4949
4950   x = -random_greater (0);
4951   check ("carg (-inf + i y) == -pi for finite y < 0",
4952          FUNC(carg) (BUILD_COMPLEX(minus_infty, x)), -M_PI);
4953
4954   check ("carg (+inf + i inf) == +pi/4",
4955          FUNC(carg) (BUILD_COMPLEX(plus_infty, plus_infty)), M_PI_4);
4956
4957   check ("carg (+inf -i inf) == -pi/4",
4958          FUNC(carg) (BUILD_COMPLEX(plus_infty, minus_infty)), -M_PI_4);
4959
4960   check ("carg (-inf +i inf) == +3*pi/4",
4961          FUNC(carg) (BUILD_COMPLEX(minus_infty, plus_infty)), 3 * M_PI_4);
4962
4963   check ("carg (-inf -i inf) == -3*pi/4",
4964          FUNC(carg) (BUILD_COMPLEX(minus_infty, minus_infty)), -3 * M_PI_4);
4965
4966 }
4967
4968
4969 static void
4970 nearbyint_test (void)
4971 {
4972   check ("nearbyint(+0) = 0", FUNC(nearbyint) (0.0), 0.0);
4973   check ("nearbyint(-0) = -0", FUNC(nearbyint) (minus_zero), minus_zero);
4974   check_isinfp ("nearbyint(+Inf) = +Inf", FUNC(nearbyint) (plus_infty));
4975   check_isinfn ("nearbyint(-Inf) = -Inf", FUNC(nearbyint) (minus_infty));
4976 }
4977
4978
4979 static void
4980 rint_test (void)
4981 {
4982   check ("rint(0) = 0", FUNC(rint) (0.0), 0.0);
4983   check ("rint(-0) = -0", FUNC(rint) (minus_zero), minus_zero);
4984   check_isinfp ("rint(+Inf) = +Inf", FUNC(rint) (plus_infty));
4985   check_isinfn ("rint(-Inf) = -Inf", FUNC(rint) (minus_infty));
4986 }
4987
4988
4989 static void
4990 lrint_test (void)
4991 {
4992   /* XXX this test is incomplete.  We need to have a way to specifiy
4993      the rounding method and test the critical cases.  So far, only
4994      unproblematic numbers are tested.  */
4995
4996   check_long ("lrint(0) = 0", FUNC(lrint) (0.0), 0);
4997   check_long ("lrint(-0) = 0", FUNC(lrint) (minus_zero), 0);
4998   check_long ("lrint(0.2) = 0", FUNC(lrint) (0.2), 0);
4999   check_long ("lrint(-0.2) = 0", FUNC(lrint) (-0.2), 0);
5000
5001   check_long ("lrint(1.4) = 1", FUNC(lrint) (1.4), 1);
5002   check_long ("lrint(-1.4) = -1", FUNC(lrint) (-1.4), -1);
5003
5004   check_long ("lrint(8388600.3) = 8388600", FUNC(lrint) (8388600.3), 8388600);
5005   check_long ("lrint(-8388600.3) = -8388600", FUNC(lrint) (-8388600.3),
5006               -8388600);
5007 }
5008
5009
5010 static void
5011 llrint_test (void)
5012 {
5013   /* XXX this test is incomplete.  We need to have a way to specifiy
5014      the rounding method and test the critical cases.  So far, only
5015      unproblematic numbers are tested.  */
5016
5017   check_longlong ("llrint(0) = 0", FUNC(llrint) (0.0), 0);
5018   check_longlong ("llrint(-0) = 0", FUNC(llrint) (minus_zero), 0);
5019   check_longlong ("llrint(0.2) = 0", FUNC(llrint) (0.2), 0);
5020   check_longlong ("llrint(-0.2) = 0", FUNC(llrint) (-0.2), 0);
5021
5022   check_longlong ("llrint(1.4) = 1", FUNC(llrint) (1.4), 1);
5023   check_longlong ("llrint(-1.4) = -1", FUNC(llrint) (-1.4), -1);
5024
5025   check_longlong ("llrint(8388600.3) = 8388600", FUNC(llrint) (8388600.3),
5026                   8388600);
5027   check_longlong ("llrint(-8388600.3) = -8388600", FUNC(llrint) (-8388600.3),
5028                   -8388600);
5029
5030   /* Test boundary conditions.  */
5031   /* 0x1FFFFF */
5032   check_longlong ("llrint(2097151.0) = 2097151", FUNC(llrint) (2097151.0),
5033                   2097151LL);
5034   /* 0x800000 */
5035   check_longlong ("llrint(8388608.0) = 8388608", FUNC(llrint) (8388608.0),
5036                   8388608LL);
5037   /* 0x1000000 */
5038   check_longlong ("llrint(16777216.0) = 16777216",
5039                   FUNC(llrint) (16777216.0), 16777216LL);
5040   /* 0x20000000000 */
5041   check_longlong ("llrint(2199023255552.0) = 2199023255552",
5042                   FUNC(llrint) (2199023255552.0), 2199023255552LL);
5043   /* 0x40000000000 */
5044   check_longlong ("llrint(4398046511104.0) = 4398046511104",
5045                   FUNC(llrint) (4398046511104.0), 4398046511104LL);
5046   /* 0x10000000000000 */
5047   check_longlong ("llrint(4503599627370496.0) = 4503599627370496",
5048                   FUNC(llrint) (4503599627370496.0), 4503599627370496LL);
5049   /* 0x10000080000000 */
5050   check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5051                   FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5052   /* 0x20000000000000 */
5053   check_longlong ("llrint(9007199254740992.0) = 9007199254740992",
5054                   FUNC(llrint) (9007199254740992.0), 9007199254740992LL);
5055   /* 0x80000000000000 */
5056   check_longlong ("llrint(36028797018963968.0) = 36028797018963968",
5057                   FUNC(llrint) (36028797018963968.0), 36028797018963968LL);
5058   /* 0x100000000000000 */
5059   check_longlong ("llrint(72057594037927936.0) = 72057594037927936",
5060                   FUNC(llrint) (72057594037927936.0), 72057594037927936LL);
5061 }
5062
5063
5064 static void
5065 round_test (void)
5066 {
5067   check ("round(0) = 0", FUNC(round) (0), 0);
5068   check ("round(-0) = -0", FUNC(round) (minus_zero), minus_zero);
5069   check ("round(0.2) = 0", FUNC(round) (0.2), 0.0);
5070   check ("round(-0.2) = -0", FUNC(round) (-0.2), minus_zero);
5071   check ("round(0.5) = 1", FUNC(round) (0.5), 1.0);
5072   check ("round(-0.5) = -1", FUNC(round) (-0.5), -1.0);
5073   check ("round(0.8) = 1", FUNC(round) (0.8), 1.0);
5074   check ("round(-0.8) = -1", FUNC(round) (-0.8), -1.0);
5075   check ("round(1.5) = 2", FUNC(round) (1.5), 2.0);
5076   check ("round(-1.5) = -2", FUNC(round) (-1.5), -2.0);
5077   check ("round(2097152.5) = 2097153", FUNC(round) (2097152.5), 2097153);
5078   check ("round(-2097152.5) = -2097153", FUNC(round) (-2097152.5), -2097153);
5079 }
5080
5081
5082 static void
5083 lround_test (void)
5084 {
5085   check_long ("lround(0) = 0", FUNC(lround) (0), 0);
5086   check_long ("lround(-0) = 0", FUNC(lround) (minus_zero), 0);
5087   check_long ("lround(0.2) = 0", FUNC(lround) (0.2), 0.0);
5088   check_long ("lround(-0.2) = 0", FUNC(lround) (-0.2), 0);
5089   check_long ("lround(0.5) = 1", FUNC(lround) (0.5), 1);
5090   check_long ("lround(-0.5) = -1", FUNC(lround) (-0.5), -1);
5091   check_long ("lround(0.8) = 1", FUNC(lround) (0.8), 1);
5092   check_long ("lround(-0.8) = -1", FUNC(lround) (-0.8), -1);
5093   check_long ("lround(1.5) = 2", FUNC(lround) (1.5), 2);
5094   check_long ("lround(-1.5) = -2", FUNC(lround) (-1.5), -2);
5095   check_long ("lround(22514.5) = 22515", FUNC(lround) (22514.5), 22515);
5096   check_long ("lround(-22514.5) = -22515", FUNC(lround) (-22514.5), -22515);
5097 #ifndef TEST_FLOAT
5098   check_long ("lround(2097152.5) = 2097153", FUNC(lround) (2097152.5),
5099               2097153);
5100   check_long ("lround(-2097152.5) = -2097153", FUNC(lround) (-2097152.5),
5101               -2097153);
5102 #endif
5103 }
5104
5105
5106 static void
5107 llround_test (void)
5108 {
5109   check_longlong ("llround(0) = 0", FUNC(llround) (0), 0);
5110   check_longlong ("llround(-0) = 0", FUNC(llround) (minus_zero), 0);
5111   check_longlong ("llround(0.2) = 0", FUNC(llround) (0.2), 0.0);
5112   check_longlong ("llround(-0.2) = 0", FUNC(llround) (-0.2), 0);
5113   check_longlong ("llround(0.5) = 1", FUNC(llround) (0.5), 1);
5114   check_longlong ("llround(-0.5) = -1", FUNC(llround) (-0.5), -1);
5115   check_longlong ("llround(0.8) = 1", FUNC(llround) (0.8), 1);
5116   check_longlong ("llround(-0.8) = -1", FUNC(llround) (-0.8), -1);
5117   check_longlong ("llround(1.5) = 2", FUNC(llround) (1.5), 2);
5118   check_longlong ("llround(-1.5) = -2", FUNC(llround) (-1.5), -2);
5119   check_longlong ("llround(22514.5) = 22515", FUNC(llround) (22514.5), 22515);
5120   check_longlong ("llround(-22514.5) = -22515", FUNC(llround) (-22514.5),
5121                   -22515);
5122 #ifndef TEST_FLOAT
5123   check_longlong ("llround(2097152.5) = 2097153",
5124                   FUNC(llround) (2097152.5), 2097153);
5125   check_longlong ("llround(-2097152.5) = -2097153",
5126                   FUNC(llround) (-2097152.5), -2097153);
5127   check_longlong ("llround(34359738368.5) = 34359738369",
5128                   FUNC(llround) (34359738368.5), 34359738369ll);
5129   check_longlong ("llround(-34359738368.5) = -34359738369",
5130                   FUNC(llround) (-34359738368.5), -34359738369ll);
5131 #endif
5132
5133   /* Test boundary conditions.  */
5134   /* 0x1FFFFF */
5135   check_longlong ("llround(2097151.0) = 2097151", FUNC(llround) (2097151.0),
5136                   2097151LL);
5137   /* 0x800000 */
5138   check_longlong ("llround(8388608.0) = 8388608", FUNC(llround) (8388608.0),
5139                   8388608LL);
5140   /* 0x1000000 */
5141   check_longlong ("llround(16777216.0) = 16777216",
5142                   FUNC(llround) (16777216.0), 16777216LL);
5143   /* 0x20000000000 */
5144   check_longlong ("llround(2199023255552.0) = 2199023255552",
5145                   FUNC(llround) (2199023255552.0), 2199023255552LL);
5146   /* 0x40000000000 */
5147   check_longlong ("llround(4398046511104.0) = 4398046511104",
5148                   FUNC(llround) (4398046511104.0), 4398046511104LL);
5149   /* 0x10000000000000 */
5150   check_longlong ("llround(4503599627370496.0) = 4503599627370496",
5151                   FUNC(llround) (4503599627370496.0), 4503599627370496LL);
5152   /* 0x10000080000000 */
5153   check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5154                   FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5155   /* 0x20000000000000 */
5156   check_longlong ("llround(9007199254740992.0) = 9007199254740992",
5157                   FUNC(llround) (9007199254740992.0), 9007199254740992LL);
5158   /* 0x80000000000000 */
5159   check_longlong ("llround(36028797018963968.0) = 36028797018963968",
5160                   FUNC(llround) (36028797018963968.0), 36028797018963968LL);
5161   /* 0x100000000000000 */
5162   check_longlong ("llround(72057594037927936.0) = 72057594037927936",
5163                   FUNC(llround) (72057594037927936.0), 72057594037927936LL);
5164 }
5165
5166
5167 static void
5168 fma_test (void)
5169 {
5170   check ("fma(1.0, 2.0, 3.0) = 5.0", FUNC(fma) (1.0, 2.0, 3.0), 5.0);
5171   check_isnan ("fma(NaN, 2.0, 3.0) = NaN", FUNC(fma) (nan_value, 2.0, 3.0));
5172   check_isnan ("fma(1.0, NaN, 3.0) = NaN", FUNC(fma) (1.0, nan_value, 3.0));
5173   check_isnan_maybe_exc ("fma(1.0, 2.0, NaN) = NaN",
5174                          FUNC(fma) (1.0, 2.0, nan_value), INVALID_EXCEPTION);
5175   check_isnan_maybe_exc ("fma(+Inf, 0.0, NaN) = NaN",
5176                          FUNC(fma) (plus_infty, 0.0, nan_value),
5177                          INVALID_EXCEPTION);
5178   check_isnan_maybe_exc ("fma(-Inf, 0.0, NaN) = NaN",
5179                          FUNC(fma) (minus_infty, 0.0, nan_value),
5180                          INVALID_EXCEPTION);
5181   check_isnan_maybe_exc ("fma(0.0, +Inf, NaN) = NaN",
5182                          FUNC(fma) (0.0, plus_infty, nan_value),
5183                          INVALID_EXCEPTION);
5184   check_isnan_maybe_exc ("fma(0.0, -Inf, NaN) = NaN",
5185                          FUNC(fma) (0.0, minus_infty, nan_value),
5186                          INVALID_EXCEPTION);
5187   check_isnan_exc ("fma(+Inf, 0.0, 1.0) = NaN",
5188                    FUNC(fma) (plus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5189   check_isnan_exc ("fma(-Inf, 0.0, 1.0) = NaN",
5190                    FUNC(fma) (minus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5191   check_isnan_exc ("fma(0.0, +Inf, 1.0) = NaN",
5192                    FUNC(fma) (0.0, plus_infty, 1.0), INVALID_EXCEPTION);
5193   check_isnan_exc ("fma(0.0, -Inf, 1.0) = NaN",
5194                    FUNC(fma) (0.0, minus_infty, 1.0), INVALID_EXCEPTION);
5195
5196   check_isnan_exc ("fma(+Inf, +Inf, -Inf) = NaN",
5197                    FUNC(fma) (plus_infty, plus_infty, minus_infty),
5198                    INVALID_EXCEPTION);
5199   check_isnan_exc ("fma(-Inf, +Inf, +Inf) = NaN",
5200                    FUNC(fma) (minus_infty, plus_infty, plus_infty),
5201                    INVALID_EXCEPTION);
5202   check_isnan_exc ("fma(+Inf, -Inf, +Inf) = NaN",
5203                    FUNC(fma) (plus_infty, minus_infty, plus_infty),
5204                    INVALID_EXCEPTION);
5205   check_isnan_exc ("fma(-Inf, -Inf, -Inf) = NaN",
5206                    FUNC(fma) (minus_infty, minus_infty, minus_infty),
5207                    INVALID_EXCEPTION);
5208 }
5209
5210
5211 static void
5212 inverse_func_pair_test (const char *test_name,
5213                         mathfunc f1, mathfunc inverse,
5214                         MATHTYPE x, MATHTYPE epsilon)
5215 {
5216   MATHTYPE a, b, difference;
5217   int result;
5218
5219   a = f1 (x);
5220   (void) &a;
5221   b = inverse (a);
5222   (void) &b;
5223
5224   output_new_test (test_name);
5225   result = check_equal (b, x, epsilon, &difference);
5226   output_result (test_name, result,
5227                  b, x, difference, PRINT, PRINT);
5228 }
5229
5230
5231 static void
5232 inverse_functions (void)
5233 {
5234   inverse_func_pair_test ("asin(sin(x)) == x",
5235                           FUNC(sin), FUNC(asin), 1.0,
5236                           CHOOSE (2e-18L, 0, 3e-7L));
5237   inverse_func_pair_test ("sin(asin(x)) == x",
5238                           FUNC(asin), FUNC(sin), 1.0, 0.0);
5239
5240   inverse_func_pair_test ("acos(cos(x)) == x",
5241                           FUNC(cos), FUNC(acos), 1.0,
5242                           CHOOSE (4e-18L, 1e-15L, 0));
5243   inverse_func_pair_test ("cos(acos(x)) == x",
5244                           FUNC(acos), FUNC(cos), 1.0, 0.0);
5245   inverse_func_pair_test ("atan(tan(x)) == x",
5246                           FUNC(tan), FUNC(atan), 1.0, CHOOSE (2e-18L, 0, 0));
5247   inverse_func_pair_test ("tan(atan(x)) == x",
5248                           FUNC(atan), FUNC(tan), 1.0,
5249                           CHOOSE (2e-18L, 1e-15L, 2e-7));
5250
5251   inverse_func_pair_test ("asinh(sinh(x)) == x",
5252                      FUNC(sinh), FUNC(asinh), 1.0, CHOOSE (1e-18L, 0, 1e-7));
5253   inverse_func_pair_test ("sinh(asinh(x)) == x",
5254                           FUNC(asinh), FUNC(sinh), 1.0,
5255                           CHOOSE (2e-18L, 2e-16L, 2e-7));
5256
5257   inverse_func_pair_test ("acosh(cosh(x)) == x",
5258                           FUNC(cosh), FUNC(acosh), 1.0,
5259                           CHOOSE (1e-18L, 1e-15L, 6e-8));
5260   inverse_func_pair_test ("cosh(acosh(x)) == x",
5261                           FUNC(acosh), FUNC(cosh), 1.0, 0.0);
5262
5263   inverse_func_pair_test ("atanh(tanh(x)) == x",
5264                      FUNC(tanh), FUNC(atanh), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
5265   inverse_func_pair_test ("tanh(atanh(x)) == x",
5266                           FUNC(atanh), FUNC(tanh), 1.0, 0.0);
5267
5268 }
5269
5270 /* Test sin and cos with the identity: sin(x)^2 + cos(x)^2 = 1.  */
5271 static void
5272 identities1_test (MATHTYPE x, MATHTYPE epsilon)
5273 {
5274   MATHTYPE res1, res2, res3, diff;
5275   int result;
5276
5277   res1 = FUNC(sin) (x);
5278   (void) &res1;
5279   res2 = FUNC(cos) (x);
5280   (void) &res2;
5281   res3 = res1 * res1 + res2 * res2;
5282   (void) &res3;
5283
5284   output_new_test ("sin^2 + cos^2 == 1");
5285   result = check_equal (res3, 1.0, epsilon, &diff);
5286   output_result_ext ("sin^2 + cos^2 == 1", result,
5287                      res3, 1.0, diff, x, PRINT, PRINT);
5288 }
5289
5290
5291 /* Test sin, cos, tan with the following relation: tan = sin/cos.  */
5292 static void
5293 identities2_test (MATHTYPE x, MATHTYPE epsilon)
5294 {
5295 #ifndef TEST_INLINE
5296   MATHTYPE res1, res2, res3, res4, diff;
5297   int result;
5298
5299   res1 = FUNC(sin) (x);
5300   (void) &res1;
5301   res2 = FUNC(cos) (x);
5302   (void) &res2;
5303   res3 = FUNC(tan) (x);
5304   (void) &res3;
5305   res4 = res1 / res2;
5306   (void) &res4;
5307
5308   output_new_test ("sin/cos == tan");
5309   result = check_equal (res4, res3, epsilon, &diff);
5310   output_result_ext ("sin/cos == tan", result,
5311                      res4, res3, diff, x, PRINT, PRINT);
5312 #endif
5313 }
5314
5315
5316 /* Test cosh and sinh with the identity cosh^2 - sinh^2 = 1.  */
5317 static void
5318 identities3_test (MATHTYPE x, MATHTYPE epsilon)
5319 {
5320   MATHTYPE res1, res2, res3, diff;
5321   int result;
5322
5323   res1 = FUNC(sinh) (x);
5324   (void) &res1;
5325   res2 = FUNC(cosh) (x);
5326   (void) &res2;
5327   res3 = res2 * res2 - res1 * res1;
5328   (void) &res3;
5329
5330   output_new_test ("cosh^2 - sinh^2 == 1");
5331   result = check_equal (res3, 1.0, epsilon, &diff);
5332   output_result_ext ("cosh^2 - sinh^2 == 1", result,
5333                      res3, 1.0, diff, x, PRINT, PRINT);
5334 }
5335
5336
5337 static void
5338 identities (void)
5339 {
5340   identities1_test (0.2L, CHOOSE (1e-18L, 0, 2e-7));
5341   identities1_test (0.9L, CHOOSE (1e-18L, 0, 1e-7));
5342   identities1_test (0, 0);
5343   identities1_test (-1, CHOOSE (1e-18L, 0, 1e-7));
5344
5345   identities2_test (0.2L, CHOOSE (1e-19L, 1e-16, 0));
5346   identities2_test (0.9L, CHOOSE (0, 1e-15, 2e-7));
5347   identities2_test (0, 0);
5348   identities2_test (-1, CHOOSE (1e-18L, 1e-15, 2e-7));
5349
5350   identities3_test (0.2L, CHOOSE (1e-18L, 0, 1e-7));
5351   identities3_test (0.9L, CHOOSE (1e-18L, 1e-15, 1e-6));
5352   identities3_test (0, CHOOSE (0, 0, 1e-6));
5353   identities3_test (-1, CHOOSE (1e-18L, 7e-16, 1e-6));
5354 }
5355
5356
5357 /*
5358    Let's test that basic arithmetic is working
5359    tests: Infinity and NaN
5360  */
5361 static void
5362 basic_tests (void)
5363 {
5364   /* variables are declared volatile to forbid some compiler
5365      optimizations */
5366   volatile MATHTYPE Inf_var, NaN_var, zero_var, one_var;
5367   MATHTYPE x1, x2;
5368
5369   zero_var = 0.0;
5370   one_var = 1.0;
5371   NaN_var = nan_value;
5372   Inf_var = one_var / zero_var;
5373
5374   (void) &zero_var;
5375   (void) &one_var;
5376   (void) &NaN_var;
5377   (void) &Inf_var;
5378
5379   /* Clear all exceptions.  The previous computations raised exceptions.  */
5380   feclearexcept (FE_ALL_EXCEPT);
5381
5382   check_isinfp ("isinf (inf) == +1", Inf_var);
5383   check_isinfn ("isinf (-inf) == -1", -Inf_var);
5384   check_bool ("!isinf (1)", !(FUNC(isinf) (one_var)));
5385   check_bool ("!isinf (NaN)", !(FUNC(isinf) (NaN_var)));
5386
5387   check_isnan ("isnan (NaN)", NaN_var);
5388   check_isnan ("isnan (-NaN)", -NaN_var);
5389   check_bool ("!isnan (1)", !(FUNC(isnan) (one_var)));
5390   check_bool ("!isnan (inf)", !(FUNC(isnan) (Inf_var)));
5391
5392   check_bool ("inf == inf", Inf_var == Inf_var);
5393   check_bool ("-inf == -inf", -Inf_var == -Inf_var);
5394   check_bool ("inf != -inf", Inf_var != -Inf_var);
5395   check_bool ("NaN != NaN", NaN_var != NaN_var);
5396
5397   /*
5398      the same tests but this time with NAN from <bits/nan.h>
5399      NAN is a double const
5400    */
5401   check_bool ("isnan (NAN)", isnan (NAN));
5402   check_bool ("isnan (-NAN)", isnan (-NAN));
5403   check_bool ("!isinf (NAN)", !(isinf (NAN)));
5404   check_bool ("!isinf (-NAN)", !(isinf (-NAN)));
5405   check_bool ("NAN != NAN", NAN != NAN);
5406
5407   /*
5408      And again with the value returned by the `nan' function.
5409    */
5410   check_bool ("isnan (NAN)", FUNC(isnan) (FUNC(nan) ("")));
5411   check_bool ("isnan (-NAN)", FUNC(isnan) (-FUNC(nan) ("")));
5412   check_bool ("!isinf (NAN)", !(FUNC(isinf) (FUNC(nan) (""))));
5413   check_bool ("!isinf (-NAN)", !(FUNC(isinf) (-FUNC(nan) (""))));
5414   check_bool ("NAN != NAN", FUNC(nan) ("") != FUNC(nan) (""));
5415
5416   /* test if EPSILON is ok */
5417   x1 = MATHCONST (1.0);
5418   x2 = x1 + CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
5419   check_bool ("1 != 1+EPSILON", x1 != x2);
5420
5421   x1 = MATHCONST (1.0);
5422   x2 = x1 - CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
5423   check_bool ("1 != 1-EPSILON", x1 != x2);
5424
5425   /* test if HUGE_VALx is ok */
5426   x1 = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5427   check_bool ("isinf (HUGE_VALx) == +1", ISINF (x1) == +1);
5428   x1 = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5429   check_bool ("isinf (-HUGE_VALx) == -1", ISINF (x1) == -1);
5430
5431 }
5432
5433
5434 static void
5435 initialize (void)
5436 {
5437   fpstack_test ("start *init*");
5438   plus_zero = 0.0;
5439   nan_value = plus_zero / plus_zero;    /* Suppress GCC warning */
5440
5441   minus_zero = FUNC (copysign) (0.0, -1.0);
5442   plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5443   minus_infty = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5444
5445   (void) &plus_zero;
5446   (void) &nan_value;
5447   (void) &minus_zero;
5448   (void) &plus_infty;
5449   (void) &minus_infty;
5450
5451   /* Clear all exceptions.  From now on we must not get random exceptions.  */
5452   feclearexcept (FE_ALL_EXCEPT);
5453
5454   /* Test to make sure we start correctly.  */
5455   fpstack_test ("end *init*");
5456 }
5457
5458
5459 static struct option long_options[] =
5460 {
5461   {"verbose", optional_argument, NULL, 'v'},
5462   {"silent", no_argument, NULL, 's'},
5463   {0, 0, 0, 0}
5464 };
5465
5466
5467 static void
5468 parse_options (int argc, char *argv[])
5469 {
5470   int c;
5471   int option_index;
5472
5473   verbose = 1;
5474
5475   while (1)
5476     {
5477       c = getopt_long (argc, argv, "v::s",
5478                        long_options, &option_index);
5479
5480       /* Detect the end of the options. */
5481       if (c == -1)
5482         break;
5483
5484       switch (c)
5485         {
5486         case 'v':
5487           if (optarg)
5488             verbose = (unsigned int) strtoul (optarg, NULL, 0);
5489           else
5490             verbose = 4;
5491           break;
5492         case 's':
5493           verbose = 0;
5494         default:
5495           break;
5496         }
5497     }
5498 }
5499
5500
5501 int
5502 main (int argc, char *argv[])
5503 {
5504
5505   parse_options (argc, argv);
5506
5507   initialize ();
5508   printf (TEST_MSG);
5509
5510   basic_tests ();
5511
5512   /* keep the tests a wee bit ordered (according to ISO 9X) */
5513   /* classification functions */
5514   fpclassify_test ();
5515   isfinite_test ();
5516   isnormal_test ();
5517   signbit_test ();
5518
5519   /* trigonometric functions */
5520   acos_test ();
5521   asin_test ();
5522   atan_test ();
5523   atan2_test ();
5524   cos_test ();
5525   sin_test ();
5526   sincos_test ();
5527   tan_test ();
5528
5529   /* hyperbolic functions */
5530   acosh_test ();
5531   asinh_test ();
5532   atanh_test ();
5533   cosh_test ();
5534   sinh_test ();
5535   tanh_test ();
5536
5537   /* exponential and logarithmic functions */
5538   exp_test ();
5539   exp2_test ();
5540   expm1_test ();
5541   frexp_test ();
5542   ldexp_test ();
5543   log_test ();
5544   log10_test ();
5545   log1p_test ();
5546   log2_test ();
5547   logb_test ();
5548   modf_test ();
5549   ilogb_test ();
5550   scalb_test ();
5551   scalbn_test ();
5552
5553   /* power and absolute value functions */
5554   cbrt_test ();
5555   fabs_test ();
5556   hypot_test ();
5557   pow_test ();
5558   sqrt_test ();
5559
5560   /* error and gamma functions */
5561   erf_test ();
5562   erfc_test ();
5563   gamma_test ();
5564   lgamma_test ();
5565
5566   /* nearest integer functions */
5567   ceil_test ();
5568   floor_test ();
5569   nearbyint_test ();
5570   rint_test ();
5571   lrint_test ();
5572   llrint_test ();
5573   round_test ();
5574   lround_test ();
5575   llround_test ();
5576   trunc_test ();
5577
5578   /* remainder functions */
5579   fmod_test ();
5580   remainder_test ();
5581   remquo_test ();
5582
5583   /* manipulation functions */
5584   copysign_test ();
5585   nextafter_test ();
5586
5587   /* maximum, minimum and positive difference functions */
5588   fdim_test ();
5589   fmin_test ();
5590   fmax_test ();
5591
5592   /* complex functions */
5593   cabs_test ();
5594   carg_test ();
5595   cexp_test ();
5596   csin_test ();
5597   csinh_test ();
5598   ccos_test ();
5599   ccosh_test ();
5600   clog_test ();
5601   clog10_test ();
5602   cacos_test ();
5603   cacosh_test ();
5604   casin_test ();
5605   casinh_test ();
5606   catan_test ();
5607   catanh_test ();
5608   ctan_test ();
5609   ctanh_test ();
5610   csqrt_test ();
5611   cpow_test ();
5612
5613   /* multiply and add */
5614   fma_test ();
5615
5616   /* special tests */
5617   identities ();
5618   inverse_functions ();
5619
5620   printf ("\nTest suite completed:\n");
5621   printf ("  %d test cases plus %d tests for exception flags executed.\n",
5622           noTests, noExcTests);
5623   if (noErrors)
5624     {
5625       printf ("  %d errors occured.\n", noErrors);
5626       exit (1);
5627     }
5628   printf ("  All tests passed successfully.\n");
5629   exit (0);
5630 }