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