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