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