gconv conversion module definition for IEC_P27-1.
[glibc/history.git] / math / libm-test.c
blob780880a0c5cc69b3803b6c1487884c70b9c6f1b8
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. */
22 Part of testsuite for libm.
24 This file has to be included by a master file that defines:
26 Makros:
27 FUNC(function): converts general function name (like cos) to
28 name with correct suffix (e.g. cosl or cosf)
29 MATHCONST(x): like FUNC but for constants (e.g convert 0.0 to 0.0L)
30 MATHTYPE: floating point type to test
31 TEST_MSG: informal message to be displayed
32 CHOOSE(Clongdouble,Cdouble,Cfloat):
33 chooses one of the parameters as epsilon for testing
34 equality
35 PRINTF_EXPR Floating point conversion specification to print a variable
36 of type MATHTYPE with printf. PRINTF_EXPR just contains
37 the specifier, not the percent and width arguments,
38 e.g. "f".
39 PRINTF_XEXPR Like PRINTF_EXPR, but print in hexadecimal format.
42 /* This program isn't finished yet.
43 It has tests for:
44 acos, acosh, asin, asinh, atan, atan2, atanh,
45 cbrt, ceil, copysign, cos, cosh, erf, erfc, exp, exp10, exp2, expm1,
46 fabs, fdim, floor, fma, fmax, fmin, fmod, fpclassify,
47 frexp, gamma, hypot,
48 ilogb, isfinite, isinf, isnan, isnormal,
49 isless, islessequal, isgreater, isgreaterequal, islessgreater, isunordered,
50 ldexp, lgamma, log, log10, log1p, log2, logb,
51 modf, nearbyint, nextafter,
52 pow, remainder, remquo, rint, lrint, llrint,
53 round, lround, llround,
54 scalb, scalbn, signbit, sin, sincos, sinh, sqrt, tan, tanh, tgamma, trunc
56 and for the following complex math functions:
57 cabs, cacos, cacosh, carg, casin, casinh, catan, catanh,
58 ccos, ccosh, cexp, clog, cpow, csin, csinh, csqrt, ctan, ctanh.
60 At the moment the following functions aren't tested:
61 OB conj, cproj, cimag, creal, drem,
62 j0, j1, jn, y0, y1, yn,
63 significand,
64 nan
66 The routines using random variables are still under construction. I don't
67 like it the way it's working now and will change it.
69 Parameter handling is primitive in the moment:
70 --verbose=[0..4] for different levels of output:
71 0: only error count
72 1: basic report on failed tests (default)
73 2: full report on failed tests
74 3: full report on failed and passed tests
75 4: additional report on exceptions
76 -v for full output (equals --verbose=4)
77 -s,--silent outputs only the error count (equals --verbose=0)
80 /* "Philosophy":
82 This suite tests some aspects of the correct implementation of
83 mathematical functions in libm. Some simple, specific parameters
84 are tested for correctness but there's no exhaustive
85 testing. Handling of specific inputs (e.g. infinity, not-a-number)
86 is also tested. Correct handling of exceptions is checked
87 against. These implemented tests should check all cases that are
88 specified in ISO C 9X.
90 Exception testing: At the moment only divide-by-zero and invalid
91 exceptions are tested. Overflow/underflow and inexact exceptions
92 aren't checked at the moment.
94 NaN values: There exist signalling and quiet NaNs. This implementation
95 only uses signalling NaN as parameter but does not differenciate
96 between the two kinds of NaNs as result.
98 Inline functions: Inlining functions should give an improvement in
99 speed - but not in precission. The inlined functions return
100 reasonable values for a reasonable range of input values. The
101 result is not necessarily correct for all values and exceptions are
102 not correctly raised in all cases. Problematic input and return
103 values are infinity, not-a-number and minus zero. This suite
104 therefore does not check these specific inputs and the exception
105 handling for inlined mathematical functions - just the "reasonable"
106 values are checked.
108 Beware: The tests might fail for any of the following reasons:
109 - Tests are wrong
110 - Functions are wrong
111 - Floating Point Unit not working properly
112 - Compiler has errors
114 With e.g. gcc 2.7.2.2 the test for cexp fails because of a compiler error.
118 #ifndef _GNU_SOURCE
119 # define _GNU_SOURCE
120 #endif
122 #include <complex.h>
123 #include <math.h>
124 #include <float.h>
125 #include <fenv.h>
127 #include <errno.h>
128 #include <stdlib.h>
129 #include <stdio.h>
130 #include <getopt.h>
132 /* Possible exceptions */
133 #define NO_EXCEPTION 0x0
134 #define INVALID_EXCEPTION 0x1
135 #define DIVIDE_BY_ZERO_EXCEPTION 0x2
137 #define PRINT 1
138 #define NO_PRINT 0
140 /* Various constants (we must supply them precalculated for accuracy). */
141 #define M_PI_6l .52359877559829887308L
142 #define M_E2l 7.389056098930650227230L
143 #define M_E3l 20.08553692318766774093L
145 static int noErrors; /* number of errors */
146 static int noTests; /* number of tests (without testing exceptions) */
147 static int noExcTests; /* number of tests for exception flags */
149 static int verbose = 3;
150 static MATHTYPE minus_zero, plus_zero;
151 static MATHTYPE plus_infty, minus_infty, nan_value;
153 typedef MATHTYPE (*mathfunc) (MATHTYPE);
155 #define BUILD_COMPLEX(real, imag) \
156 ({ __complex__ MATHTYPE __retval; \
157 __real__ __retval = (real); \
158 __imag__ __retval = (imag); \
159 __retval; })
162 #define ISINF(x) \
163 (sizeof (x) == sizeof (float) ? \
164 isinff (x) \
165 : sizeof (x) == sizeof (double) ? \
166 isinf (x) : isinfl (x))
170 Test if Floating-Point stack hasn't changed
172 static void
173 fpstack_test (const char *test_name)
175 #ifdef i386
176 static int old_stack;
177 int sw;
178 asm ("fnstsw":"=a" (sw));
179 sw >>= 11;
180 sw &= 7;
181 if (sw != old_stack)
183 printf ("FP-Stack wrong after test %s\n", test_name);
184 if (verbose > 2)
185 printf ("=======> stack = %d\n", sw);
186 ++noErrors;
187 old_stack = sw;
189 #endif
194 Get a random value x with min_value < x < max_value
195 and min_value, max_value finite,
196 max_value and min_value shouldn't be too close together
198 static MATHTYPE
199 random_value (MATHTYPE min_value, MATHTYPE max_value)
201 int r;
202 MATHTYPE x;
204 r = rand ();
206 x = (max_value - min_value) / RAND_MAX * (MATHTYPE) r + min_value;
208 if ((x <= min_value) || (x >= max_value) || !isfinite (x))
209 x = (max_value - min_value) / 2 + min_value;
211 /* Make sure the RNG has no influence on the exceptions. */
212 feclearexcept (FE_ALL_EXCEPT);
214 return x;
217 /* Get a random value x with x > min_value. */
218 static MATHTYPE
219 random_greater (MATHTYPE min_value)
221 return random_value (min_value, 1e6); /* CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX) */
224 /* Get a random value x with x < max_value. */
225 static MATHTYPE
226 random_less (MATHTYPE max_value)
228 return random_value (-1e6, max_value);
232 static void
233 output_new_test (const char *test_name)
235 if (verbose > 2)
236 printf ("\nTesting: %s\n", test_name);
240 static void
241 output_pass_value (void)
243 if (verbose > 2)
244 printf ("Pass: Value Ok.\n");
248 static void
249 output_fail_value (const char * test_name)
251 if (verbose > 0 && verbose < 3)
252 printf ("Fail: %s\n", test_name);
253 if (verbose >= 3)
254 printf ("Fail:\n");
258 /* Test whether a given exception was raised. */
259 static void
260 test_single_exception (const char *test_name,
261 short int exception,
262 short int exc_flag,
263 int fe_flag,
264 const char *flag_name)
266 #ifndef TEST_INLINE
267 if (exception & exc_flag)
269 if (fetestexcept (fe_flag))
271 if (verbose > 3)
272 printf ("Pass: Exception \"%s\" set\n", flag_name);
274 else
276 if (verbose && verbose < 3)
277 printf ("Fail: %s: Exception \"%s\" not set\n",
278 test_name, flag_name);
279 if (verbose >= 3)
280 printf ("Fail: Exception \"%s\" not set\n",
281 flag_name);
282 ++noErrors;
285 else
287 if (fetestexcept (fe_flag))
289 if (verbose && verbose < 3)
290 printf ("Fail: %s: Exception \"%s\" set\n",
291 test_name, flag_name);
292 if (verbose >= 3)
293 printf ("Fail: Exception \"%s\" set\n",
294 flag_name);
295 ++noErrors;
297 else
299 if (verbose > 3)
300 printf ("Pass: Exception \"%s\" not set\n",
301 flag_name);
304 #endif
308 /* Test whether exception given by EXCEPTION are raised. */
309 static void
310 test_not_exception (const char *test_name, short int exception)
312 ++noExcTests;
313 #ifdef FE_DIVBYZERO
314 if ((exception & DIVIDE_BY_ZERO_EXCEPTION) == 0)
315 test_single_exception (test_name, exception,
316 DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
317 "Divide by zero");
318 #endif
319 #ifdef FE_INVALID
320 if ((exception & INVALID_EXCEPTION) == 0)
321 test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
322 "Invalid operation");
323 #endif
324 feclearexcept (FE_ALL_EXCEPT);
328 /* Test whether exceptions given by EXCEPTION are raised. */
329 static void
330 test_exceptions (const char *test_name, short int exception)
332 ++noExcTests;
333 #ifdef FE_DIVBYZERO
334 test_single_exception (test_name, exception,
335 DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
336 "Divide by zero");
337 #endif
338 #ifdef FE_INVALID
339 test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
340 "Invalid operation");
341 #endif
342 feclearexcept (FE_ALL_EXCEPT);
346 /* Test if two floating point numbers are equal. */
347 static int
348 check_equal (MATHTYPE computed, MATHTYPE supplied, MATHTYPE eps, MATHTYPE * diff)
350 int ret_value;
352 /* Both plus Infinity or both minus infinity. */
353 if (ISINF (computed) && (ISINF (computed) == ISINF (supplied)))
354 return 1;
356 if (isnan (computed) && isnan (supplied)) /* isnan works for all types */
357 return 1;
359 *diff = FUNC(fabs) (computed - supplied);
362 ret_value = (*diff <= eps &&
363 (signbit (computed) == signbit (supplied) || eps != 0.0));
365 /* Make sure the subtraction/comparison have no influence on the exceptions. */
366 feclearexcept (FE_ALL_EXCEPT);
368 return ret_value;
373 static void
374 output_result_bool (const char *test_name, int result)
376 ++noTests;
377 if (result)
379 output_pass_value ();
381 else
383 output_fail_value (test_name);
384 if (verbose > 1)
385 printf (" Value: %d\n", result);
386 ++noErrors;
389 fpstack_test (test_name);
393 static void
394 output_isvalue (const char *test_name, int result,
395 MATHTYPE value)
397 ++noTests;
398 if (result)
400 output_pass_value ();
402 else
404 output_fail_value (test_name);
405 if (verbose > 1)
406 printf (" Value: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
407 value, value);
408 ++noErrors;
411 fpstack_test (test_name);
415 static void
416 output_isvalue_ext (const char *test_name, int result,
417 MATHTYPE value, MATHTYPE parameter)
419 ++noTests;
420 if (result)
422 output_pass_value ();
424 else
426 output_fail_value (test_name);
427 if (verbose > 1)
429 printf (" Value: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
430 value, value);
431 printf (" Parameter: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
432 parameter, parameter);
434 noErrors++;
437 fpstack_test (test_name);
441 static void
442 output_result (const char *test_name, int result,
443 MATHTYPE computed, MATHTYPE expected,
444 MATHTYPE difference,
445 int print_values, int print_diff)
447 ++noTests;
448 if (result)
450 output_pass_value ();
452 else
454 output_fail_value (test_name);
455 if (verbose > 1 && print_values)
457 printf ("Result:\n");
458 printf (" is: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
459 computed, computed);
460 printf (" should be: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
461 expected, expected);
462 if (print_diff)
463 printf (" difference: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR
464 "\n", difference, difference);
466 ++noErrors;
469 fpstack_test (test_name);
473 static void
474 output_result_ext (const char *test_name, int result,
475 MATHTYPE computed, MATHTYPE expected,
476 MATHTYPE difference,
477 MATHTYPE parameter,
478 int print_values, int print_diff)
480 ++noTests;
481 if (result)
483 output_pass_value ();
485 else
487 output_fail_value (test_name);
488 if (verbose > 1 && print_values)
490 printf ("Result:\n");
491 printf (" is: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
492 computed, computed);
493 printf (" should be: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
494 expected, expected);
495 if (print_diff)
496 printf (" difference: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR
497 "\n", difference, difference);
498 printf ("Parameter: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
499 parameter, parameter);
501 ++noErrors;
504 fpstack_test (test_name);
508 check that computed and expected values are the same
510 static void
511 check (const char *test_name, MATHTYPE computed, MATHTYPE expected)
513 MATHTYPE diff;
514 int result;
516 output_new_test (test_name);
517 test_exceptions (test_name, NO_EXCEPTION);
518 result = check_equal (computed, expected, 0, &diff);
519 output_result (test_name, result,
520 computed, expected, diff, PRINT, PRINT);
525 check that computed and expected values are the same,
526 outputs the parameter to the function
528 static void
529 check_ext (const char *test_name, MATHTYPE computed, MATHTYPE expected,
530 MATHTYPE parameter)
532 MATHTYPE diff;
533 int result;
535 output_new_test (test_name);
536 test_exceptions (test_name, NO_EXCEPTION);
537 result = check_equal (computed, expected, 0, &diff);
538 output_result_ext (test_name, result,
539 computed, expected, diff, parameter, PRINT, PRINT);
544 check that computed and expected values are the same and
545 checks also for exception flags
547 static void
548 check_exc (const char *test_name, MATHTYPE computed, MATHTYPE expected,
549 short exception)
551 MATHTYPE diff;
552 int result;
554 output_new_test (test_name);
555 test_exceptions (test_name, exception);
556 result = check_equal (computed, expected, 0, &diff);
557 output_result (test_name, result,
558 computed, expected, diff, PRINT, PRINT);
562 check that computed and expected values are close enough
564 static void
565 check_eps (const char *test_name, MATHTYPE computed, MATHTYPE expected,
566 MATHTYPE epsilon)
568 MATHTYPE diff;
569 int result;
571 output_new_test (test_name);
572 test_exceptions (test_name, NO_EXCEPTION);
573 result = check_equal (computed, expected, epsilon, &diff);
574 output_result (test_name, result,
575 computed, expected, diff, PRINT, PRINT);
579 check a boolean condition
581 static void
582 check_bool (const char *test_name, int computed)
584 output_new_test (test_name);
585 test_exceptions (test_name, NO_EXCEPTION);
586 output_result_bool (test_name, computed);
592 check that computed and expected values are equal (int values)
594 static void
595 check_int (const char *test_name, int computed, int expected)
597 int diff = computed - expected;
598 int result = diff == 0;
600 output_new_test (test_name);
601 test_exceptions (test_name, NO_EXCEPTION);
603 if (result)
605 output_pass_value ();
607 else
609 output_fail_value (test_name);
610 if (verbose > 1)
612 printf ("Result:\n");
613 printf (" is: %d\n", computed);
614 printf (" should be: %d\n", expected);
616 noErrors++;
619 fpstack_test (test_name);
624 check that computed and expected values are equal (long int values)
626 static void
627 check_long (const char *test_name, long int computed, long int expected)
629 long int diff = computed - expected;
630 int result = diff == 0;
632 ++noTests;
633 output_new_test (test_name);
634 test_exceptions (test_name, NO_EXCEPTION);
636 if (result)
638 output_pass_value ();
640 else
642 output_fail_value (test_name);
643 if (verbose > 1)
645 printf ("Result:\n");
646 printf (" is: %ld\n", computed);
647 printf (" should be: %ld\n", expected);
649 noErrors++;
652 fpstack_test (test_name);
656 check that computed and expected values are equal (long long int values)
658 static void
659 check_longlong (const char *test_name, long long int computed,
660 long long int expected)
662 long long int diff = computed - expected;
663 int result = diff == 0;
665 ++noTests;
666 output_new_test (test_name);
667 test_exceptions (test_name, NO_EXCEPTION);
669 if (result)
671 output_pass_value ();
673 else
675 output_fail_value (test_name);
676 if (verbose > 1)
678 printf ("Result:\n");
679 printf (" is: %lld\n", computed);
680 printf (" should be: %lld\n", expected);
682 noErrors++;
685 fpstack_test (test_name);
689 check that computed value is not-a-number
691 static void
692 check_isnan (const char *test_name, MATHTYPE computed)
694 output_new_test (test_name);
695 test_exceptions (test_name, NO_EXCEPTION);
696 output_isvalue (test_name, isnan (computed), computed);
701 check that computed value is not-a-number and test for exceptions
703 static void
704 check_isnan_exc (const char *test_name, MATHTYPE computed,
705 short exception)
707 output_new_test (test_name);
708 test_exceptions (test_name, exception);
709 output_isvalue (test_name, isnan (computed), computed);
714 check that computed value is not-a-number and test for exceptions
716 static void
717 check_isnan_maybe_exc (const char *test_name, MATHTYPE computed,
718 short exception)
720 output_new_test (test_name);
721 test_not_exception (test_name, exception);
722 output_isvalue (test_name, isnan (computed), computed);
726 check that computed value is not-a-number and supply parameter
728 #ifndef TEST_INLINE
729 static void
730 check_isnan_ext (const char *test_name, MATHTYPE computed,
731 MATHTYPE parameter)
733 output_new_test (test_name);
734 test_exceptions (test_name, NO_EXCEPTION);
735 output_isvalue_ext (test_name, isnan (computed), computed, parameter);
737 #endif
740 check that computed value is not-a-number, test for exceptions
741 and supply parameter
743 static void
744 check_isnan_exc_ext (const char *test_name, MATHTYPE computed,
745 short exception, MATHTYPE parameter)
747 output_new_test (test_name);
748 test_exceptions (test_name,exception);
749 output_isvalue_ext (test_name, isnan (computed), computed, parameter);
753 /* Tests if computed is +Inf */
754 static void
755 check_isinfp (const char *test_name, MATHTYPE computed)
757 output_new_test (test_name);
758 test_exceptions (test_name, NO_EXCEPTION);
759 output_isvalue (test_name, (ISINF (computed) == +1), computed);
763 static void
764 check_isinfp_ext (const char *test_name, MATHTYPE computed,
765 MATHTYPE parameter)
767 output_new_test (test_name);
768 test_exceptions (test_name, NO_EXCEPTION);
769 output_isvalue_ext (test_name, (ISINF (computed) == +1), computed, parameter);
773 /* Tests if computed is +Inf */
774 static void
775 check_isinfp_exc (const char *test_name, MATHTYPE computed,
776 int exception)
778 output_new_test (test_name);
779 test_exceptions (test_name, exception);
780 output_isvalue (test_name, (ISINF (computed) == +1), computed);
783 /* Tests if computed is -Inf */
784 static void
785 check_isinfn (const char *test_name, MATHTYPE computed)
787 output_new_test (test_name);
788 test_exceptions (test_name, NO_EXCEPTION);
789 output_isvalue (test_name, (ISINF (computed) == -1), computed);
793 #ifndef TEST_INLINE
794 static void
795 check_isinfn_ext (const char *test_name, MATHTYPE computed,
796 MATHTYPE parameter)
798 output_new_test (test_name);
799 test_exceptions (test_name, NO_EXCEPTION);
800 output_isvalue_ext (test_name, (ISINF (computed) == -1), computed, parameter);
802 #endif
805 /* Tests if computed is -Inf */
806 static void
807 check_isinfn_exc (const char *test_name, MATHTYPE computed,
808 int exception)
810 output_new_test (test_name);
811 test_exceptions (test_name, exception);
812 output_isvalue (test_name, (ISINF (computed) == -1), computed);
816 /* This is to prevent messages from the SVID libm emulation. */
818 matherr (struct exception *x __attribute__ ((unused)))
820 return 1;
824 /****************************************************************************
825 Test for single functions of libm
826 ****************************************************************************/
828 static void
829 acos_test (void)
831 #ifndef TEST_INLINE
832 MATHTYPE x;
834 x = random_greater (1);
835 check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
836 FUNC(acos) (x),
837 INVALID_EXCEPTION);
839 x = random_less (1);
840 check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
841 FUNC(acos) (x),
842 INVALID_EXCEPTION);
843 #endif
844 check ("acos (0) == pi/2", FUNC(acos) (0), M_PI_2l);
845 check ("acos (-0) == pi/2", FUNC(acos) (minus_zero), M_PI_2l);
847 check ("acos (1) == 0", FUNC(acos) (1), 0);
848 check ("acos (-1) == pi", FUNC(acos) (-1), M_PIl);
850 check_eps ("acos (0.5) == pi/3", FUNC(acos) (0.5), M_PI_6l * 2.0,
851 CHOOSE (1e-18, 0, 0));
852 check_eps ("acos (-0.5) == 2*pi/3", FUNC(acos) (-0.5), M_PI_6l * 4.0,
853 CHOOSE (1e-17, 0, 0));
855 check_eps ("acos (0.7) == 0.795398830...", FUNC(acos) (0.7),
856 0.7953988301841435554L, CHOOSE(7e-17L, 0, 0));
861 static void
862 acosh_test (void)
864 #ifndef TEST_INLINE
865 MATHTYPE x;
867 check_isinfp ("acosh(+inf) == +inf", FUNC(acosh) (plus_infty));
869 x = random_less (1);
870 check_isnan_exc ("acosh(x) == NaN plus invalid exception if x < 1",
871 FUNC(acosh) (x), INVALID_EXCEPTION);
872 #endif
874 check ("acosh(1) == 0", FUNC(acosh) (1), 0);
875 check_eps ("acosh(7) == 2.633915793...", FUNC(acosh) (7),
876 2.6339157938496334172L, CHOOSE (3e-19, 0, 0));
880 static void
881 asin_test (void)
883 #ifndef TEST_INLINE
884 MATHTYPE x;
886 x = random_greater (1);
887 check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
888 FUNC(asin) (x),
889 INVALID_EXCEPTION);
891 x = random_less (1);
892 check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
893 FUNC(asin) (x),
894 INVALID_EXCEPTION);
895 #endif
897 check ("asin (0) == 0", FUNC(asin) (0), 0);
898 check ("asin (-0) == -0", FUNC(asin) (minus_zero), minus_zero);
899 check_eps ("asin (0.5) == pi/6", FUNC(asin) (0.5), M_PI_6l,
900 CHOOSE(3.5e-18, 0, 2e-7));
901 check_eps ("asin (-0.5) == -pi/6", FUNC(asin) (-0.5), -M_PI_6l,
902 CHOOSE(3.5e-18, 0, 2e-7));
903 check ("asin (1.0) == pi/2", FUNC(asin) (1.0), M_PI_2l);
904 check ("asin (-1.0) == -pi/2", FUNC(asin) (-1.0), -M_PI_2l);
905 check_eps ("asin (0.7) == 0.775397496...", FUNC(asin) (0.7),
906 0.7753974966107530637L, CHOOSE(7e-17L, 2e-16, 2e-7));
910 static void
911 asinh_test (void)
914 check ("asinh(+0) == +0", FUNC(asinh) (0), 0);
915 #ifndef TEST_INLINE
916 check ("asinh(-0) == -0", FUNC(asinh) (minus_zero), minus_zero);
917 check_isinfp ("asinh(+inf) == +inf", FUNC(asinh) (plus_infty));
918 check_isinfn ("asinh(-inf) == -inf", FUNC(asinh) (minus_infty));
919 #endif
920 check_eps ("asinh(0.7) == 0.652666566...", FUNC(asinh) (0.7),
921 0.652666566082355786L, CHOOSE(4e-17L, 0, 6e-8));
926 static void
927 atan_test (void)
929 check ("atan (0) == 0", FUNC(atan) (0), 0);
930 check ("atan (-0) == -0", FUNC(atan) (minus_zero), minus_zero);
932 check ("atan (+inf) == pi/2", FUNC(atan) (plus_infty), M_PI_2l);
933 check ("atan (-inf) == -pi/2", FUNC(atan) (minus_infty), -M_PI_2l);
935 check_eps ("atan (1) == pi/4", FUNC(atan) (1), M_PI_4l,
936 CHOOSE (1e-18, 0, 0));
937 check_eps ("atan (-1) == -pi/4", FUNC(atan) (1), M_PI_4l,
938 CHOOSE (1e-18, 0, 0));
940 check_eps ("atan (0.7) == 0.610725964...", FUNC(atan) (0.7),
941 0.6107259643892086165L, CHOOSE(3e-17L, 0, 0));
945 static void
946 atan2_test (void)
948 MATHTYPE x;
950 x = random_greater (0);
951 check ("atan2 (0,x) == 0 for x > 0",
952 FUNC(atan2) (0, x), 0);
953 x = random_greater (0);
954 check ("atan2 (-0,x) == -0 for x > 0",
955 FUNC(atan2) (minus_zero, x), minus_zero);
957 check ("atan2 (+0,+0) == +0", FUNC(atan2) (0, 0), 0);
958 check ("atan2 (-0,+0) == -0", FUNC(atan2) (minus_zero, 0), minus_zero);
960 x = -random_greater (0);
961 check ("atan2 (+0,x) == +pi for x < 0", FUNC(atan2) (0, x), M_PIl);
963 x = -random_greater (0);
964 check ("atan2 (-0,x) == -pi for x < 0", FUNC(atan2) (minus_zero, x), -M_PIl);
966 check ("atan2 (+0,-0) == +pi", FUNC(atan2) (0, minus_zero), M_PIl);
967 check ("atan2 (-0,-0) == -pi", FUNC(atan2) (minus_zero, minus_zero), -M_PIl);
969 x = random_greater (0);
970 check ("atan2 (y,+0) == pi/2 for y > 0", FUNC(atan2) (x, 0), M_PI_2l);
972 x = random_greater (0);
973 check ("atan2 (y,-0) == pi/2 for y > 0", FUNC(atan2) (x, minus_zero),
974 M_PI_2l);
976 x = random_less (0);
977 check ("atan2 (y,+0) == -pi/2 for y < 0", FUNC(atan2) (x, 0), -M_PI_2l);
979 x = random_less (0);
980 check ("atan2 (y,-0) == -pi/2 for y < 0", FUNC(atan2) (x, minus_zero),
981 -M_PI_2l);
983 x = random_greater (0);
984 check ("atan2 (y,inf) == +0 for finite y > 0",
985 FUNC(atan2) (x, plus_infty), 0);
987 x = -random_greater (0);
988 check ("atan2 (y,inf) == -0 for finite y < 0",
989 FUNC(atan2) (x, plus_infty), minus_zero);
991 x = random_value (-1e4, 1e4);
992 check ("atan2(+inf, x) == pi/2 for finite x",
993 FUNC(atan2) (plus_infty, x), M_PI_2l);
995 x = random_value (-1e4, 1e4);
996 check ("atan2(-inf, x) == -pi/2 for finite x",
997 FUNC(atan2) (minus_infty, x), -M_PI_2l);
999 x = random_greater (0);
1000 check ("atan2 (y,-inf) == +pi for finite y > 0",
1001 FUNC(atan2) (x, minus_infty), M_PIl);
1003 x = -random_greater (0);
1004 check ("atan2 (y,-inf) == -pi for finite y < 0",
1005 FUNC(atan2) (x, minus_infty), -M_PIl);
1007 check ("atan2 (+inf,+inf) == +pi/4",
1008 FUNC(atan2) (plus_infty, plus_infty), M_PI_4l);
1010 check ("atan2 (-inf,+inf) == -pi/4",
1011 FUNC(atan2) (minus_infty, plus_infty), -M_PI_4l);
1013 check ("atan2 (+inf,-inf) == +3*pi/4",
1014 FUNC(atan2) (plus_infty, minus_infty), 3 * M_PI_4l);
1016 check ("atan2 (-inf,-inf) == -3*pi/4",
1017 FUNC(atan2) (minus_infty, minus_infty), -3 * M_PI_4l);
1019 /* FIXME: Add some specific tests */
1020 check_eps ("atan2 (0.7,1) == 0.61072...", FUNC(atan2) (0.7,1),
1021 0.6107259643892086165L, CHOOSE(3e-17L, 0, 0));
1022 check_eps ("atan2 (0.4,0.0003) == 1.57004...", FUNC(atan2) (0.4, 0.0003),
1023 1.5700463269355215718L, CHOOSE(2e-19L, 0, 0));
1028 static void
1029 atanh_test (void)
1031 #ifndef TEST_INLINE
1032 MATHTYPE x;
1033 #endif
1035 check ("atanh(+0) == +0", FUNC(atanh) (0), 0);
1036 #ifndef TEST_INLINE
1037 check ("atanh(-0) == -0", FUNC(atanh) (minus_zero), minus_zero);
1039 check_isinfp_exc ("atanh(+1) == +inf plus divide-by-zero exception",
1040 FUNC(atanh) (1), DIVIDE_BY_ZERO_EXCEPTION);
1041 check_isinfn_exc ("atanh(-1) == -inf plus divide-by-zero exception",
1042 FUNC(atanh) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1044 x = random_greater (1.0);
1045 check_isnan_exc_ext ("atanh (x) == NaN plus invalid exception if |x| > 1",
1046 FUNC(atanh) (x), INVALID_EXCEPTION, x);
1048 x = random_less (1.0);
1049 check_isnan_exc_ext ("atanh (x) == NaN plus invalid exception if |x| > 1",
1050 FUNC(atanh) (x), INVALID_EXCEPTION, x);
1052 #endif
1053 check_eps ("atanh(0.7) == 0.867300527...", FUNC(atanh) (0.7),
1054 0.8673005276940531944L, CHOOSE(9e-17L, 2e-16, 0));
1058 static void
1059 cbrt_test (void)
1061 check ("cbrt (+0) == +0", FUNC(cbrt) (0.0), 0.0);
1062 check ("cbrt (-0) == -0", FUNC(cbrt) (minus_zero), minus_zero);
1064 #ifndef TEST_INLINE
1065 check_isinfp ("cbrt (+inf) == +inf", FUNC(cbrt) (plus_infty));
1066 check_isinfn ("cbrt (-inf) == -inf", FUNC(cbrt) (minus_infty));
1067 check_isnan ("cbrt (NaN) == NaN", FUNC(cbrt) (nan_value));
1068 #endif
1069 check_eps ("cbrt (-0.001) == -0.1", FUNC(cbrt) (-0.001), -0.1,
1070 CHOOSE (5e-18L, 0, 0));
1071 check_eps ("cbrt (8) == 2", FUNC(cbrt) (8), 2, CHOOSE (5e-17L, 0, 0));
1072 check_eps ("cbrt (-27) == -3", FUNC(cbrt) (-27.0), -3.0,
1073 CHOOSE (3e-16L, 5e-16, 0));
1074 check_eps ("cbrt (0.970299) == 0.99", FUNC(cbrt) (0.970299), 0.99,
1075 CHOOSE (2e-17L, 2e-16, 0));
1076 check_eps ("cbrt (0.7) == .8879040017...", FUNC(cbrt) (0.7),
1077 0.8879040017426007084L, CHOOSE(2e-17L, 6e-16, 0));
1082 static void
1083 ceil_test (void)
1085 check ("ceil (+0) == +0", FUNC(ceil) (0.0), 0.0);
1086 check ("ceil (-0) == -0", FUNC(ceil) (minus_zero), minus_zero);
1087 check_isinfp ("ceil (+inf) == +inf", FUNC(ceil) (plus_infty));
1088 check_isinfn ("ceil (-inf) == -inf", FUNC(ceil) (minus_infty));
1090 check ("ceil (pi) == 4", FUNC(ceil) (M_PIl), 4.0);
1091 check ("ceil (-pi) == -3", FUNC(ceil) (-M_PIl), -3.0);
1095 static void
1096 cos_test (void)
1099 check ("cos (+0) == 1", FUNC(cos) (0), 1);
1100 check ("cos (-0) == 1", FUNC(cos) (minus_zero), 1);
1101 check_isnan_exc ("cos (+inf) == NaN plus invalid exception",
1102 FUNC(cos) (plus_infty),
1103 INVALID_EXCEPTION);
1104 check_isnan_exc ("cos (-inf) == NaN plus invalid exception",
1105 FUNC(cos) (minus_infty),
1106 INVALID_EXCEPTION);
1108 check_eps ("cos (pi/3) == 0.5", FUNC(cos) (M_PI_6l * 2.0),
1109 0.5, CHOOSE (4e-18L, 1e-15L, 1e-7L));
1110 check_eps ("cos (2*pi/3) == -0.5", FUNC(cos) (M_PI_6l * 4.0),
1111 -0.5, CHOOSE (4e-18L, 1e-15L, 1e-7L));
1112 check_eps ("cos (pi/2) == 0", FUNC(cos) (M_PI_2l),
1113 0, CHOOSE (1e-19L, 1e-16L, 1e-7L));
1115 check_eps ("cos (0.7) == 0.7648421872...", FUNC(cos) (0.7),
1116 0.7648421872844884262L, CHOOSE(3e-17, 2e-16, 6e-8));
1119 static void
1120 cosh_test (void)
1122 check ("cosh (+0) == 1", FUNC(cosh) (0), 1);
1123 check ("cosh (-0) == 1", FUNC(cosh) (minus_zero), 1);
1125 #ifndef TEST_INLINE
1126 check_isinfp ("cosh (+inf) == +inf", FUNC(cosh) (plus_infty));
1127 check_isinfp ("cosh (-inf) == +inf", FUNC(cosh) (minus_infty));
1128 #endif
1130 check_eps ("cosh (0.7) == 1.2551690056...", FUNC(cosh) (0.7),
1131 1.255169005630943018L, CHOOSE(4e-17L, 0, 0));
1135 static void
1136 erf_test (void)
1138 errno = 0;
1139 FUNC(erf) (0);
1140 if (errno == ENOSYS)
1141 /* Function not implemented. */
1142 return;
1144 check ("erf (+0) == +0", FUNC(erf) (0), 0);
1145 check ("erf (-0) == -0", FUNC(erf) (minus_zero), minus_zero);
1146 check ("erf (+inf) == +1", FUNC(erf) (plus_infty), 1);
1147 check ("erf (-inf) == -1", FUNC(erf) (minus_infty), -1);
1149 check_eps ("erf (0.7) == 0.6778011938...", FUNC(erf) (0.7),
1150 0.67780119383741847297L, CHOOSE(0, 2e-16, 0));
1154 static void
1155 erfc_test (void)
1157 errno = 0;
1158 FUNC(erfc) (0);
1159 if (errno == ENOSYS)
1160 /* Function not implemented. */
1161 return;
1163 check ("erfc (+inf) == 0", FUNC(erfc) (plus_infty), 0.0);
1164 check ("erfc (-inf) == 2", FUNC(erfc) (minus_infty), 2.0);
1165 check ("erfc (+0) == 1", FUNC(erfc) (0.0), 1.0);
1166 check ("erfc (-0) == 1", FUNC(erfc) (minus_zero), 1.0);
1168 check_eps ("erfc (0.7) == 0.3221988061...", FUNC(erfc) (0.7),
1169 0.32219880616258152702L, CHOOSE(0, 6e-17, 0));
1173 static void
1174 exp_test (void)
1176 check ("exp (+0) == 1", FUNC(exp) (0), 1);
1177 check ("exp (-0) == 1", FUNC(exp) (minus_zero), 1);
1179 #ifndef TEST_INLINE
1180 check_isinfp ("exp (+inf) == +inf", FUNC(exp) (plus_infty));
1181 check ("exp (-inf) == 0", FUNC(exp) (minus_infty), 0);
1182 #endif
1183 check_eps ("exp (1) == e", FUNC(exp) (1), M_El, CHOOSE (4e-18L, 0, 0));
1185 check_eps ("exp (2) == e^2", FUNC(exp) (2), M_E2l,
1186 CHOOSE (1e-18, 0, 0));
1187 check_eps ("exp (3) == e^3", FUNC(exp) (3), M_E3l,
1188 CHOOSE (1.5e-17, 0, 0));
1189 check_eps ("exp (0.7) == 2.0137527074...", FUNC(exp) (0.7),
1190 2.0137527074704765216L, CHOOSE(9e-17L, 0, 0));
1194 static void
1195 exp10_test (void)
1197 errno = 0;
1198 FUNC(exp10) (0);
1199 if (errno == ENOSYS)
1200 /* Function not implemented. */
1201 return;
1203 check ("exp10 (+0) == 1", FUNC(exp10) (0), 1);
1204 check ("exp10 (-0) == 1", FUNC(exp10) (minus_zero), 1);
1206 check_isinfp ("exp10 (+inf) == +inf", FUNC(exp10) (plus_infty));
1207 check ("exp10 (-inf) == 0", FUNC(exp10) (minus_infty), 0);
1208 check_eps ("exp10 (3) == 1000", FUNC(exp10) (3), 1000,
1209 CHOOSE(5e-16, 7e-13, 2e-4));
1210 check_eps ("exp10 (-1) == 0.1", FUNC(exp10) (-1), 0.1,
1211 CHOOSE(6e-18, 3e-17, 8e-09));
1212 check_isinfp ("exp10 (1e6) == +inf", FUNC(exp10) (1e6));
1213 check ("exp10 (-1e6) == 0", FUNC(exp10) (-1e6), 0);
1214 check_eps ("exp10 (0.7) == 5.0118723...", FUNC(exp10) (0.7),
1215 5.0118723362727228500L, CHOOSE(6e-16, 9e-16, 5e-7));
1219 static void
1220 exp2_test (void)
1222 errno = 0;
1223 FUNC(exp2) (0);
1224 if (errno == ENOSYS)
1225 /* Function not implemented. */
1226 return;
1228 check ("exp2 (+0) == 1", FUNC(exp2) (0), 1);
1229 check ("exp2 (-0) == 1", FUNC(exp2) (minus_zero), 1);
1231 check_isinfp ("exp2 (+inf) == +inf", FUNC(exp2) (plus_infty));
1232 check ("exp2 (-inf) == 0", FUNC(exp2) (minus_infty), 0);
1233 check ("exp2 (10) == 1024", FUNC(exp2) (10), 1024);
1234 check ("exp2 (-1) == 0.5", FUNC(exp2) (-1), 0.5);
1235 check_isinfp ("exp2 (1e6) == +inf", FUNC(exp2) (1e6));
1236 check ("exp2 (-1e6) == 0", FUNC(exp2) (-1e6), 0);
1237 check_eps ("exp2 (0.7) == 1.6245047927...", FUNC(exp2) (0.7),
1238 1.6245047927124710452L, CHOOSE(6e-17L, 0, 6e-8));
1242 static void
1243 expm1_test (void)
1245 check ("expm1 (+0) == 0", FUNC(expm1) (0), 0);
1246 #ifndef TEST_INLINE
1247 check ("expm1 (-0) == -0", FUNC(expm1) (minus_zero), minus_zero);
1249 check_isinfp ("expm1 (+inf) == +inf", FUNC(expm1) (plus_infty));
1250 check ("expm1 (-inf) == -1", FUNC(expm1) (minus_infty), -1);
1251 #endif
1253 check_eps ("expm1 (1) == e-1", FUNC(expm1) (1), M_El - 1.0,
1254 CHOOSE (4e-18L, 0, 2e-7));
1256 check_eps ("expm1 (0.7) == 1.01375...", FUNC(expm1) (0.7),
1257 1.0137527074704765216L, CHOOSE(9e-17L, 0, 0));
1263 static void
1264 check_frexp (const char *test_name, MATHTYPE computed, MATHTYPE expected,
1265 int comp_int, int exp_int)
1267 MATHTYPE diff;
1268 int result;
1270 result = (check_equal (computed, expected, 0, &diff)
1271 && (comp_int == exp_int));
1273 if (result)
1275 if (verbose > 2)
1276 printf ("Pass: %s\n", test_name);
1278 else
1280 if (verbose)
1281 printf ("Fail: %s\n", test_name);
1282 if (verbose > 1)
1284 printf ("Result:\n");
1285 printf (" is: %.20" PRINTF_EXPR " *2^%d %.20"
1286 PRINTF_XEXPR "*2^%d\n",
1287 computed, comp_int, computed, comp_int);
1288 printf (" should be: %.20" PRINTF_EXPR " *2^%d %.20"
1289 PRINTF_XEXPR "*2^%d\n",
1290 expected, exp_int, expected, exp_int);
1291 printf (" difference: %.20" PRINTF_EXPR " %.20" PRINTF_XEXPR "\n",
1292 diff, diff);
1294 noErrors++;
1296 fpstack_test (test_name);
1297 output_result (test_name, result,
1298 computed, expected, diff, PRINT, PRINT);
1302 static void
1303 frexp_test (void)
1305 int x_int;
1306 MATHTYPE result;
1308 result = FUNC(frexp) (plus_infty, &x_int);
1309 check_isinfp ("frexp (+inf, expr) == +inf", result);
1311 result = FUNC(frexp) (minus_infty, &x_int);
1312 check_isinfn ("frexp (-inf, expr) == -inf", result);
1314 result = FUNC(frexp) (nan_value, &x_int);
1315 check_isnan ("frexp (Nan, expr) == NaN", result);
1317 result = FUNC(frexp) (0, &x_int);
1318 check_frexp ("frexp: +0 == 0 * 2^0", result, 0, x_int, 0);
1320 result = FUNC(frexp) (minus_zero, &x_int);
1321 check_frexp ("frexp: -0 == -0 * 2^0", result, minus_zero, x_int, 0);
1323 result = FUNC(frexp) (12.8L, &x_int);
1324 check_frexp ("frexp: 12.8 == 0.8 * 2^4", result, 0.8L, x_int, 4);
1326 result = FUNC(frexp) (-27.34L, &x_int);
1327 check_frexp ("frexp: -27.34 == -0.854375 * 2^5", result, -0.854375L, x_int, 5);
1332 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)
1333 /* All floating-point numbers can be put in one of these categories. */
1334 enum
1336 FP_NAN,
1337 #define FP_NAN FP_NAN
1338 FP_INFINITE,
1339 #define FP_INFINITE FP_INFINITE
1340 FP_ZERO,
1341 #define FP_ZERO FP_ZERO
1342 FP_SUBNORMAL,
1343 #define FP_SUBNORMAL FP_SUBNORMAL
1344 FP_NORMAL
1345 #define FP_NORMAL FP_NORMAL
1347 #endif
1350 static void
1351 fpclassify_test (void)
1353 MATHTYPE x;
1355 /* fpclassify is a macro, don't give it constants as parameter */
1356 check_bool ("fpclassify (NaN) == FP_NAN", fpclassify (nan_value) == FP_NAN);
1357 check_bool ("fpclassify (+inf) == FP_INFINITE",
1358 fpclassify (plus_infty) == FP_INFINITE);
1359 check_bool ("fpclassify (-inf) == FP_INFINITE",
1360 fpclassify (minus_infty) == FP_INFINITE);
1361 check_bool ("fpclassify (+0) == FP_ZERO",
1362 fpclassify (plus_zero) == FP_ZERO);
1363 check_bool ("fpclassify (-0) == FP_ZERO",
1364 fpclassify (minus_zero) == FP_ZERO);
1366 x = 1000.0;
1367 check_bool ("fpclassify (1000) == FP_NORMAL",
1368 fpclassify (x) == FP_NORMAL);
1372 static void
1373 isfinite_test (void)
1375 check_bool ("isfinite (0) != 0", isfinite (0));
1376 check_bool ("isfinite (-0) != 0", isfinite (minus_zero));
1377 check_bool ("isfinite (10) != 0", isfinite (10));
1378 check_bool ("isfinite (+inf) == 0", isfinite (plus_infty) == 0);
1379 check_bool ("isfinite (-inf) == 0", isfinite (minus_infty) == 0);
1380 check_bool ("isfinite (NaN) == 0", isfinite (nan_value) == 0);
1384 static void
1385 isnormal_test (void)
1387 check_bool ("isnormal (0) == 0", isnormal (0) == 0);
1388 check_bool ("isnormal (-0) == 0", isnormal (minus_zero) == 0);
1389 check_bool ("isnormal (10) != 0", isnormal (10));
1390 check_bool ("isnormal (+inf) == 0", isnormal (plus_infty) == 0);
1391 check_bool ("isnormal (-inf) == 0", isnormal (minus_infty) == 0);
1392 check_bool ("isnormal (NaN) == 0", isnormal (nan_value) == 0);
1397 static void
1398 signbit_test (void)
1400 MATHTYPE x;
1402 check_bool ("signbit (+0) == 0", signbit (0) == 0);
1403 check_bool ("signbit (-0) != 0", signbit (minus_zero));
1404 check_bool ("signbit (+inf) == 0", signbit (plus_infty) == 0);
1405 check_bool ("signbit (-inf) != 0", signbit (minus_infty));
1407 x = random_less (0);
1408 check_bool ("signbit (x) != 0 for x < 0", signbit (x));
1410 x = random_greater (0);
1411 check_bool ("signbit (x) == 0 for x > 0", signbit (x) == 0);
1416 static void
1417 gamma_test (void)
1419 errno = 0;
1420 FUNC(gamma) (1);
1421 if (errno == ENOSYS)
1422 /* Function not implemented. */
1423 return;
1424 feclearexcept (FE_ALL_EXCEPT);
1427 check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
1428 check_isinfp_exc ("gamma (0) == +inf plus divide by zero exception",
1429 FUNC(gamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1431 check_isinfp_exc ("gamma (x) == +inf plus divide by zero exception for integer x <= 0",
1432 FUNC(gamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1433 check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
1434 FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
1436 signgam = 0;
1437 check ("gamma (1) == 0", FUNC(gamma) (1), 0);
1438 check_int ("gamma (1) sets signgam to 1", signgam, 1);
1440 signgam = 0;
1441 check ("gamma (3) == M_LN2", FUNC(gamma) (3), M_LN2l);
1442 check_int ("gamma (3) sets signgam to 1", signgam, 1);
1444 signgam = 0;
1445 check_eps ("gamma (0.5) == log(sqrt(pi))", FUNC(gamma) (0.5),
1446 FUNC(log) (FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 1e-7));
1447 check_int ("gamma (0.5) sets signgam to 1", signgam, 1);
1449 signgam = 0;
1450 check_eps ("gamma (-0.5) == log(2*sqrt(pi))", FUNC(gamma) (-0.5),
1451 FUNC(log) (2*FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 0));
1453 check_int ("gamma (-0.5) sets signgam to -1", signgam, -1);
1457 static void
1458 tgamma_test (void)
1460 errno = 0;
1461 FUNC(tgamma) (1);
1462 if (errno == ENOSYS)
1463 /* Function not implemented. */
1464 return;
1465 feclearexcept (FE_ALL_EXCEPT);
1468 check_isinfp ("tgamma (+inf) == +inf", FUNC(tgamma) (plus_infty));
1469 check_isnan_exc ("tgamma (0) == NaN plus invalid exception",
1470 FUNC(tgamma) (0), INVALID_EXCEPTION);
1472 check_isnan_exc_ext ("tgamma (x) == NaN plus invalid exception for integer x <= 0",
1473 FUNC(tgamma) (-2), INVALID_EXCEPTION, -2);
1474 check_isnan_exc ("tgamma (-inf) == NaN plus invalid exception",
1475 FUNC(tgamma) (minus_infty), INVALID_EXCEPTION);
1477 #ifdef TODO
1478 check_eps ("tgamma (0.5) == sqrt(pi)", FUNC(tgamma) (0.5),
1479 FUNC(sqrt) (M_PIl), CHOOSE (0, 5e-16, 2e-7));
1480 #endif
1481 check_eps ("tgamma (-0.5) == -2*sqrt(pi)", FUNC(tgamma) (-0.5),
1482 -2*FUNC(sqrt) (M_PIl), CHOOSE (0, 5e-16, 3e-7));
1484 check ("tgamma (1) == 1", FUNC(tgamma) (1), 1);
1485 check ("tgamma (4) == 6", FUNC(tgamma) (4), 6);
1487 check_eps ("tgamma (0.7) == 1.29805...", FUNC(tgamma) (0.7),
1488 1.29805533264755778568L, CHOOSE(0, 3e-16, 2e-7));
1489 check ("tgamma (1.2) == 0.91816...", FUNC(tgamma) (1.2),
1490 0.91816874239976061064L);
1494 static void
1495 lgamma_test (void)
1497 errno = 0;
1498 FUNC(lgamma) (0);
1499 if (errno == ENOSYS)
1500 /* Function not implemented. */
1501 return;
1502 feclearexcept (FE_ALL_EXCEPT);
1504 check_isinfp ("lgamma (+inf) == +inf", FUNC(lgamma) (plus_infty));
1505 check_isinfp_exc ("lgamma (0) == +inf plus divide by zero exception",
1506 FUNC(lgamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1508 check_isinfp_exc ("lgamma (x) == +inf plus divide by zero exception for integer x <= 0",
1509 FUNC(lgamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1510 check_isnan_exc ("lgamma (-inf) == NaN plus invalid exception",
1511 FUNC(lgamma) (minus_infty), INVALID_EXCEPTION);
1513 signgam = 0;
1514 check ("lgamma (1) == 0", FUNC(lgamma) (1), 0);
1515 check_int ("lgamma (0) sets signgam to 1", signgam, 1);
1517 signgam = 0;
1518 check ("lgamma (3) == M_LN2", FUNC(lgamma) (3), M_LN2l);
1519 check_int ("lgamma (3) sets signgam to 1", signgam, 1);
1521 signgam = 0;
1522 check_eps ("lgamma (0.5) == log(sqrt(pi))", FUNC(lgamma) (0.5),
1523 FUNC(log) (FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 1e-7));
1524 check_int ("lgamma (0.5) sets signgam to 1", signgam, 1);
1526 signgam = 0;
1527 check_eps ("lgamma (-0.5) == log(2*sqrt(pi))", FUNC(lgamma) (-0.5),
1528 FUNC(log) (2*FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 0));
1530 check_int ("lgamma (-0.5) sets signgam to -1", signgam, -1);
1532 signgam = 0;
1533 check_eps ("lgamma (0.7) == 0.26086...", FUNC(lgamma) (0.7),
1534 0.26086724653166651439L, CHOOSE(0, 6e-17, 3e-8));
1535 check_int ("lgamma (0.7) sets signgam to 1", signgam, 1);
1537 signgam = 0;
1538 check_eps ("lgamma (1.2) == -0.08537...", FUNC(lgamma) (1.2),
1539 -0.853740900033158497197e-1L, CHOOSE(0, 2e-17, 2e-8));
1540 check_int ("lgamma (1.2) sets signgam to 1", signgam, 1);
1545 static void
1546 ilogb_test (void)
1548 int i;
1550 check_int ("ilogb (1) == 0", FUNC(ilogb) (1), 0);
1551 check_int ("ilogb (e) == 1", FUNC(ilogb) (M_El), 1);
1552 check_int ("ilogb (1024) == 10", FUNC(ilogb) (1024), 10);
1553 check_int ("ilogb (-2000) == 10", FUNC(ilogb) (-2000), 10);
1555 /* XXX We have a problem here: the standard does not tell us whether
1556 exceptions are allowed/required. ignore them for now. */
1557 i = FUNC (ilogb) (0.0);
1558 feclearexcept (FE_ALL_EXCEPT);
1559 check_int ("ilogb (0) == FP_ILOGB0", i, FP_ILOGB0);
1560 i = FUNC(ilogb) (nan_value);
1561 feclearexcept (FE_ALL_EXCEPT);
1562 check_int ("ilogb (NaN) == FP_ILOGBNAN", i, FP_ILOGBNAN);
1567 static void
1568 ldexp_test (void)
1570 MATHTYPE x;
1572 check ("ldexp (0, 0) == 0", FUNC(ldexp) (0, 0), 0);
1574 check_isinfp ("ldexp (+inf, 1) == +inf", FUNC(ldexp) (plus_infty, 1));
1575 check_isinfn ("ldexp (-inf, 1) == -inf", FUNC(ldexp) (minus_infty, 1));
1576 check_isnan ("ldexp (NaN, 1) == NaN", FUNC(ldexp) (nan_value, 1));
1578 check ("ldexp (0.8, 4) == 12.8", FUNC(ldexp) (0.8L, 4), 12.8L);
1579 check ("ldexp (-0.854375, 5) == -27.34", FUNC(ldexp) (-0.854375L, 5), -27.34L);
1581 x = random_greater (0.0);
1582 check_ext ("ldexp (x, 0) == x", FUNC(ldexp) (x, 0L), x, x);
1587 static void
1588 log_test (void)
1590 check_isinfn_exc ("log (+0) == -inf plus divide-by-zero exception",
1591 FUNC(log) (0), DIVIDE_BY_ZERO_EXCEPTION);
1592 check_isinfn_exc ("log (-0) == -inf plus divide-by-zero exception",
1593 FUNC(log) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1595 check ("log (1) == 0", FUNC(log) (1), 0);
1597 check_isnan_exc ("log (x) == NaN plus invalid exception if x < 0",
1598 FUNC(log) (-1), INVALID_EXCEPTION);
1599 check_isinfp ("log (+inf) == +inf", FUNC(log) (plus_infty));
1601 check_eps ("log (e) == 1", FUNC(log) (M_El), 1, CHOOSE (1e-18L, 0, 9e-8L));
1602 check_eps ("log (1/e) == -1", FUNC(log) (1.0 / M_El), -1,
1603 CHOOSE (2e-18L, 0, 0));
1604 check ("log (2) == M_LN2", FUNC(log) (2), M_LN2l);
1605 check_eps ("log (10) == M_LN10", FUNC(log) (10), M_LN10l,
1606 CHOOSE (1e-18L, 0, 0));
1607 check_eps ("log (0.7) == -0.3566749439...", FUNC(log) (0.7),
1608 -0.35667494393873237891L, CHOOSE(7e-17L, 6e-17, 3e-8));
1612 static void
1613 log10_test (void)
1615 check_isinfn_exc ("log10 (+0) == -inf plus divide-by-zero exception",
1616 FUNC(log10) (0), DIVIDE_BY_ZERO_EXCEPTION);
1617 check_isinfn_exc ("log10 (-0) == -inf plus divide-by-zero exception",
1618 FUNC(log10) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1620 check ("log10 (1) == +0", FUNC(log10) (1), 0);
1622 check_isnan_exc ("log10 (x) == NaN plus invalid exception if x < 0",
1623 FUNC(log10) (-1), INVALID_EXCEPTION);
1625 check_isinfp ("log10 (+inf) == +inf", FUNC(log10) (plus_infty));
1627 check_eps ("log10 (0.1) == -1", FUNC(log10) (0.1L), -1,
1628 CHOOSE (1e-18L, 0, 0));
1629 check_eps ("log10 (10) == 1", FUNC(log10) (10.0), 1,
1630 CHOOSE (1e-18L, 0, 0));
1631 check_eps ("log10 (100) == 2", FUNC(log10) (100.0), 2,
1632 CHOOSE (1e-18L, 0, 0));
1633 check ("log10 (10000) == 4", FUNC(log10) (10000.0), 4);
1634 check_eps ("log10 (e) == M_LOG10E", FUNC(log10) (M_El), M_LOG10El,
1635 CHOOSE (1e-18, 0, 9e-8));
1636 check_eps ("log10 (0.7) == -0.1549019599...", FUNC(log10) (0.7),
1637 -0.15490195998574316929L, CHOOSE(3e-17L, 3e-17, 2e-8));
1641 static void
1642 log1p_test (void)
1644 check ("log1p (+0) == +0", FUNC(log1p) (0), 0);
1645 check ("log1p (-0) == -0", FUNC(log1p) (minus_zero), minus_zero);
1647 check_isinfn_exc ("log1p (-1) == -inf plus divide-by-zero exception",
1648 FUNC(log1p) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1649 check_isnan_exc ("log1p (x) == NaN plus invalid exception if x < -1",
1650 FUNC(log1p) (-2), INVALID_EXCEPTION);
1652 check_isinfp ("log1p (+inf) == +inf", FUNC(log1p) (plus_infty));
1654 check_eps ("log1p (e-1) == 1", FUNC(log1p) (M_El - 1.0), 1,
1655 CHOOSE (1e-18L, 0, 6e-8));
1657 check_eps ("log1p (-0.3) == -0.35667...", FUNC(log1p) (-0.3),
1658 -0.35667494393873237891L, CHOOSE(2e-17L, 6e-17, 3e-8));
1662 static void
1663 log2_test (void)
1665 check_isinfn_exc ("log2 (+0) == -inf plus divide-by-zero exception",
1666 FUNC(log2) (0), DIVIDE_BY_ZERO_EXCEPTION);
1667 check_isinfn_exc ("log2 (-0) == -inf plus divide-by-zero exception",
1668 FUNC(log2) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1670 check ("log2 (1) == +0", FUNC(log2) (1), 0);
1672 check_isnan_exc ("log2 (x) == NaN plus invalid exception if x < 0",
1673 FUNC(log2) (-1), INVALID_EXCEPTION);
1675 check_isinfp ("log2 (+inf) == +inf", FUNC(log2) (plus_infty));
1677 check_eps ("log2 (e) == M_LOG2E", FUNC(log2) (M_El), M_LOG2El,
1678 CHOOSE (1e-18L, 0, 0));
1679 check ("log2 (2) == 1", FUNC(log2) (2.0), 1);
1680 check_eps ("log2 (16) == 4", FUNC(log2) (16.0), 4, CHOOSE (1e-18L, 0, 0));
1681 check ("log2 (256) == 8", FUNC(log2) (256.0), 8);
1682 check_eps ("log2 (0.7) == -0.5145731728...", FUNC(log2) (0.7),
1683 -0.51457317282975824043L, CHOOSE(1e-16L, 2e-16, 6e-8));
1688 static void
1689 logb_test (void)
1691 check_isinfp ("logb (+inf) == +inf", FUNC(logb) (plus_infty));
1692 check_isinfp ("logb (-inf) == +inf", FUNC(logb) (minus_infty));
1694 check_isinfn_exc ("logb (+0) == -inf plus divide-by-zero exception",
1695 FUNC(logb) (0), DIVIDE_BY_ZERO_EXCEPTION);
1697 check_isinfn_exc ("logb (-0) == -inf plus divide-by-zero exception",
1698 FUNC(logb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1700 check ("logb (1) == 0", FUNC(logb) (1), 0);
1701 check ("logb (e) == 1", FUNC(logb) (M_El), 1);
1702 check ("logb (1024) == 10", FUNC(logb) (1024), 10);
1703 check ("logb (-2000) == 10", FUNC(logb) (-2000), 10);
1708 static void
1709 modf_test (void)
1711 MATHTYPE result, intpart;
1713 result = FUNC(modf) (plus_infty, &intpart);
1714 check ("modf (+inf, &x) returns +0", result, 0);
1715 check_isinfp ("modf (+inf, &x) set x to +inf", intpart);
1717 result = FUNC(modf) (minus_infty, &intpart);
1718 check ("modf (-inf, &x) returns -0", result, minus_zero);
1719 check_isinfn ("modf (-inf, &x) sets x to -inf", intpart);
1721 result = FUNC(modf) (nan_value, &intpart);
1722 check_isnan ("modf (NaN, &x) returns NaN", result);
1723 check_isnan ("modf (NaN, &x) sets x to NaN", intpart);
1725 result = FUNC(modf) (0, &intpart);
1726 check ("modf (0, &x) returns 0", result, 0);
1727 check ("modf (0, &x) sets x to 0", intpart, 0);
1729 result = FUNC(modf) (minus_zero, &intpart);
1730 check ("modf (-0, &x) returns -0", result, minus_zero);
1731 check ("modf (-0, &x) sets x to -0", intpart, minus_zero);
1733 result = FUNC(modf) (1.5, &intpart);
1734 check ("modf (1.5, &x) returns 0.5", result, 0.5);
1735 check ("modf (1.5, &x) sets x to 1", intpart, 1);
1737 result = FUNC(modf) (2.5, &intpart);
1738 check ("modf (2.5, &x) returns 0.5", result, 0.5);
1739 check ("modf (2.5, &x) sets x to 2", intpart, 2);
1741 result = FUNC(modf) (-2.5, &intpart);
1742 check ("modf (-2.5, &x) returns -0.5", result, -0.5);
1743 check ("modf (-2.5, &x) sets x to -2", intpart, -2);
1745 result = FUNC(modf) (20, &intpart);
1746 check ("modf (20, &x) returns 0", result, 0);
1747 check ("modf (20, &x) sets x to 20", intpart, 20);
1749 result = FUNC(modf) (21, &intpart);
1750 check ("modf (21, &x) returns 0", result, 0);
1751 check ("modf (21, &x) sets x to 21", intpart, 21);
1753 result = FUNC(modf) (89.6, &intpart);
1754 check_eps ("modf (89.6, &x) returns 0.6", result, 0.6,
1755 CHOOSE(6e-15L, 6e-15, 2e-6));
1756 check ("modf (89.6, &x) sets x to 89", intpart, 89);
1760 static void
1761 scalb_test (void)
1763 MATHTYPE x;
1765 check_isnan ("scalb (2, 0.5) == NaN", FUNC(scalb) (2, 0.5));
1766 check_isnan ("scalb (3, -2.5) == NaN", FUNC(scalb) (3, -2.5));
1768 check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1769 check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1771 x = random_greater (0.0);
1772 check ("scalb (x, 0) == 0", FUNC(scalb) (x, 0), x);
1773 x = random_greater (0.0);
1774 check ("scalb (-x, 0) == 0", FUNC(scalb) (-x, 0), -x);
1776 check_isnan_exc ("scalb (+0, +inf) == NaN plus invalid exception",
1777 FUNC(scalb) (0, plus_infty), INVALID_EXCEPTION);
1778 check_isnan_exc ("scalb (-0, +inf) == NaN plus invalid exception",
1779 FUNC(scalb) (minus_zero, plus_infty), INVALID_EXCEPTION);
1781 check ("scalb (+0, 2) == +0", FUNC(scalb) (0, 2), 0);
1782 check ("scalb (-0, 4) == -0", FUNC(scalb) (minus_zero, -4), minus_zero);
1783 check ("scalb (+0, 0) == +0", FUNC(scalb) (0, 0), 0);
1784 check ("scalb (-0, 0) == -0", FUNC(scalb) (minus_zero, 0), minus_zero);
1785 check ("scalb (+0, -1) == +0", FUNC(scalb) (0, -1), 0);
1786 check ("scalb (-0, -10) == -0", FUNC(scalb) (minus_zero, -10), minus_zero);
1787 check ("scalb (+0, -inf) == +0", FUNC(scalb) (0, minus_infty), 0);
1788 check ("scalb (-0, -inf) == -0", FUNC(scalb) (minus_zero, minus_infty),
1789 minus_zero);
1791 check_isinfp ("scalb (+inf, -1) == +inf", FUNC(scalb) (plus_infty, -1));
1792 check_isinfn ("scalb (-inf, -10) == -inf", FUNC(scalb) (minus_infty, -10));
1793 check_isinfp ("scalb (+inf, 0) == +inf", FUNC(scalb) (plus_infty, 0));
1794 check_isinfn ("scalb (-inf, 0) == -inf", FUNC(scalb) (minus_infty, 0));
1795 check_isinfp ("scalb (+inf, 2) == +inf", FUNC(scalb) (plus_infty, 2));
1796 check_isinfn ("scalb (-inf, 100) == -inf", FUNC(scalb) (minus_infty, 100));
1798 x = random_greater (0.0);
1799 check ("scalb (x, -inf) == 0", FUNC(scalb) (x, minus_infty), 0.0);
1800 check ("scalb (-x, -inf) == -0", FUNC(scalb) (-x, minus_infty), minus_zero);
1802 x = random_greater (0.0);
1803 check_isinfp ("scalb (x, +inf) == +inf", FUNC(scalb) (x, plus_infty));
1804 x = random_greater (0.0);
1805 check_isinfn ("scalb (-x, +inf) == -inf", FUNC(scalb) (-x, plus_infty));
1806 check_isinfp ("scalb (+inf, +inf) == +inf",
1807 FUNC(scalb) (plus_infty, plus_infty));
1808 check_isinfn ("scalb (-inf, +inf) == -inf",
1809 FUNC(scalb) (minus_infty, plus_infty));
1811 check_isnan ("scalb (+inf, -inf) == NaN",
1812 FUNC(scalb) (plus_infty, minus_infty));
1813 check_isnan ("scalb (-inf, -inf) == NaN",
1814 FUNC(scalb) (minus_infty, minus_infty));
1816 check_isnan ("scalb (NaN, 1) == NaN", FUNC(scalb) (nan_value, 1));
1817 check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1818 check_isnan ("scalb (NaN, 0) == NaN", FUNC(scalb) (nan_value, 0));
1819 check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1820 check_isnan ("scalb (NaN, +inf) == NaN",
1821 FUNC(scalb) (nan_value, plus_infty));
1822 check_isnan ("scalb (+inf, NaN) == NaN",
1823 FUNC(scalb) (plus_infty, nan_value));
1824 check_isnan ("scalb (NaN, NaN) == NaN", FUNC(scalb) (nan_value, nan_value));
1826 check ("scalb (0.8, 4) == 12.8", FUNC(scalb) (0.8L, 4), 12.8L);
1827 check ("scalb (-0.854375, 5) == -27.34", FUNC(scalb) (-0.854375L, 5), -27.34L);
1831 static void
1832 scalbn_test (void)
1834 MATHTYPE x;
1836 check ("scalbn (0, 0) == 0", FUNC(scalbn) (0, 0), 0);
1838 check_isinfp ("scalbn (+inf, 1) == +inf", FUNC(scalbn) (plus_infty, 1));
1839 check_isinfn ("scalbn (-inf, 1) == -inf", FUNC(scalbn) (minus_infty, 1));
1840 check_isnan ("scalbn (NaN, 1) == NaN", FUNC(scalbn) (nan_value, 1));
1842 check ("scalbn (0.8, 4) == 12.8", FUNC(scalbn) (0.8L, 4), 12.8L);
1843 check ("scalbn (-0.854375, 5) == -27.34", FUNC(scalbn) (-0.854375L, 5), -27.34L);
1845 x = random_greater (0.0);
1846 check_ext ("scalbn (x, 0) == x", FUNC(scalbn) (x, 0L), x, x);
1850 static void
1851 sin_test (void)
1853 check ("sin (+0) == +0", FUNC(sin) (0), 0);
1854 check ("sin (-0) == -0", FUNC(sin) (minus_zero), minus_zero);
1855 check_isnan_exc ("sin (+inf) == NaN plus invalid exception",
1856 FUNC(sin) (plus_infty),
1857 INVALID_EXCEPTION);
1858 check_isnan_exc ("sin (-inf) == NaN plus invalid exception",
1859 FUNC(sin) (minus_infty),
1860 INVALID_EXCEPTION);
1862 check_eps ("sin (pi/6) == 0.5", FUNC(sin) (M_PI_6l),
1863 0.5, CHOOSE (4e-18L, 0, 0));
1864 check_eps ("sin (-pi/6) == -0.5", FUNC(sin) (-M_PI_6l),
1865 -0.5, CHOOSE (4e-18L, 0, 0));
1866 check ("sin (pi/2) == 1", FUNC(sin) (M_PI_2l), 1);
1867 check ("sin (-pi/2) == -1", FUNC(sin) (-M_PI_2l), -1);
1868 check_eps ("sin (0.7) == 0.6442176872...", FUNC(sin) (0.7),
1869 0.64421768723769105367L, CHOOSE(4e-17L, 0, 0));
1873 static void
1874 sinh_test (void)
1876 check ("sinh (+0) == +0", FUNC(sinh) (0), 0);
1878 #ifndef TEST_INLINE
1879 check ("sinh (-0) == -0", FUNC(sinh) (minus_zero), minus_zero);
1881 check_isinfp ("sinh (+inf) == +inf", FUNC(sinh) (plus_infty));
1882 check_isinfn ("sinh (-inf) == -inf", FUNC(sinh) (minus_infty));
1883 #endif
1885 check_eps ("sinh (0.7) == 0.7585837018...", FUNC(sinh) (0.7),
1886 0.75858370183953350346L, CHOOSE(6e-17L, 2e-16, 6e-8));
1890 static void
1891 sincos_test (void)
1893 MATHTYPE sin_res, cos_res;
1894 fenv_t fenv;
1896 FUNC(sincos) (0, &sin_res, &cos_res);
1897 fegetenv (&fenv);
1898 check ("sincos (+0, &sin, &cos) puts +0 in sin", sin_res, 0);
1899 fesetenv (&fenv);
1900 check ("sincos (+0, &sin, &cos) puts 1 in cos", cos_res, 1);
1902 FUNC(sincos) (minus_zero, &sin_res, &cos_res);
1903 fegetenv (&fenv);
1904 check ("sincos (-0, &sin, &cos) puts -0 in sin", sin_res, minus_zero);
1905 fesetenv (&fenv);
1906 check ("sincos (-0, &sin, &cos) puts 1 in cos", cos_res, 1);
1908 FUNC(sincos) (plus_infty, &sin_res, &cos_res);
1909 fegetenv (&fenv);
1910 check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in sin plus invalid exception",
1911 sin_res, INVALID_EXCEPTION);
1912 fesetenv (&fenv);
1913 check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in cos plus invalid exception",
1914 cos_res, INVALID_EXCEPTION);
1916 FUNC(sincos) (minus_infty, &sin_res, &cos_res);
1917 fegetenv (&fenv);
1918 check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in sin plus invalid exception",
1919 sin_res, INVALID_EXCEPTION);
1920 fesetenv (&fenv);
1921 check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in cos plus invalid exception",
1922 cos_res, INVALID_EXCEPTION);
1924 FUNC(sincos) (M_PI_2l, &sin_res, &cos_res);
1925 fegetenv (&fenv);
1926 check ("sincos (pi/2, &sin, &cos) puts 1 in sin", sin_res, 1);
1927 fesetenv (&fenv);
1928 check_eps ("sincos (pi/2, &sin, &cos) puts 0 in cos", cos_res, 0,
1929 CHOOSE (1e-18L, 1e-16, 1e-7));
1931 FUNC(sincos) (M_PI_6l, &sin_res, &cos_res);
1932 check_eps ("sincos (pi/6, &sin, &cos) puts 0.5 in sin", sin_res, 0.5,
1933 CHOOSE (5e-18L, 0, 0));
1935 FUNC(sincos) (M_PI_6l*2.0, &sin_res, &cos_res);
1936 check_eps ("sincos (pi/3, &sin, &cos) puts 0.5 in cos", cos_res, 0.5,
1937 CHOOSE (5e-18L, 1e-15, 1e-7));
1939 FUNC(sincos) (0.7, &sin_res, &cos_res);
1940 check_eps ("sincos (0.7, &sin, &cos) puts 0.6442176872... in sin", sin_res,
1941 0.64421768723769105367L, CHOOSE(4e-17L, 0, 0));
1942 check_eps ("sincos (0.7, &sin, &cos) puts 0.7648421872... in cos", cos_res,
1943 0.76484218728448842626L, CHOOSE(3e-17L, 2e-16, 6e-8));
1947 static void
1948 tan_test (void)
1950 check ("tan (+0) == +0", FUNC(tan) (0), 0);
1951 check ("tan (-0) == -0", FUNC(tan) (minus_zero), minus_zero);
1952 check_isnan_exc ("tan (+inf) == NaN plus invalid exception",
1953 FUNC(tan) (plus_infty), INVALID_EXCEPTION);
1954 check_isnan_exc ("tan (-inf) == NaN plus invalid exception",
1955 FUNC(tan) (minus_infty), INVALID_EXCEPTION);
1957 check_eps ("tan (pi/4) == 1", FUNC(tan) (M_PI_4l), 1,
1958 CHOOSE (2e-18L, 1e-15L, 2e-7));
1959 check_eps ("tan (0.7) == 0.8422883804...", FUNC(tan) (0.7),
1960 0.84228838046307944813L, CHOOSE(8e-17L, 0, 0));
1964 static void
1965 tanh_test (void)
1967 check ("tanh (+0) == +0", FUNC(tanh) (0), 0);
1968 #ifndef TEST_INLINE
1969 check ("tanh (-0) == -0", FUNC(tanh) (minus_zero), minus_zero);
1971 check ("tanh (+inf) == +1", FUNC(tanh) (plus_infty), 1);
1972 check ("tanh (-inf) == -1", FUNC(tanh) (minus_infty), -1);
1973 #endif
1974 check_eps ("tanh (0.7) == 0.6043677771...", FUNC(tanh) (0.7),
1975 0.60436777711716349631L, CHOOSE(3e-17L, 2e-16, 6e-8));
1979 static void
1980 fabs_test (void)
1982 check ("fabs (+0) == +0", FUNC(fabs) (0), 0);
1983 check ("fabs (-0) == +0", FUNC(fabs) (minus_zero), 0);
1985 check_isinfp ("fabs (+inf) == +inf", FUNC(fabs) (plus_infty));
1986 check_isinfp ("fabs (-inf) == +inf", FUNC(fabs) (minus_infty));
1988 check ("fabs (+38) == 38", FUNC(fabs) (38.0), 38.0);
1989 check ("fabs (-e) == e", FUNC(fabs) (-M_El), M_El);
1993 static void
1994 floor_test (void)
1996 check ("floor (+0) == +0", FUNC(floor) (0.0), 0.0);
1997 check ("floor (-0) == -0", FUNC(floor) (minus_zero), minus_zero);
1998 check_isinfp ("floor (+inf) == +inf", FUNC(floor) (plus_infty));
1999 check_isinfn ("floor (-inf) == -inf", FUNC(floor) (minus_infty));
2001 check ("floor (pi) == 3", FUNC(floor) (M_PIl), 3.0);
2002 check ("floor (-pi) == -4", FUNC(floor) (-M_PIl), -4.0);
2006 static void
2007 hypot_test (void)
2009 MATHTYPE a;
2011 a = random_greater (0);
2012 check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot) (plus_infty, a), a);
2013 check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot) (minus_infty, a), a);
2015 #ifndef TEST_INLINE
2016 check_isinfp ("hypot (+inf, NaN) == +inf", FUNC(hypot) (plus_infty, nan_value));
2017 check_isinfp ("hypot (-inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
2018 #endif
2020 check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot) (nan_value, nan_value));
2022 a = FUNC(hypot) (12.4L, 0.7L);
2023 check ("hypot (x,y) == hypot (y,x)", FUNC(hypot) (0.7L, 12.4L), a);
2024 check ("hypot (x,y) == hypot (-x,y)", FUNC(hypot) (-12.4L, 0.7L), a);
2025 check ("hypot (x,y) == hypot (-y,x)", FUNC(hypot) (-0.7L, 12.4L), a);
2026 check ("hypot (x,y) == hypot (-x,-y)", FUNC(hypot) (-12.4L, -0.7L), a);
2027 check ("hypot (x,y) == hypot (-y,-x)", FUNC(hypot) (-0.7L, -12.4L), a);
2028 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-0.7L, 0), 0.7L);
2029 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (0.7L, 0), 0.7L);
2030 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-1.0L, 0), 1.0L);
2031 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (1.0L, 0), 1.0L);
2032 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-5.7e7L, 0), 5.7e7L);
2033 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (5.7e7L, 0), 5.7e7L);
2035 check_eps ("hypot (0.7,1.2) == 1.38924...", FUNC(hypot) (0.7, 1.2),
2036 1.3892443989449804508L, CHOOSE(7e-17L, 3e-16, 0));
2040 static void
2041 pow_test (void)
2043 MATHTYPE x;
2045 check ("pow (+0, +0) == 1", FUNC(pow) (0, 0), 1);
2046 check ("pow (+0, -0) == 1", FUNC(pow) (0, minus_zero), 1);
2047 check ("pow (-0, +0) == 1", FUNC(pow) (minus_zero, 0), 1);
2048 check ("pow (-0, -0) == 1", FUNC(pow) (minus_zero, minus_zero), 1);
2050 check ("pow (+10, +0) == 1", FUNC(pow) (10, 0), 1);
2051 check ("pow (+10, -0) == 1", FUNC(pow) (10, minus_zero), 1);
2052 check ("pow (-10, +0) == 1", FUNC(pow) (-10, 0), 1);
2053 check ("pow (-10, -0) == 1", FUNC(pow) (-10, minus_zero), 1);
2055 check ("pow (NaN, +0) == 1", FUNC(pow) (nan_value, 0), 1);
2056 check ("pow (NaN, -0) == 1", FUNC(pow) (nan_value, minus_zero), 1);
2058 #ifndef TEST_INLINE
2059 check_isinfp ("pow (+1.1, +inf) == +inf", FUNC(pow) (1.1, plus_infty));
2060 check_isinfp ("pow (+inf, +inf) == +inf", FUNC(pow) (plus_infty, plus_infty));
2061 check_isinfp ("pow (-1.1, +inf) == +inf", FUNC(pow) (-1.1, plus_infty));
2062 check_isinfp ("pow (-inf, +inf) == +inf", FUNC(pow) (minus_infty, plus_infty));
2064 check ("pow (0.9, +inf) == +0", FUNC(pow) (0.9L, plus_infty), 0);
2065 check ("pow (1e-7, +inf) == +0", FUNC(pow) (1e-7L, plus_infty), 0);
2066 check ("pow (-0.9, +inf) == +0", FUNC(pow) (-0.9L, plus_infty), 0);
2067 check ("pow (-1e-7, +inf) == +0", FUNC(pow) (-1e-7L, plus_infty), 0);
2069 check ("pow (+1.1, -inf) == 0", FUNC(pow) (1.1, minus_infty), 0);
2070 check ("pow (+inf, -inf) == 0", FUNC(pow) (plus_infty, minus_infty), 0);
2071 check ("pow (-1.1, -inf) == 0", FUNC(pow) (-1.1, minus_infty), 0);
2072 check ("pow (-inf, -inf) == 0", FUNC(pow) (minus_infty, minus_infty), 0);
2074 check_isinfp ("pow (0.9, -inf) == +inf", FUNC(pow) (0.9L, minus_infty));
2075 check_isinfp ("pow (1e-7, -inf) == +inf", FUNC(pow) (1e-7L, minus_infty));
2076 check_isinfp ("pow (-0.9, -inf) == +inf", FUNC(pow) (-0.9L, minus_infty));
2077 check_isinfp ("pow (-1e-7, -inf) == +inf", FUNC(pow) (-1e-7L, minus_infty));
2079 check_isinfp ("pow (+inf, 1e-7) == +inf", FUNC(pow) (plus_infty, 1e-7L));
2080 check_isinfp ("pow (+inf, 1) == +inf", FUNC(pow) (plus_infty, 1));
2081 check_isinfp ("pow (+inf, 1e7) == +inf", FUNC(pow) (plus_infty, 1e7L));
2083 check ("pow (+inf, -1e-7) == 0", FUNC(pow) (plus_infty, -1e-7L), 0);
2084 check ("pow (+inf, -1) == 0", FUNC(pow) (plus_infty, -1), 0);
2085 check ("pow (+inf, -1e7) == 0", FUNC(pow) (plus_infty, -1e7L), 0);
2087 check_isinfn ("pow (-inf, 1) == -inf", FUNC(pow) (minus_infty, 1));
2088 check_isinfn ("pow (-inf, 11) == -inf", FUNC(pow) (minus_infty, 11));
2089 check_isinfn ("pow (-inf, 1001) == -inf", FUNC(pow) (minus_infty, 1001));
2091 check_isinfp ("pow (-inf, 2) == +inf", FUNC(pow) (minus_infty, 2));
2092 check_isinfp ("pow (-inf, 12) == +inf", FUNC(pow) (minus_infty, 12));
2093 check_isinfp ("pow (-inf, 1002) == +inf", FUNC(pow) (minus_infty, 1002));
2094 check_isinfp ("pow (-inf, 0.1) == +inf", FUNC(pow) (minus_infty, 0.1));
2095 check_isinfp ("pow (-inf, 1.1) == +inf", FUNC(pow) (minus_infty, 1.1));
2096 check_isinfp ("pow (-inf, 11.1) == +inf", FUNC(pow) (minus_infty, 11.1));
2097 check_isinfp ("pow (-inf, 1001.1) == +inf", FUNC(pow) (minus_infty, 1001.1));
2099 check ("pow (-inf, -1) == -0", FUNC(pow) (minus_infty, -1), minus_zero);
2100 check ("pow (-inf, -11) == -0", FUNC(pow) (minus_infty, -11), minus_zero);
2101 check ("pow (-inf, -1001) == -0", FUNC(pow) (minus_infty, -1001), minus_zero);
2103 check ("pow (-inf, -2) == +0", FUNC(pow) (minus_infty, -2), 0);
2104 check ("pow (-inf, -12) == +0", FUNC(pow) (minus_infty, -12), 0);
2105 check ("pow (-inf, -1002) == +0", FUNC(pow) (minus_infty, -1002), 0);
2106 check ("pow (-inf, -0.1) == +0", FUNC(pow) (minus_infty, -0.1), 0);
2107 check ("pow (-inf, -1.1) == +0", FUNC(pow) (minus_infty, -1.1), 0);
2108 check ("pow (-inf, -11.1) == +0", FUNC(pow) (minus_infty, -11.1), 0);
2109 check ("pow (-inf, -1001.1) == +0", FUNC(pow) (minus_infty, -1001.1), 0);
2111 check_isnan ("pow (NaN, NaN) == NaN", FUNC(pow) (nan_value, nan_value));
2112 check_isnan ("pow (0, NaN) == NaN", FUNC(pow) (0, nan_value));
2113 check_isnan ("pow (1, NaN) == NaN", FUNC(pow) (1, nan_value));
2114 check_isnan ("pow (-1, NaN) == NaN", FUNC(pow) (-1, nan_value));
2115 check_isnan ("pow (NaN, 1) == NaN", FUNC(pow) (nan_value, 1));
2116 check_isnan ("pow (NaN, -1) == NaN", FUNC(pow) (nan_value, -1));
2118 x = random_greater (0.0);
2119 check_isnan_ext ("pow (x, NaN) == NaN", FUNC(pow) (x, nan_value), x);
2121 check_isnan_exc ("pow (+1, +inf) == NaN plus invalid exception",
2122 FUNC(pow) (1, plus_infty), INVALID_EXCEPTION);
2123 check_isnan_exc ("pow (-1, +inf) == NaN plus invalid exception",
2124 FUNC(pow) (-1, plus_infty), INVALID_EXCEPTION);
2125 check_isnan_exc ("pow (+1, -inf) == NaN plus invalid exception",
2126 FUNC(pow) (1, minus_infty), INVALID_EXCEPTION);
2127 check_isnan_exc ("pow (-1, -inf) == NaN plus invalid exception",
2128 FUNC(pow) (-1, minus_infty), INVALID_EXCEPTION);
2130 check_isnan_exc ("pow (-0.1, 1.1) == NaN plus invalid exception",
2131 FUNC(pow) (-0.1, 1.1), INVALID_EXCEPTION);
2132 check_isnan_exc ("pow (-0.1, -1.1) == NaN plus invalid exception",
2133 FUNC(pow) (-0.1, -1.1), INVALID_EXCEPTION);
2134 check_isnan_exc ("pow (-10.1, 1.1) == NaN plus invalid exception",
2135 FUNC(pow) (-10.1, 1.1), INVALID_EXCEPTION);
2136 check_isnan_exc ("pow (-10.1, -1.1) == NaN plus invalid exception",
2137 FUNC(pow) (-10.1, -1.1), INVALID_EXCEPTION);
2139 check_isinfp_exc ("pow (+0, -1) == +inf plus divide-by-zero exception",
2140 FUNC(pow) (0, -1), DIVIDE_BY_ZERO_EXCEPTION);
2141 check_isinfp_exc ("pow (+0, -11) == +inf plus divide-by-zero exception",
2142 FUNC(pow) (0, -11), DIVIDE_BY_ZERO_EXCEPTION);
2143 check_isinfn_exc ("pow (-0, -1) == -inf plus divide-by-zero exception",
2144 FUNC(pow) (minus_zero, -1), DIVIDE_BY_ZERO_EXCEPTION);
2145 check_isinfn_exc ("pow (-0, -11) == -inf plus divide-by-zero exception",
2146 FUNC(pow) (minus_zero, -11), DIVIDE_BY_ZERO_EXCEPTION);
2148 check_isinfp_exc ("pow (+0, -2) == +inf plus divide-by-zero exception",
2149 FUNC(pow) (0, -2), DIVIDE_BY_ZERO_EXCEPTION);
2150 check_isinfp_exc ("pow (+0, -11.1) == +inf plus divide-by-zero exception",
2151 FUNC(pow) (0, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2152 check_isinfp_exc ("pow (-0, -2) == +inf plus divide-by-zero exception",
2153 FUNC(pow) (minus_zero, -2), DIVIDE_BY_ZERO_EXCEPTION);
2154 check_isinfp_exc ("pow (-0, -11.1) == +inf plus divide-by-zero exception",
2155 FUNC(pow) (minus_zero, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2156 #endif
2158 check ("pow (+0, 1) == +0", FUNC(pow) (0, 1), 0);
2159 check ("pow (+0, 11) == +0", FUNC(pow) (0, 11), 0);
2160 #ifndef TEST_INLINE
2161 check ("pow (-0, 1) == -0", FUNC(pow) (minus_zero, 1), minus_zero);
2162 check ("pow (-0, 11) == -0", FUNC(pow) (minus_zero, 11), minus_zero);
2163 #endif
2165 check ("pow (+0, 2) == +0", FUNC(pow) (0, 2), 0);
2166 check ("pow (+0, 11.1) == +0", FUNC(pow) (0, 11.1), 0);
2168 #ifndef TEST_INLINE
2169 check ("pow (-0, 2) == +0", FUNC(pow) (minus_zero, 2), 0);
2170 check ("pow (-0, 11.1) == +0", FUNC(pow) (minus_zero, 11.1), 0);
2172 x = random_greater (1.0);
2173 check_isinfp_ext ("pow (x, +inf) == +inf for |x| > 1",
2174 FUNC(pow) (x, plus_infty), x);
2176 x = random_value (-1.0, 1.0);
2177 check_ext ("pow (x, +inf) == +0 for |x| < 1",
2178 FUNC(pow) (x, plus_infty), 0.0, x);
2180 x = random_greater (1.0);
2181 check_ext ("pow (x, -inf) == +0 for |x| > 1",
2182 FUNC(pow) (x, minus_infty), 0.0, x);
2184 x = random_value (-1.0, 1.0);
2185 check_isinfp_ext ("pow (x, -inf) == +inf for |x| < 1",
2186 FUNC(pow) (x, minus_infty), x);
2188 x = random_greater (0.0);
2189 check_isinfp_ext ("pow (+inf, y) == +inf for y > 0",
2190 FUNC(pow) (plus_infty, x), x);
2192 x = random_less (0.0);
2193 check_ext ("pow (+inf, y) == +0 for y < 0",
2194 FUNC(pow) (plus_infty, x), 0.0, x);
2196 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2197 check_isinfn_ext ("pow (-inf, y) == -inf for y an odd integer > 0",
2198 FUNC(pow) (minus_infty, x), x);
2200 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2201 check_isinfp_ext ("pow (-inf, y) == +inf for y > 0 and not an odd integer",
2202 FUNC(pow) (minus_infty, x), x);
2204 x = -((rand () % 1000000) * 2.0 + 1); /* Get random odd integer < 0 */
2205 check_ext ("pow (-inf, y) == -0 for y an odd integer < 0",
2206 FUNC(pow) (minus_infty, x), minus_zero, x);
2208 x = ((rand () % 1000000) + 1) * -2.0; /* Get random even integer < 0 */
2209 check_ext ("pow (-inf, y) == +0 for y < 0 and not an odd integer",
2210 FUNC(pow) (minus_infty, x), 0.0, x);
2211 #endif
2213 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2214 check_ext ("pow (+0, y) == +0 for y an odd integer > 0",
2215 FUNC(pow) (0.0, x), 0.0, x);
2216 #ifndef TEST_INLINE
2217 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2218 check_ext ("pow (-0, y) == -0 for y an odd integer > 0",
2219 FUNC(pow) (minus_zero, x), minus_zero, x);
2220 #endif
2222 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2223 check_ext ("pow (+0, y) == +0 for y > 0 and not an odd integer",
2224 FUNC(pow) (0.0, x), 0.0, x);
2226 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2227 check_ext ("pow (-0, y) == +0 for y > 0 and not an odd integer",
2228 FUNC(pow) (minus_zero, x), 0.0, x);
2230 check_eps ("pow (0.7, 1.2) == 0.65180...", FUNC(pow) (0.7, 1.2),
2231 0.65180494056638638188L, CHOOSE(4e-17L, 0, 0));
2233 #ifdef TEST_DOUBLE
2234 check ("pow (-7.49321e+133, -9.80818e+16) == 0",
2235 FUNC(pow) (-7.49321e+133, -9.80818e+16), 0);
2236 #endif
2240 static void
2241 fdim_test (void)
2243 check ("fdim (+0, +0) = +0", FUNC(fdim) (0, 0), 0);
2244 check ("fdim (9, 0) = 9", FUNC(fdim) (9, 0), 9);
2245 check ("fdim (0, 9) = 0", FUNC(fdim) (0, 9), 0);
2246 check ("fdim (-9, 0) = 9", FUNC(fdim) (-9, 0), 0);
2247 check ("fdim (0, -9) = 9", FUNC(fdim) (0, -9), 9);
2249 check_isinfp ("fdim (+inf, 9) = +inf", FUNC(fdim) (plus_infty, 9));
2250 check_isinfp ("fdim (+inf, -9) = +inf", FUNC(fdim) (plus_infty, -9));
2251 check ("fdim (-inf, 9) = 0", FUNC(fdim) (minus_infty, 9), 0);
2252 check ("fdim (-inf, -9) = 0", FUNC(fdim) (minus_infty, -9), 0);
2253 check_isinfp ("fdim (+9, -inf) = +inf", FUNC(fdim) (9, minus_infty));
2254 check_isinfp ("fdim (-9, -inf) = +inf", FUNC(fdim) (-9, minus_infty));
2255 check ("fdim (9, inf) = 0", FUNC(fdim) (9, plus_infty), 0);
2256 check ("fdim (-9, inf) = 0", FUNC(fdim) (-9, plus_infty), 0);
2258 check_isnan ("fdim (0, NaN) = NaN", FUNC(fdim) (0, nan_value));
2259 check_isnan ("fdim (9, NaN) = NaN", FUNC(fdim) (9, nan_value));
2260 check_isnan ("fdim (-9, NaN) = NaN", FUNC(fdim) (-9, nan_value));
2261 check_isnan ("fdim (NaN, 9) = NaN", FUNC(fdim) (nan_value, 9));
2262 check_isnan ("fdim (NaN, -9) = NaN", FUNC(fdim) (nan_value, -9));
2263 check_isnan ("fdim (+inf, NaN) = NaN", FUNC(fdim) (plus_infty, nan_value));
2264 check_isnan ("fdim (-inf, NaN) = NaN", FUNC(fdim) (minus_infty, nan_value));
2265 check_isnan ("fdim (NaN, +inf) = NaN", FUNC(fdim) (nan_value, plus_infty));
2266 check_isnan ("fdim (NaN, -inf) = NaN", FUNC(fdim) (nan_value, minus_infty));
2267 check_isnan ("fdim (NaN, NaN) = NaN", FUNC(fdim) (nan_value, nan_value));
2271 static void
2272 fmin_test (void)
2274 check ("fmin (+0, +0) = +0", FUNC(fmin) (0, 0), 0);
2275 check ("fmin (9, 0) = 0", FUNC(fmin) (9, 0), 0);
2276 check ("fmin (0, 9) = 0", FUNC(fmin) (0, 9), 0);
2277 check ("fmin (-9, 0) = -9", FUNC(fmin) (-9, 0), -9);
2278 check ("fmin (0, -9) = -9", FUNC(fmin) (0, -9), -9);
2280 check ("fmin (+inf, 9) = 9", FUNC(fmin) (plus_infty, 9), 9);
2281 check ("fmin (9, +inf) = 9", FUNC(fmin) (9, plus_infty), 9);
2282 check ("fmin (+inf, -9) = -9", FUNC(fmin) (plus_infty, -9), -9);
2283 check ("fmin (-9, +inf) = -9", FUNC(fmin) (-9, plus_infty), -9);
2284 check_isinfn ("fmin (-inf, 9) = -inf", FUNC(fmin) (minus_infty, 9));
2285 check_isinfn ("fmin (-inf, -9) = -inf", FUNC(fmin) (minus_infty, -9));
2286 check_isinfn ("fmin (+9, -inf) = -inf", FUNC(fmin) (9, minus_infty));
2287 check_isinfn ("fmin (-9, -inf) = -inf", FUNC(fmin) (-9, minus_infty));
2289 check ("fmin (0, NaN) = 0", FUNC(fmin) (0, nan_value), 0);
2290 check ("fmin (9, NaN) = 9", FUNC(fmin) (9, nan_value), 9);
2291 check ("fmin (-9, NaN) = 9", FUNC(fmin) (-9, nan_value), -9);
2292 check ("fmin (NaN, 0) = 0", FUNC(fmin) (nan_value, 0), 0);
2293 check ("fmin (NaN, 9) = NaN", FUNC(fmin) (nan_value, 9), 9);
2294 check ("fmin (NaN, -9) = NaN", FUNC(fmin) (nan_value, -9), -9);
2295 check_isinfp ("fmin (+inf, NaN) = +inf", FUNC(fmin) (plus_infty, nan_value));
2296 check_isinfn ("fmin (-inf, NaN) = -inf", FUNC(fmin) (minus_infty, nan_value));
2297 check_isinfp ("fmin (NaN, +inf) = +inf", FUNC(fmin) (nan_value, plus_infty));
2298 check_isinfn ("fmin (NaN, -inf) = -inf", FUNC(fmin) (nan_value, minus_infty));
2299 check_isnan ("fmin (NaN, NaN) = NaN", FUNC(fmin) (nan_value, nan_value));
2303 static void
2304 fmax_test (void)
2306 check ("fmax (+0, +0) = +0", FUNC(fmax) (0, 0), 0);
2307 check ("fmax (9, 0) = 9", FUNC(fmax) (9, 0), 9);
2308 check ("fmax (0, 9) = 9", FUNC(fmax) (0, 9), 9);
2309 check ("fmax (-9, 0) = 0", FUNC(fmax) (-9, 0), 0);
2310 check ("fmax (0, -9) = 0", FUNC(fmax) (0, -9), 0);
2312 check_isinfp ("fmax (+inf, 9) = +inf", FUNC(fmax) (plus_infty, 9));
2313 check_isinfp ("fmax (9, +inf) = +inf", FUNC(fmax) (0, plus_infty));
2314 check_isinfp ("fmax (-9, +inf) = +inf", FUNC(fmax) (-9, plus_infty));
2315 check_isinfp ("fmax (+inf, -9) = +inf", FUNC(fmax) (plus_infty, -9));
2316 check ("fmax (-inf, 9) = 9", FUNC(fmax) (minus_infty, 9), 9);
2317 check ("fmax (-inf, -9) = -9", FUNC(fmax) (minus_infty, -9), -9);
2318 check ("fmax (+9, -inf) = 9", FUNC(fmax) (9, minus_infty), 9);
2319 check ("fmax (-9, -inf) = -9", FUNC(fmax) (-9, minus_infty), -9);
2321 check ("fmax (0, NaN) = 0", FUNC(fmax) (0, nan_value), 0);
2322 check ("fmax (9, NaN) = 9", FUNC(fmax) (9, nan_value), 9);
2323 check ("fmax (-9, NaN) = 9", FUNC(fmax) (-9, nan_value), -9);
2324 check ("fmax (NaN, 0) = 0", FUNC(fmax) (nan_value, 0), 0);
2325 check ("fmax (NaN, 9) = NaN", FUNC(fmax) (nan_value, 9), 9);
2326 check ("fmax (NaN, -9) = NaN", FUNC(fmax) (nan_value, -9), -9);
2327 check_isinfp ("fmax (+inf, NaN) = +inf", FUNC(fmax) (plus_infty, nan_value));
2328 check_isinfn ("fmax (-inf, NaN) = -inf", FUNC(fmax) (minus_infty, nan_value));
2329 check_isinfp ("fmax (NaN, +inf) = +inf", FUNC(fmax) (nan_value, plus_infty));
2330 check_isinfn ("fmax (NaN, -inf) = -inf", FUNC(fmax) (nan_value, minus_infty));
2331 check_isnan ("fmax (NaN, NaN) = NaN", FUNC(fmax) (nan_value, nan_value));
2335 static void
2336 fmod_test (void)
2338 MATHTYPE x;
2340 x = random_greater (0);
2341 check_ext ("fmod (+0, y) == +0 for y != 0", FUNC(fmod) (0, x), 0, x);
2343 x = random_greater (0);
2344 check_ext ("fmod (-0, y) == -0 for y != 0", FUNC(fmod) (minus_zero, x),
2345 minus_zero, x);
2347 check_isnan_exc_ext ("fmod (+inf, y) == NaN plus invalid exception",
2348 FUNC(fmod) (plus_infty, x), INVALID_EXCEPTION, x);
2349 check_isnan_exc_ext ("fmod (-inf, y) == NaN plus invalid exception",
2350 FUNC(fmod) (minus_infty, x), INVALID_EXCEPTION, x);
2351 check_isnan_exc_ext ("fmod (x, +0) == NaN plus invalid exception",
2352 FUNC(fmod) (x, 0), INVALID_EXCEPTION, x);
2353 check_isnan_exc_ext ("fmod (x, -0) == NaN plus invalid exception",
2354 FUNC(fmod) (x, minus_zero), INVALID_EXCEPTION, x);
2356 x = random_greater (0);
2357 check_ext ("fmod (x, +inf) == x for x not infinite",
2358 FUNC(fmod) (x, plus_infty), x, x);
2359 x = random_greater (0);
2360 check_ext ("fmod (x, -inf) == x for x not infinite",
2361 FUNC(fmod) (x, minus_infty), x, x);
2363 check_eps ("fmod (6.5, 2.3) == 1.9", FUNC(fmod) (6.5, 2.3), 1.9,
2364 CHOOSE(5e-16, 1e-15, 2e-7));
2365 check_eps ("fmod (-6.5, 2.3) == -1.9", FUNC(fmod) (-6.5, 2.3), -1.9,
2366 CHOOSE(5e-16, 1e-15, 2e-7));
2367 check_eps ("fmod (6.5, -2.3) == 1.9", FUNC(fmod) (6.5, -2.3), 1.9,
2368 CHOOSE(5e-16, 1e-15, 2e-7));
2369 check_eps ("fmod (-6.5, -2.3) == -1.9", FUNC(fmod) (-6.5, -2.3), -1.9,
2370 CHOOSE(5e-16, 1e-15, 2e-7));
2376 static void
2377 nextafter_test (void)
2379 MATHTYPE x;
2381 check ("nextafter (+0, +0) = +0", FUNC(nextafter) (0, 0), 0);
2382 check ("nextafter (-0, +0) = +0", FUNC(nextafter) (minus_zero, 0), 0);
2383 check ("nextafter (+0, -0) = -0", FUNC(nextafter) (0, minus_zero),
2384 minus_zero);
2385 check ("nextafter (-0, -0) = -0", FUNC(nextafter) (minus_zero, minus_zero),
2386 minus_zero);
2388 check ("nextafter (9, 9) = 9", FUNC(nextafter) (9, 9), 9);
2389 check ("nextafter (-9, -9) = -9", FUNC(nextafter) (-9, -9), -9);
2390 check_isinfp ("nextafter (+inf, +inf) = +inf",
2391 FUNC(nextafter) (plus_infty, plus_infty));
2392 check_isinfn ("nextafter (-inf, -inf) = -inf",
2393 FUNC(nextafter) (minus_infty, minus_infty));
2395 x = rand () * 1.1;
2396 check_isnan ("nextafter (NaN, x) = NaN", FUNC(nextafter) (nan_value, x));
2397 check_isnan ("nextafter (x, NaN) = NaN", FUNC(nextafter) (x, nan_value));
2398 check_isnan ("nextafter (NaN, NaN) = NaN", FUNC(nextafter) (nan_value,
2399 nan_value));
2401 /* XXX We need the hexadecimal FP number representation here for further
2402 tests. */
2406 static void
2407 copysign_test (void)
2409 check ("copysign (0, 4) = 0", FUNC(copysign) (0, 4), 0);
2410 check ("copysign (0, -4) = -0", FUNC(copysign) (0, -4), minus_zero);
2411 check ("copysign (-0, 4) = 0", FUNC(copysign) (minus_zero, 4), 0);
2412 check ("copysign (-0, -4) = -0", FUNC(copysign) (minus_zero, -4),
2413 minus_zero);
2415 check_isinfp ("copysign (+inf, 0) = +inf", FUNC(copysign) (plus_infty, 0));
2416 check_isinfn ("copysign (+inf, -0) = -inf", FUNC(copysign) (plus_infty,
2417 minus_zero));
2418 check_isinfp ("copysign (-inf, 0) = +inf", FUNC(copysign) (minus_infty, 0));
2419 check_isinfn ("copysign (-inf, -0) = -inf", FUNC(copysign) (minus_infty,
2420 minus_zero));
2422 check ("copysign (0, +inf) = 0", FUNC(copysign) (0, plus_infty), 0);
2423 check ("copysign (0, -inf) = -0", FUNC(copysign) (0, minus_zero),
2424 minus_zero);
2425 check ("copysign (-0, +inf) = 0", FUNC(copysign) (minus_zero, plus_infty),
2427 check ("copysign (-0, -inf) = -0", FUNC(copysign) (minus_zero, minus_zero),
2428 minus_zero);
2430 /* XXX More correctly we would have to check the sign of the NaN. */
2431 check_isnan ("copysign (+NaN, 0) = +NaN", FUNC(copysign) (nan_value, 0));
2432 check_isnan ("copysign (+NaN, -0) = -NaN", FUNC(copysign) (nan_value,
2433 minus_zero));
2434 check_isnan ("copysign (-NaN, 0) = +NaN", FUNC(copysign) (-nan_value, 0));
2435 check_isnan ("copysign (-NaN, -0) = -NaN", FUNC(copysign) (-nan_value,
2436 minus_zero));
2440 static void
2441 trunc_test (void)
2443 check ("trunc(0) = 0", FUNC(trunc) (0), 0);
2444 check ("trunc(-0) = -0", FUNC(trunc) (minus_zero), minus_zero);
2445 check ("trunc(0.625) = 0", FUNC(trunc) (0.625), 0);
2446 check ("trunc(-0.625) = -0", FUNC(trunc) (-0.625), minus_zero);
2447 check ("trunc(1) = 1", FUNC(trunc) (1), 1);
2448 check ("trunc(-1) = -1", FUNC(trunc) (-1), -1);
2449 check ("trunc(1.625) = 1", FUNC(trunc) (1.625), 1);
2450 check ("trunc(-1.625) = -1", FUNC(trunc) (-1.625), -1);
2452 check ("trunc(1048580.625) = 1048580", FUNC(trunc) (1048580.625L),
2453 1048580L);
2454 check ("trunc(-1048580.625) = -1048580", FUNC(trunc) (-1048580.625L),
2455 -1048580L);
2457 check ("trunc(8388610.125) = 8388610", FUNC(trunc) (8388610.125L),
2458 8388610.0L);
2459 check ("trunc(-8388610.125) = -8388610", FUNC(trunc) (-8388610.125L),
2460 -8388610.0L);
2462 check ("trunc(4294967296.625) = 4294967296", FUNC(trunc) (4294967296.625L),
2463 4294967296.0L);
2464 check ("trunc(-4294967296.625) = -4294967296",
2465 FUNC(trunc) (-4294967296.625L), -4294967296.0L);
2467 check_isinfp ("trunc(+inf) = +inf", FUNC(trunc) (plus_infty));
2468 check_isinfn ("trunc(-inf) = -inf", FUNC(trunc) (minus_infty));
2469 check_isnan ("trunc(NaN) = NaN", FUNC(trunc) (nan_value));
2473 static void
2474 sqrt_test (void)
2476 MATHTYPE x;
2479 /* XXX Tests fuer negative x are missing */
2480 check ("sqrt (0) == 0", FUNC(sqrt) (0), 0);
2481 check_isnan ("sqrt (NaN) == NaN", FUNC(sqrt) (nan_value));
2482 check_isinfp ("sqrt (+inf) == +inf", FUNC(sqrt) (plus_infty));
2484 check ("sqrt (-0) == -0", FUNC(sqrt) (0), 0);
2486 x = random_less (0.0);
2487 check_isnan_exc_ext ("sqrt (x) == NaN plus invalid exception for x < 0",
2488 FUNC(sqrt) (x), INVALID_EXCEPTION, x);
2490 x = random_value (0, 10000);
2491 check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x);
2492 check ("sqrt (4) == 2", FUNC(sqrt) (4), 2);
2493 check ("sqrt (2) == 1.14142...", FUNC(sqrt) (2), M_SQRT2l);
2494 check ("sqrt (0.25) == 0.5", FUNC(sqrt) (0.25), 0.5);
2495 check ("sqrt (6642.25) == 81.5", FUNC(sqrt) (6642.25), 81.5);
2496 check_eps ("sqrt (15239.903) == 123.45", FUNC(sqrt) (15239.903), 123.45,
2497 CHOOSE (3e-6L, 3e-6, 8e-6));
2498 check_eps ("sqrt (0.7) == 0.8366600265", FUNC(sqrt) (0.7),
2499 0.83666002653407554798L, CHOOSE(3e-17L, 0, 0));
2502 static void
2503 remainder_test (void)
2505 MATHTYPE result;
2507 result = FUNC(remainder) (1, 0);
2508 check_isnan_exc ("remainder(1, +0) == NaN plus invalid exception",
2509 result, INVALID_EXCEPTION);
2511 result = FUNC(remainder) (1, minus_zero);
2512 check_isnan_exc ("remainder(1, -0) == NaN plus invalid exception",
2513 result, INVALID_EXCEPTION);
2515 result = FUNC(remainder) (plus_infty, 1);
2516 check_isnan_exc ("remainder(+inf, 1) == NaN plus invalid exception",
2517 result, INVALID_EXCEPTION);
2519 result = FUNC(remainder) (minus_infty, 1);
2520 check_isnan_exc ("remainder(-inf, 1) == NaN plus invalid exception",
2521 result, INVALID_EXCEPTION);
2523 result = FUNC(remainder) (1.625, 1.0);
2524 check ("remainder(1.625, 1.0) == -0.375", result, -0.375);
2526 result = FUNC(remainder) (-1.625, 1.0);
2527 check ("remainder(-1.625, 1.0) == 0.375", result, 0.375);
2529 result = FUNC(remainder) (1.625, -1.0);
2530 check ("remainder(1.625, -1.0) == -0.375", result, -0.375);
2532 result = FUNC(remainder) (-1.625, -1.0);
2533 check ("remainder(-1.625, -1.0) == 0.375", result, 0.375);
2535 result = FUNC(remainder) (5.0, 2.0);
2536 check ("remainder(5.0, 2.0) == 1.0", result, 1.0);
2538 result = FUNC(remainder) (3.0, 2.0);
2539 check ("remainder(3.0, 2.0) == -1.0", result, -1.0);
2543 static void
2544 remquo_test (void)
2546 int quo;
2547 MATHTYPE result;
2549 result = FUNC(remquo) (1, 0, &quo);
2550 check_isnan_exc ("remquo(1, +0, &x) == NaN plus invalid exception",
2551 result, INVALID_EXCEPTION);
2553 result = FUNC(remquo) (1, minus_zero, &quo);
2554 check_isnan_exc ("remquo(1, -0, &x) == NaN plus invalid exception",
2555 result, INVALID_EXCEPTION);
2557 result = FUNC(remquo) (plus_infty, 1, &quo);
2558 check_isnan_exc ("remquo(+inf, 1, &x) == NaN plus invalid exception",
2559 result, INVALID_EXCEPTION);
2561 result = FUNC(remquo) (minus_infty, 1, &quo);
2562 check_isnan_exc ("remquo(-inf, 1, &x) == NaN plus invalid exception",
2563 result, INVALID_EXCEPTION);
2565 result = FUNC(remquo) (1.625, 1.0, &quo);
2566 check ("remquo(1.625, 1.0, &x) == -0.375", result, -0.375);
2567 check_long ("remquo(1.625, 1.0, &x) puts 2 in x", quo, 2);
2569 result = FUNC(remquo) (-1.625, 1.0, &quo);
2570 check ("remquo(-1.625, 1.0, &x) == 0.375", result, 0.375);
2571 check_long ("remquo(-1.625, 1.0, &x) puts -2 in x", quo, -2);
2573 result = FUNC(remquo) (1.625, -1.0, &quo);
2574 check ("remquo(1.625, -1.0, &x) == -0.375", result, -0.375);
2575 check_long ("remquo(1.625, -1.0, &x) puts -2 in x", quo, -2);
2577 result = FUNC(remquo) (-1.625, -1.0, &quo);
2578 check ("remquo(-1.625, -1.0, &x) == 0.375", result, 0.375);
2579 check_long ("remquo(-1.625, -1.0, &x) puts 2 in x", quo, 2);
2581 result = FUNC(remquo) (5.0, 2.0, &quo);
2582 check ("remquo(5.0, 2.0, &x) == 1.0", result, 1.0);
2583 check_long ("remquo (5.0, 2.0, &x) puts 2 in x", quo, 2);
2585 result = FUNC(remquo) (3.0, 2.0, &quo);
2586 check ("remquo(3.0, 2.0, &x) == -1.0", result, -1.0);
2587 check_long ("remquo (3.0, 2.0, &x) puts 2 in x", quo, 2);
2591 static void
2592 cexp_test (void)
2594 __complex__ MATHTYPE result;
2596 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, plus_zero));
2597 check ("real(cexp(0 + 0i)) = 1", __real__ result, 1);
2598 check ("imag(cexp(0 + 0i)) = 0", __imag__ result, 0);
2599 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_zero));
2600 check ("real(cexp(-0 + 0i)) = 1", __real__ result, 1);
2601 check ("imag(cexp(-0 + 0i)) = 0", __imag__ result, 0);
2602 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, minus_zero));
2603 check ("real(cexp(0 - 0i)) = 1", __real__ result, 1);
2604 check ("imag(cexp(0 - 0i)) = -0", __imag__ result, minus_zero);
2605 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_zero));
2606 check ("real(cexp(-0 - 0i)) = 1", __real__ result, 1);
2607 check ("imag(cexp(-0 - 0i)) = -0", __imag__ result, minus_zero);
2609 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_zero));
2610 check_isinfp ("real(cexp(+inf + 0i)) = +inf", __real__ result);
2611 check ("imag(cexp(+inf + 0i)) = 0", __imag__ result, 0);
2612 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_zero));
2613 check_isinfp ("real(cexp(+inf - 0i)) = +inf", __real__ result);
2614 check ("imag(cexp(+inf - 0i)) = -0", __imag__ result, minus_zero);
2616 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_zero));
2617 check ("real(cexp(-inf + 0i)) = 0", __real__ result, 0);
2618 check ("imag(cexp(-inf + 0i)) = 0", __imag__ result, 0);
2619 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_zero));
2620 check ("real(cexp(-inf - 0i)) = 0", __real__ result, 0);
2621 check ("imag(cexp(-inf - 0i)) = -0", __imag__ result, minus_zero);
2624 result = FUNC(cexp) (BUILD_COMPLEX (0.0, plus_infty));
2625 check_isnan_exc ("real(cexp(0 + i inf)) = NaN plus invalid exception",
2626 __real__ result, INVALID_EXCEPTION);
2627 check_isnan ("imag(cexp(0 + i inf)) = NaN plus invalid exception",
2628 __imag__ result);
2630 #if defined __GNUC__ && __GNUC__ <= 2 && __GNUC_MINOR__ <= 7
2631 if (verbose)
2632 printf ("The following test for cexp might fail due to a gcc compiler error!\n");
2633 #endif
2635 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_infty));
2636 check_isnan_exc ("real(cexp(-0 + i inf)) = NaN plus invalid exception",
2637 __real__ result, INVALID_EXCEPTION);
2638 check_isnan ("imag(cexp(-0 + i inf)) = NaN plus invalid exception",
2639 __imag__ result);
2640 result = FUNC(cexp) (BUILD_COMPLEX (0.0, minus_infty));
2641 check_isnan_exc ("real(cexp(0 - i inf)) = NaN plus invalid exception",
2642 __real__ result, INVALID_EXCEPTION);
2643 check_isnan ("imag(cexp(0 - i inf)) = NaN plus invalid exception",
2644 __imag__ result);
2645 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_infty));
2646 check_isnan_exc ("real(cexp(-0 - i inf)) = NaN plus invalid exception",
2647 __real__ result, INVALID_EXCEPTION);
2648 check_isnan ("imag(cexp(-0 - i inf)) = NaN plus invalid exception",
2649 __imag__ result);
2651 result = FUNC(cexp) (BUILD_COMPLEX (100.0, plus_infty));
2652 check_isnan_exc ("real(cexp(100.0 + i inf)) = NaN plus invalid exception",
2653 __real__ result, INVALID_EXCEPTION);
2654 check_isnan ("imag(cexp(100.0 + i inf)) = NaN plus invalid exception",
2655 __imag__ result);
2656 result = FUNC(cexp) (BUILD_COMPLEX (-100.0, plus_infty));
2657 check_isnan_exc ("real(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2658 __real__ result, INVALID_EXCEPTION);
2659 check_isnan ("imag(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2660 __imag__ result);
2661 result = FUNC(cexp) (BUILD_COMPLEX (100.0, minus_infty));
2662 check_isnan_exc ("real(cexp(100.0 - i inf)) = NaN plus invalid exception",
2663 __real__ result, INVALID_EXCEPTION);
2664 check_isnan ("imag(cexp(100.0 - i inf)) = NaN plus invalid exception",
2665 __imag__ result);
2666 result = FUNC(cexp) (BUILD_COMPLEX (-100.0, minus_infty));
2667 check_isnan_exc ("real(cexp(-100.0 - i inf)) = NaN plus invalid exception",
2668 __real__ result, INVALID_EXCEPTION);
2669 check_isnan ("imag(cexp(-100.0 - i inf)) = NaN", __imag__ result);
2671 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 2.0));
2672 check ("real(cexp(-inf + 2.0i)) = -0", __real__ result, minus_zero);
2673 check ("imag(cexp(-inf + 2.0i)) = 0", __imag__ result, 0);
2674 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 4.0));
2675 check ("real(cexp(-inf + 4.0i)) = -0", __real__ result, minus_zero);
2676 check ("imag(cexp(-inf + 4.0i)) = -0", __imag__ result, minus_zero);
2678 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 2.0));
2679 check_isinfn ("real(cexp(+inf + 2.0i)) = -inf", __real__ result);
2680 check_isinfp ("imag(cexp(+inf + 2.0i)) = +inf", __imag__ result);
2681 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 4.0));
2682 check_isinfn ("real(cexp(+inf + 4.0i)) = -inf", __real__ result);
2683 check_isinfn ("imag(cexp(+inf + 4.0i)) = -inf", __imag__ result);
2685 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_infty));
2686 check_isinfp_exc ("real(cexp(+inf + i inf)) = +inf plus invalid exception",
2687 __real__ result, INVALID_EXCEPTION);
2688 check_isnan ("imag(cexp(+inf + i inf)) = NaN plus invalid exception",
2689 __imag__ result);
2690 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_infty));
2691 check_isinfp_exc ("real(cexp(+inf - i inf)) = +inf plus invalid exception",
2692 __real__ result, INVALID_EXCEPTION);
2693 check_isnan ("imag(cexp(+inf - i inf)) = NaN plus invalid exception",
2694 __imag__ result);
2696 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_infty));
2697 check ("real(cexp(-inf + i inf)) = 0", __real__ result, 0);
2698 check ("imag(cexp(-inf + i inf)) = 0", __imag__ result, 0);
2699 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_infty));
2700 check ("real(cexp(-inf - i inf)) = 0", __real__ result, 0);
2701 check ("imag(cexp(-inf - i inf)) = -0", __imag__ result, minus_zero);
2703 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, nan_value));
2704 check ("real(cexp(-inf + i NaN)) = 0", __real__ result, 0);
2705 check ("imag(cexp(-inf + i NaN)) = 0", fabs (__imag__ result), 0);
2707 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, nan_value));
2708 check_isinfp ("real(cexp(+inf + i NaN)) = +inf", __real__ result);
2709 check_isnan ("imag(cexp(+inf + i NaN)) = NaN", __imag__ result);
2711 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 0.0));
2712 check_isnan_maybe_exc ("real(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2713 __real__ result, INVALID_EXCEPTION);
2714 check_isnan ("imag(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2715 __imag__ result);
2716 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
2717 check_isnan_maybe_exc ("real(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2718 __real__ result, INVALID_EXCEPTION);
2719 check_isnan ("imag(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2720 __imag__ result);
2721 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, plus_infty));
2722 check_isnan_maybe_exc ("real(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2723 __real__ result, INVALID_EXCEPTION);
2724 check_isnan ("imag(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2725 __imag__ result);
2727 result = FUNC(cexp) (BUILD_COMPLEX (0, nan_value));
2728 check_isnan_maybe_exc ("real(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2729 __real__ result, INVALID_EXCEPTION);
2730 check_isnan ("imag(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2731 __imag__ result);
2732 result = FUNC(cexp) (BUILD_COMPLEX (1, nan_value));
2733 check_isnan_maybe_exc ("real(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2734 __real__ result, INVALID_EXCEPTION);
2735 check_isnan ("imag(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2736 __imag__ result);
2738 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, nan_value));
2739 check_isnan ("real(cexp(NaN + i NaN)) = NaN", __real__ result);
2740 check_isnan ("imag(cexp(NaN + i NaN)) = NaN", __imag__ result);
2742 result = FUNC(cexp) (BUILD_COMPLEX (0.7, 1.2));
2743 check_eps ("real(cexp(0.7 + i 1.2)) == 0.72969...", __real__ result,
2744 0.7296989091503236012L, CHOOSE(6e-17L, 2e-16, 2e-7));
2745 check_eps ("imag(cexp(0.7 + i 1.2)) == 1.87689...", __imag__ result,
2746 1.8768962328348102821L, CHOOSE(2e-16L, 0, 3e-7));
2748 result = FUNC(cexp) (BUILD_COMPLEX (-2, -3));
2749 check_eps ("real(cexp(-2 - i 3)) == -0.13398...", __real__ result,
2750 -0.1339809149295426134L, CHOOSE(6e-20L, 0, 2e-8));
2751 check_eps ("imag(cexp(-2 - i 3)) == -0.01909...", __imag__ result,
2752 -0.0190985162611351964L, CHOOSE(4e-20L, 0, 2e-9));
2756 static void
2757 csin_test (void)
2759 __complex__ MATHTYPE result;
2761 result = FUNC(csin) (BUILD_COMPLEX (0.0, 0.0));
2762 check ("real(csin(0 + 0i)) = 0", __real__ result, 0);
2763 check ("imag(csin(0 + 0i)) = 0", __imag__ result, 0);
2764 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, 0.0));
2765 check ("real(csin(-0 + 0i)) = -0", __real__ result, minus_zero);
2766 check ("imag(csin(-0 + 0i)) = 0", __imag__ result, 0);
2767 result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_zero));
2768 check ("real(csin(0 - 0i)) = 0", __real__ result, 0);
2769 check ("imag(csin(0 - 0i)) = -0", __imag__ result, minus_zero);
2770 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_zero));
2771 check ("real(csin(-0 - 0i)) = -0", __real__ result, minus_zero);
2772 check ("imag(csin(-0 - 0i)) = -0", __imag__ result, minus_zero);
2774 result = FUNC(csin) (BUILD_COMPLEX (0.0, plus_infty));
2775 check ("real(csin(0 + i Inf)) = 0", __real__ result, 0);
2776 check_isinfp ("imag(csin(0 + i Inf)) = +Inf", __imag__ result);
2777 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, plus_infty));
2778 check ("real(csin(-0 + i Inf)) = -0", __real__ result, minus_zero);
2779 check_isinfp ("imag(csin(-0 + i Inf)) = +Inf", __imag__ result);
2780 result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_infty));
2781 check ("real(csin(0 - i Inf)) = 0", __real__ result, 0);
2782 check_isinfn ("imag(csin(0 - i Inf)) = -Inf", __imag__ result);
2783 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_infty));
2784 check ("real(csin(-0 - i Inf)) = -0", __real__ result, minus_zero);
2785 check_isinfn("imag(csin(-0 - i Inf)) = -Inf", __imag__ result);
2787 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 0.0));
2788 check_isnan_exc ("real(csin(+Inf + 0i)) = NaN plus invalid exception",
2789 __real__ result, INVALID_EXCEPTION);
2790 check ("imag(csin(+Inf + 0i)) = +-0 plus invalid exception",
2791 FUNC(fabs) (__imag__ result), 0);
2792 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 0.0));
2793 check_isnan_exc ("real(csin(-Inf + 0i)) = NaN plus invalid exception",
2794 __real__ result, INVALID_EXCEPTION);
2795 check ("imag(csin(-Inf + 0i)) = +-0 plus invalid exception",
2796 FUNC(fabs) (__imag__ result), 0);
2797 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_zero));
2798 check_isnan_exc ("real(csin(+Inf - 0i)) = NaN plus invalid exception",
2799 __real__ result, INVALID_EXCEPTION);
2800 check ("imag(csin(+Inf - 0i)) = +-0 plus invalid exception",
2801 FUNC(fabs) (__imag__ result), 0.0);
2802 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_zero));
2803 check_isnan_exc ("real(csin(-Inf - 0i)) = NaN plus invalid exception",
2804 __real__ result, INVALID_EXCEPTION);
2805 check ("imag(csin(-Inf - 0i)) = +-0 plus invalid exception",
2806 FUNC(fabs) (__imag__ result), 0.0);
2808 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, plus_infty));
2809 check_isnan_exc ("real(csin(+Inf + i Inf)) = NaN plus invalid exception",
2810 __real__ result, INVALID_EXCEPTION);
2811 check_isinfp ("imag(csin(+Inf + i Inf)) = +-Inf plus invalid exception",
2812 FUNC(fabs) (__imag__ result));
2813 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, plus_infty));
2814 check_isnan_exc ("real(csin(-Inf + i Inf)) = NaN plus invalid exception",
2815 __real__ result, INVALID_EXCEPTION);
2816 check_isinfp ("imag(csin(-Inf + i Inf)) = +-Inf plus invalid exception",
2817 FUNC(fabs) (__imag__ result));
2818 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_infty));
2819 check_isnan_exc ("real(csin(Inf - i Inf)) = NaN plus invalid exception",
2820 __real__ result, INVALID_EXCEPTION);
2821 check_isinfp ("imag(csin(Inf - i Inf)) = +-Inf plus invalid exception",
2822 FUNC(fabs) (__imag__ result));
2823 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_infty));
2824 check_isnan_exc ("real(csin(-Inf - i Inf)) = NaN plus invalid exception",
2825 __real__ result, INVALID_EXCEPTION);
2826 check_isinfp ("imag(csin(-Inf - i Inf)) = +-Inf plus invalid exception",
2827 FUNC(fabs) (__imag__ result));
2829 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 6.75));
2830 check_isnan_exc ("real(csin(+Inf + i 6.75)) = NaN plus invalid exception",
2831 __real__ result, INVALID_EXCEPTION);
2832 check_isnan ("imag(csin(+Inf + i6.75)) = NaN plus invalid exception",
2833 __imag__ result);
2834 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, -6.75));
2835 check_isnan_exc ("real(csin(+Inf - i 6.75)) = NaN plus invalid exception",
2836 __real__ result, INVALID_EXCEPTION);
2837 check_isnan ("imag(csin(+Inf - i6.75)) = NaN plus invalid exception",
2838 __imag__ result);
2839 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 6.75));
2840 check_isnan_exc ("real(csin(-Inf + i6.75)) = NaN plus invalid exception",
2841 __real__ result, INVALID_EXCEPTION);
2842 check_isnan ("imag(csin(-Inf + i6.75)) = NaN plus invalid exception",
2843 __imag__ result);
2844 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, -6.75));
2845 check_isnan_exc ("real(csin(-Inf - i6.75)) = NaN plus invalid exception",
2846 __real__ result, INVALID_EXCEPTION);
2847 check_isnan ("imag(csin(-Inf - i6.75)) = NaN plus invalid exception",
2848 __imag__ result);
2850 result = FUNC(csin) (BUILD_COMPLEX (4.625, plus_infty));
2851 check_isinfn ("real(csin(4.625 + i Inf)) = -Inf", __real__ result);
2852 check_isinfn ("imag(csin(4.625 + i Inf)) = -Inf", __imag__ result);
2853 result = FUNC(csin) (BUILD_COMPLEX (4.625, minus_infty));
2854 check_isinfn ("real(csin(4.625 - i Inf)) = -Inf", __real__ result);
2855 check_isinfp ("imag(csin(4.625 - i Inf)) = +Inf", __imag__ result);
2856 result = FUNC(csin) (BUILD_COMPLEX (-4.625, plus_infty));
2857 check_isinfp ("real(csin(-4.625 + i Inf)) = +Inf", __real__ result);
2858 check_isinfn ("imag(csin(-4.625 + i Inf)) = -Inf", __imag__ result);
2859 result = FUNC(csin) (BUILD_COMPLEX (-4.625, minus_infty));
2860 check_isinfp ("real(csin(-4.625 - i Inf)) = +Inf", __real__ result);
2861 check_isinfp ("imag(csin(-4.625 - i Inf)) = +Inf", __imag__ result);
2863 result = FUNC(csin) (BUILD_COMPLEX (nan_value, 0.0));
2864 check_isnan ("real(csin(NaN + i0)) = NaN", __real__ result);
2865 check ("imag(csin(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2866 result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_zero));
2867 check_isnan ("real(csin(NaN - i0)) = NaN", __real__ result);
2868 check ("imag(csin(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2870 result = FUNC(csin) (BUILD_COMPLEX (nan_value, plus_infty));
2871 check_isnan ("real(csin(NaN + i Inf)) = NaN", __real__ result);
2872 check_isinfp ("imag(csin(NaN + i Inf)) = +-Inf",
2873 FUNC(fabs) (__imag__ result));
2874 result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_infty));
2875 check_isnan ("real(csin(NaN - i Inf)) = NaN", __real__ result);
2876 check_isinfp ("real(csin(NaN - i Inf)) = +-Inf",
2877 FUNC(fabs) (__imag__ result));
2879 result = FUNC(csin) (BUILD_COMPLEX (nan_value, 9.0));
2880 check_isnan_maybe_exc ("real(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2881 __real__ result, INVALID_EXCEPTION);
2882 check_isnan ("imag(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2883 __imag__ result);
2884 result = FUNC(csin) (BUILD_COMPLEX (nan_value, -9.0));
2885 check_isnan_maybe_exc ("real(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2886 __real__ result, INVALID_EXCEPTION);
2887 check_isnan ("imag(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2888 __imag__ result);
2890 result = FUNC(csin) (BUILD_COMPLEX (0.0, nan_value));
2891 check ("real(csin(0 + i NaN))", __real__ result, 0.0);
2892 check_isnan ("imag(csin(0 + i NaN)) = NaN", __imag__ result);
2893 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, nan_value));
2894 check ("real(csin(-0 + i NaN)) = -0", __real__ result, minus_zero);
2895 check_isnan ("imag(csin(-0 + NaN)) = NaN", __imag__ result);
2897 result = FUNC(csin) (BUILD_COMPLEX (10.0, nan_value));
2898 check_isnan_maybe_exc ("real(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2899 __real__ result, INVALID_EXCEPTION);
2900 check_isnan ("imag(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2901 __imag__ result);
2902 result = FUNC(csin) (BUILD_COMPLEX (nan_value, -10.0));
2903 check_isnan_maybe_exc ("real(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2904 __real__ result, INVALID_EXCEPTION);
2905 check_isnan ("imag(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2906 __imag__ result);
2908 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, nan_value));
2909 check_isnan_maybe_exc ("real(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2910 __real__ result, INVALID_EXCEPTION);
2911 check_isnan ("imag(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2912 __imag__ result);
2913 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, nan_value));
2914 check_isnan_maybe_exc ("real(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2915 __real__ result, INVALID_EXCEPTION);
2916 check_isnan ("imag(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2917 __imag__ result);
2919 result = FUNC(csin) (BUILD_COMPLEX (nan_value, nan_value));
2920 check_isnan ("real(csin(NaN + i NaN)) = NaN", __real__ result);
2921 check_isnan ("imag(csin(NaN + i NaN)) = NaN", __imag__ result);
2923 result = FUNC(csin) (BUILD_COMPLEX (0.7, 1.2));
2924 check_eps ("real(csin(0.7 + i 1.2)) = 1.166456341...", __real__ result,
2925 1.1664563419657581376L, CHOOSE(2e-16L, 0, 0));
2926 check_eps ("imag(csin(0.7 + i 1.2)) = 1.154499724...", __imag__ result,
2927 1.1544997246948547371L, CHOOSE(2e-17L, 0, 2e-7));
2929 result = FUNC(csin) (BUILD_COMPLEX (-2, -3));
2930 check_eps ("real(csin(-2 - i 3)) == -9.15449...", __real__ result,
2931 -9.1544991469114295734L, CHOOSE(4e-18L, 0, 1e-6));
2932 check_eps ("imag(csin(-2 - i 3)) == -4.16890...", __imag__ result,
2933 4.1689069599665643507L, CHOOSE(2e-17L, 0, 5e-7));
2937 static void
2938 csinh_test (void)
2940 __complex__ MATHTYPE result;
2942 result = FUNC(csinh) (BUILD_COMPLEX (0.0, 0.0));
2943 check ("real(csinh(0 + 0i)) = 0", __real__ result, 0);
2944 check ("imag(csinh(0 + 0i)) = 0", __imag__ result, 0);
2945 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, 0.0));
2946 check ("real(csinh(-0 + 0i)) = -0", __real__ result, minus_zero);
2947 check ("imag(csinh(-0 + 0i)) = 0", __imag__ result, 0);
2948 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_zero));
2949 check ("real(csinh(0 - 0i)) = 0", __real__ result, 0);
2950 check ("imag(csinh(0 - 0i)) = -0", __imag__ result, minus_zero);
2951 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_zero));
2952 check ("real(csinh(-0 - 0i)) = -0", __real__ result, minus_zero);
2953 check ("imag(csinh(-0 - 0i)) = -0", __imag__ result, minus_zero);
2955 result = FUNC(csinh) (BUILD_COMPLEX (0.0, plus_infty));
2956 check_exc ("real(csinh(0 + i Inf)) = +-0 plus invalid exception",
2957 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2958 check_isnan ("imag(csinh(0 + i Inf)) = NaN plus invalid exception",
2959 __imag__ result);
2960 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, plus_infty));
2961 check_exc ("real(csinh(-0 + i Inf)) = +-0 plus invalid exception",
2962 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2963 check_isnan ("imag(csinh(-0 + i Inf)) = NaN plus invalid exception",
2964 __imag__ result);
2965 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_infty));
2966 check_exc ("real(csinh(0 - i Inf)) = +-0 plus invalid exception",
2967 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2968 check_isnan ("imag(csinh(0 - i Inf)) = NaN plus invalid exception",
2969 __imag__ result);
2970 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_infty));
2971 check_exc ("real(csinh(-0 - i Inf)) = +-0 plus invalid exception",
2972 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2973 check_isnan ("imag(csinh(-0 - i Inf)) = NaN plus invalid exception",
2974 __imag__ result);
2976 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 0.0));
2977 check_isinfp ("real(csinh(+Inf + 0i)) = +Inf", __real__ result);
2978 check ("imag(csinh(+Inf + 0i)) = 0", __imag__ result, 0);
2979 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 0.0));
2980 check_isinfn ("real(csinh(-Inf + 0i)) = -Inf", __real__ result);
2981 check ("imag(csinh(-Inf + 0i)) = 0", __imag__ result, 0);
2982 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_zero));
2983 check_isinfp ("real(csinh(+Inf - 0i)) = +Inf", __real__ result);
2984 check ("imag(csinh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
2985 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_zero));
2986 check_isinfn ("real(csinh(-Inf - 0i)) = -Inf", __real__ result);
2987 check ("imag(csinh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
2989 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, plus_infty));
2990 check_isinfp_exc ("real(csinh(+Inf + i Inf)) = +-Inf plus invalid exception",
2991 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2992 check_isnan ("imag(csinh(+Inf + i Inf)) = NaN plus invalid exception",
2993 __imag__ result);
2994 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, plus_infty));
2995 check_isinfp_exc ("real(csinh(-Inf + i Inf)) = +-Inf plus invalid exception",
2996 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2997 check_isnan ("imag(csinh(-Inf + i Inf)) = NaN plus invalid exception",
2998 __imag__ result);
2999 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_infty));
3000 check_isinfp_exc ("real(csinh(Inf - i Inf)) = +-Inf plus invalid exception",
3001 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
3002 check_isnan ("imag(csinh(Inf - i Inf)) = NaN plus invalid exception",
3003 __imag__ result);
3004 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_infty));
3005 check_isinfp_exc ("real(csinh(-Inf - i Inf)) = +-Inf plus invalid exception",
3006 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
3007 check_isnan ("imag(csinh(-Inf - i Inf)) = NaN plus invalid exception",
3008 __imag__ result);
3010 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 4.625));
3011 check_isinfn ("real(csinh(+Inf + i4.625)) = -Inf", __real__ result);
3012 check_isinfn ("imag(csinh(+Inf + i4.625)) = -Inf", __imag__ result);
3013 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 4.625));
3014 check_isinfp ("real(csinh(-Inf + i4.625)) = +Inf", __real__ result);
3015 check_isinfn ("imag(csinh(-Inf + i4.625)) = -Inf", __imag__ result);
3016 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, -4.625));
3017 check_isinfn ("real(csinh(+Inf - i4.625)) = -Inf", __real__ result);
3018 check_isinfp ("imag(csinh(+Inf - i4.625)) = +Inf", __imag__ result);
3019 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, -4.625));
3020 check_isinfp ("real(csinh(-Inf - i4.625)) = +Inf", __real__ result);
3021 check_isinfp ("imag(csinh(-Inf - i4.625)) = +Inf", __imag__ result);
3023 result = FUNC(csinh) (BUILD_COMPLEX (6.75, plus_infty));
3024 check_isnan_exc ("real(csinh(6.75 + i Inf)) = NaN plus invalid exception",
3025 __real__ result, INVALID_EXCEPTION);
3026 check_isnan ("imag(csinh(6.75 + i Inf)) = NaN plus invalid exception",
3027 __imag__ result);
3028 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, plus_infty));
3029 check_isnan_exc ("real(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
3030 __real__ result, INVALID_EXCEPTION);
3031 check_isnan ("imag(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
3032 __imag__ result);
3033 result = FUNC(csinh) (BUILD_COMPLEX (6.75, minus_infty));
3034 check_isnan_exc ("real(csinh(6.75 - i Inf)) = NaN plus invalid exception",
3035 __real__ result, INVALID_EXCEPTION);
3036 check_isnan ("imag(csinh(6.75 - i Inf)) = NaN plus invalid exception",
3037 __imag__ result);
3038 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, minus_infty));
3039 check_isnan_exc ("real(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
3040 __real__ result, INVALID_EXCEPTION);
3041 check_isnan ("imag(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
3042 __imag__ result);
3044 result = FUNC(csinh) (BUILD_COMPLEX (0.0, nan_value));
3045 check ("real(csinh(0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
3046 check_isnan ("imag(csinh(0 + i NaN)) = NaN", __imag__ result);
3047 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, nan_value));
3048 check ("real(csinh(-0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
3049 check_isnan ("imag(csinh(-0 + i NaN)) = NaN", __imag__ result);
3051 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, nan_value));
3052 check_isinfp ("real(csinh(+Inf + i NaN)) = +-Inf",
3053 FUNC(fabs) (__real__ result));
3054 check_isnan ("imag(csinh(+Inf + i NaN)) = NaN", __imag__ result);
3055 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, nan_value));
3056 check_isinfp ("real(csinh(-Inf + i NaN)) = +-Inf",
3057 FUNC(fabs) (__real__ result));
3058 check_isnan ("imag(csinh(-Inf + i NaN)) = NaN", __imag__ result);
3060 result = FUNC(csinh) (BUILD_COMPLEX (9.0, nan_value));
3061 check_isnan_maybe_exc ("real(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3062 __real__ result, INVALID_EXCEPTION);
3063 check_isnan ("imag(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3064 __imag__ result);
3065 result = FUNC(csinh) (BUILD_COMPLEX (-9.0, nan_value));
3066 check_isnan_maybe_exc ("real(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3067 __real__ result, INVALID_EXCEPTION);
3068 check_isnan ("imag(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3069 __imag__ result);
3071 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 0.0));
3072 check_isnan ("real(csinh(NaN + i0)) = NaN", __real__ result);
3073 check ("imag(csinh(NaN + i0)) = 0", __imag__ result, 0.0);
3074 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_zero));
3075 check_isnan ("real(csinh(NaN - i0)) = NaN", __real__ result);
3076 check ("imag(csinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3078 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 10.0));
3079 check_isnan_maybe_exc ("real(csinh(NaN + i10)) = NaN plus maybe invalid exception",
3080 __real__ result, INVALID_EXCEPTION);
3081 check_isnan ("imag(csinh(NaN + i10)) = NaN plus maybe invalid exception",
3082 __imag__ result);
3083 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, -10.0));
3084 check_isnan_maybe_exc ("real(csinh(NaN - i10)) = NaN plus maybe invalid exception",
3085 __real__ result, INVALID_EXCEPTION);
3086 check_isnan ("imag(csinh(NaN - i10)) = NaN plus maybe invalid exception",
3087 __imag__ result);
3089 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, plus_infty));
3090 check_isnan_maybe_exc ("real(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
3091 __real__ result, INVALID_EXCEPTION);
3092 check_isnan ("imag(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
3093 __imag__ result);
3094 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_infty));
3095 check_isnan_maybe_exc ("real(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
3096 __real__ result, INVALID_EXCEPTION);
3097 check_isnan ("imag(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
3098 __imag__ result);
3100 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, nan_value));
3101 check_isnan ("real(csinh(NaN + i NaN)) = NaN", __real__ result);
3102 check_isnan ("imag(csinh(NaN + i NaN)) = NaN", __imag__ result);
3104 result = FUNC(csinh) (BUILD_COMPLEX (0.7, 1.2));
3105 check_eps ("real(csinh(0.7 + i 1.2)) = 0.274878686...", __real__ result,
3106 0.27487868678117583582L, CHOOSE(2e-17L, 6e-17, 3e-8));
3107 check_eps ("imag(csinh(0.7 + i 1.2)) = 1.169866572...", __imag__ result,
3108 1.1698665727426565139L, CHOOSE(6e-17L, 0, 2e-7));
3110 result = FUNC(csinh) (BUILD_COMPLEX (-2, -3));
3111 check_eps ("real(csinh(-2 - i 3)) == -3.59056...", __real__ result,
3112 3.5905645899857799520L, CHOOSE(7e-19L, 5e-16, 3e-7));
3113 check_eps ("imag(csinh(-2 - i 3)) == -0.53092...", __imag__ result,
3114 -0.5309210862485198052L, CHOOSE(3e-19L, 2e-16, 6e-8));
3118 static void
3119 ccos_test (void)
3121 __complex__ MATHTYPE result;
3123 result = FUNC(ccos) (BUILD_COMPLEX (0.0, 0.0));
3124 check ("real(ccos(0 + 0i)) = 1.0", __real__ result, 1.0);
3125 check ("imag(ccos(0 + 0i)) = -0", __imag__ result, minus_zero);
3126 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, 0.0));
3127 check ("real(ccos(-0 + 0i)) = 1.0", __real__ result, 1.0);
3128 check ("imag(ccos(-0 + 0i)) = 0", __imag__ result, 0.0);
3129 result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_zero));
3130 check ("real(ccos(0 - 0i)) = 1.0", __real__ result, 1.0);
3131 check ("imag(ccos(0 - 0i)) = 0", __imag__ result, 0.0);
3132 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_zero));
3133 check ("real(ccos(-0 - 0i)) = 1.0", __real__ result, 1.0);
3134 check ("imag(ccos(-0 - 0i)) = -0", __imag__ result, minus_zero);
3136 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 0.0));
3137 check_isnan_exc ("real(ccos(+Inf + i0)) = NaN plus invalid exception",
3138 __real__ result, INVALID_EXCEPTION);
3139 check ("imag(ccos(Inf + i0)) = +-0 plus invalid exception",
3140 FUNC(fabs) (__imag__ result), 0);
3141 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_zero));
3142 check_isnan_exc ("real(ccos(Inf - i0)) = NaN plus invalid exception",
3143 __real__ result, INVALID_EXCEPTION);
3144 check ("imag(ccos(Inf - i0)) = +-0 plus invalid exception",
3145 FUNC(fabs) (__imag__ result), 0);
3146 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 0.0));
3147 check_isnan_exc ("real(ccos(-Inf + i0)) = NaN plus invalid exception",
3148 __real__ result, INVALID_EXCEPTION);
3149 check ("imag(ccos(-Inf + i0)) = +-0 plus invalid exception",
3150 FUNC(fabs) (__imag__ result), 0);
3151 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_zero));
3152 check_isnan_exc ("real(ccos(-Inf - i0)) = NaN plus invalid exception",
3153 __real__ result, INVALID_EXCEPTION);
3154 check ("imag(ccos(-Inf - i0)) = +-0 plus invalid exception",
3155 FUNC(fabs) (__imag__ result), 0);
3157 result = FUNC(ccos) (BUILD_COMPLEX (0.0, plus_infty));
3158 check_isinfp ("real(ccos(0 + i Inf)) = +Inf", __real__ result);
3159 check ("imag(ccos(0 + i Inf)) = -0", __imag__ result, minus_zero);
3160 result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_infty));
3161 check_isinfp ("real(ccos(0 - i Inf)) = +Inf", __real__ result);
3162 check ("imag(ccos(0 - i Inf)) = 0", __imag__ result, 0);
3163 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, plus_infty));
3164 check_isinfp ("real(ccos(-0 + i Inf)) = +Inf", __real__ result);
3165 check ("imag(ccos(-0 + i Inf)) = 0", __imag__ result, 0.0);
3166 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_infty));
3167 check_isinfp ("real(ccos(-0 - i Inf)) = +Inf", __real__ result);
3168 check ("imag(ccos(-0 - i Inf)) = -0", __imag__ result, minus_zero);
3170 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, plus_infty));
3171 check_isinfp_exc ("real(ccos(+Inf + i Inf)) = +Inf plus invalid exception",
3172 __real__ result, INVALID_EXCEPTION);
3173 check_isnan ("imag(ccos(+Inf + i Inf)) = NaN plus invalid exception",
3174 __imag__ result);
3175 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, plus_infty));
3176 check_isinfp_exc ("real(ccos(-Inf + i Inf)) = +Inf plus invalid exception",
3177 __real__ result, INVALID_EXCEPTION);
3178 check_isnan ("imag(ccos(-Inf + i Inf)) = NaN plus invalid exception",
3179 __imag__ result);
3180 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_infty));
3181 check_isinfp_exc ("real(ccos(Inf - i Inf)) = +Inf plus invalid exception",
3182 __real__ result, INVALID_EXCEPTION);
3183 check_isnan ("imag(ccos(Inf - i Inf)) = NaN plus invalid exception",
3184 __imag__ result);
3185 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_infty));
3186 check_isinfp_exc ("real(ccos(-Inf - i Inf)) = +Inf plus invalid exception",
3187 __real__ result, INVALID_EXCEPTION);
3188 check_isnan ("imag(ccos(-Inf - i Inf)) = NaN plus invalid exception",
3189 __imag__ result);
3191 result = FUNC(ccos) (BUILD_COMPLEX (4.625, plus_infty));
3192 check_isinfn ("real(ccos(4.625 + i Inf)) = -Inf", __real__ result);
3193 check_isinfp ("imag(ccos(4.625 + i Inf)) = +Inf", __imag__ result);
3194 result = FUNC(ccos) (BUILD_COMPLEX (4.625, minus_infty));
3195 check_isinfn ("real(ccos(4.625 - i Inf)) = -Inf", __real__ result);
3196 check_isinfn ("imag(ccos(4.625 - i Inf)) = -Inf", __imag__ result);
3197 result = FUNC(ccos) (BUILD_COMPLEX (-4.625, plus_infty));
3198 check_isinfn ("real(ccos(-4.625 + i Inf)) = -Inf", __real__ result);
3199 check_isinfn ("imag(ccos(-4.625 + i Inf)) = -Inf", __imag__ result);
3200 result = FUNC(ccos) (BUILD_COMPLEX (-4.625, minus_infty));
3201 check_isinfn ("real(ccos(-4.625 - i Inf)) = -Inf", __real__ result);
3202 check_isinfp ("imag(ccos(-4.625 - i Inf)) = +Inf", __imag__ result);
3204 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 6.75));
3205 check_isnan_exc ("real(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3206 __real__ result, INVALID_EXCEPTION);
3207 check_isnan ("imag(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3208 __imag__ result);
3209 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, -6.75));
3210 check_isnan_exc ("real(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3211 __real__ result, INVALID_EXCEPTION);
3212 check_isnan ("imag(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3213 __imag__ result);
3214 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 6.75));
3215 check_isnan_exc ("real(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3216 __real__ result, INVALID_EXCEPTION);
3217 check_isnan ("imag(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3218 __imag__ result);
3219 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, -6.75));
3220 check_isnan_exc ("real(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3221 __real__ result, INVALID_EXCEPTION);
3222 check_isnan ("imag(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3223 __imag__ result);
3225 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 0.0));
3226 check_isnan ("real(ccos(NaN + i0)) = NaN", __real__ result);
3227 check ("imag(ccos(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3228 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_zero));
3229 check_isnan ("real(ccos(NaN - i0)) = NaN", __real__ result);
3230 check ("imag(ccos(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3232 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, plus_infty));
3233 check_isinfp ("real(ccos(NaN + i Inf)) = +Inf", __real__ result);
3234 check_isnan ("imag(ccos(NaN + i Inf)) = NaN", __imag__ result);
3235 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_infty));
3236 check_isinfp ("real(ccos(NaN - i Inf)) = +Inf", __real__ result);
3237 check_isnan ("imag(ccos(NaN - i Inf)) = NaN", __imag__ result);
3239 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 9.0));
3240 check_isnan_maybe_exc ("real(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3241 __real__ result, INVALID_EXCEPTION);
3242 check_isnan ("imag(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3243 __imag__ result);
3244 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, -9.0));
3245 check_isnan_maybe_exc ("real(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3246 __real__ result, INVALID_EXCEPTION);
3247 check_isnan ("imag(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3248 __imag__ result);
3250 result = FUNC(ccos) (BUILD_COMPLEX (0.0, nan_value));
3251 check_isnan ("real(ccos(0 + i NaN)) = NaN", __real__ result);
3252 check ("imag(ccos(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3253 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, nan_value));
3254 check_isnan ("real(ccos(-0 + i NaN)) = NaN", __real__ result);
3255 check ("imag(ccos(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3257 result = FUNC(ccos) (BUILD_COMPLEX (10.0, nan_value));
3258 check_isnan_maybe_exc ("real(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3259 __real__ result, INVALID_EXCEPTION);
3260 check_isnan ("imag(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3261 __imag__ result);
3262 result = FUNC(ccos) (BUILD_COMPLEX (-10.0, nan_value));
3263 check_isnan_maybe_exc ("real(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3264 __real__ result, INVALID_EXCEPTION);
3265 check_isnan ("imag(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3266 __imag__ result);
3268 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, nan_value));
3269 check_isnan_maybe_exc ("real(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3270 __real__ result, INVALID_EXCEPTION);
3271 check_isnan ("imag(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3272 __imag__ result);
3273 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, nan_value));
3274 check_isnan_maybe_exc ("real(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3275 __real__ result, INVALID_EXCEPTION);
3276 check_isnan ("imag(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3277 __imag__ result);
3279 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, nan_value));
3280 check_isnan ("real(ccos(NaN + i NaN)) = NaN", __real__ result);
3281 check_isnan ("imag(ccos(NaN + i NaN)) = NaN", __imag__ result);
3283 result = FUNC(ccos) (BUILD_COMPLEX (0.7, 1.2));
3284 check_eps ("real(ccos(0.7 + i 1.2)) = 1.384865764...", __real__ result,
3285 1.3848657645312111080L, CHOOSE(4e-18L, 3e-16, 2e-7));
3286 check_eps ("imag(ccos(0.7 + i 1.2)) = -0.972421703...", __imag__ result,
3287 -0.97242170335830028619L, CHOOSE(2e-16L, 2e-16, 0));
3289 result = FUNC(ccos) (BUILD_COMPLEX (-2, -3));
3290 check_eps ("real(ccos(-2 - i 3)) == -4.18962...", __real__ result,
3291 -4.1896256909688072301L, CHOOSE(2e-17L, 0, 5e-7));
3292 check_eps ("imag(ccos(-2 - i 3)) == -9.10922...", __imag__ result,
3293 -9.1092278937553365979L, CHOOSE(3e-18L, 0, 1e-6));
3297 static void
3298 ccosh_test (void)
3300 __complex__ MATHTYPE result;
3302 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, 0.0));
3303 check ("real(ccosh(0 + 0i)) = 1.0", __real__ result, 1.0);
3304 check ("imag(ccosh(0 + 0i)) = 0", __imag__ result, 0);
3305 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, 0.0));
3306 check ("real(ccosh(-0 + 0i)) = 1.0", __real__ result, 1.0);
3307 check ("imag(ccosh(-0 + 0i)) = -0", __imag__ result, minus_zero);
3308 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_zero));
3309 check ("real(ccosh(0 - 0i)) = 1.0", __real__ result, 1.0);
3310 check ("imag(ccosh(0 - 0i)) = -0", __imag__ result, minus_zero);
3311 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3312 check ("real(ccosh(-0 - 0i)) = 1.0", __real__ result, 1.0);
3313 check ("imag(ccosh(-0 - 0i)) = 0", __imag__ result, 0.0);
3315 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, plus_infty));
3316 check_isnan_exc ("real(ccosh(0 + i Inf)) = NaN plus invalid exception",
3317 __real__ result, INVALID_EXCEPTION);
3318 check ("imag(ccosh(0 + i Inf)) = +-0 plus invalid exception",
3319 FUNC(fabs) (__imag__ result), 0);
3320 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, plus_infty));
3321 check_isnan_exc ("real(ccosh(-0 + i Inf)) = NaN plus invalid exception",
3322 __real__ result, INVALID_EXCEPTION);
3323 check ("imag(ccosh(-0 + i Inf)) = +-0 plus invalid exception",
3324 FUNC(fabs) (__imag__ result), 0);
3325 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_infty));
3326 check_isnan_exc ("real(ccosh(0 - i Inf)) = NaN plus invalid exception",
3327 __real__ result, INVALID_EXCEPTION);
3328 check ("imag(ccosh(0 - i Inf)) = +-0 plus invalid exception",
3329 FUNC(fabs) (__imag__ result), 0);
3330 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_infty));
3331 check_isnan_exc ("real(ccosh(-0 - i Inf)) = NaN plus invalid exception",
3332 __real__ result, INVALID_EXCEPTION);
3333 check ("imag(ccosh(-0 - i Inf)) = +-0 plus invalid exception",
3334 FUNC(fabs) (__imag__ result), 0);
3336 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 0.0));
3337 check_isinfp ("real(ccosh(+Inf + 0i)) = +Inf", __real__ result);
3338 check ("imag(ccosh(+Inf + 0i)) = 0", __imag__ result, 0);
3339 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 0.0));
3340 check_isinfp ("real(ccosh(-Inf + 0i)) = +Inf", __real__ result);
3341 check ("imag(ccosh(-Inf + 0i)) = -0", __imag__ result, minus_zero);
3342 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3343 check_isinfp ("real(ccosh(+Inf - 0i)) = +Inf", __real__ result);
3344 check ("imag(ccosh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
3345 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3346 check_isinfp ("real(ccosh(-Inf - 0i)) = +Inf", __real__ result);
3347 check ("imag(ccosh(-Inf - 0i)) = 0", __imag__ result, 0.0);
3349 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3350 check_isinfp_exc ("real(ccosh(+Inf + i Inf)) = +Inf plus invalid exception",
3351 __real__ result, INVALID_EXCEPTION);
3352 check_isnan ("imag(ccosh(+Inf + i Inf)) = NaN plus invalid exception",
3353 __imag__ result);
3354 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3355 check_isinfp_exc ("real(ccosh(-Inf + i Inf)) = +Inf plus invalid exception",
3356 __real__ result, INVALID_EXCEPTION);
3357 check_isnan ("imag(ccosh(-Inf + i Inf)) = NaN plus invalid exception",
3358 __imag__ result);
3359 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3360 check_isinfp_exc ("real(ccosh(Inf - i Inf)) = +Inf plus invalid exception",
3361 __real__ result, INVALID_EXCEPTION);
3362 check_isnan ("imag(ccosh(Inf - i Inf)) = NaN plus invalid exception",
3363 __imag__ result);
3364 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3365 check_isinfp_exc ("real(ccosh(-Inf - i Inf)) = +Inf plus invalid exception",
3366 __real__ result, INVALID_EXCEPTION);
3367 check_isnan ("imag(ccosh(-Inf - i Inf)) = NaN plus invalid exception",
3368 __imag__ result);
3370 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 4.625));
3371 check_isinfn ("real(ccosh(+Inf + i4.625)) = -Inf", __real__ result);
3372 check_isinfn ("imag(ccosh(+Inf + i4.625)) = -Inf", __imag__ result);
3373 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 4.625));
3374 check_isinfn ("real(ccosh(-Inf + i4.625)) = -Inf", __real__ result);
3375 check_isinfp ("imag(ccosh(-Inf + i4.625)) = Inf", __imag__ result);
3376 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, -4.625));
3377 check_isinfn ("real(ccosh(+Inf - i4.625)) = -Inf", __real__ result);
3378 check_isinfp ("imag(ccosh(+Inf - i4.625)) = +Inf", __imag__ result);
3379 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, -4.625));
3380 check_isinfn ("real(ccosh(-Inf - i4.625)) = -Inf", __real__ result);
3381 check_isinfn ("imag(ccosh(-Inf - i4.625)) = -Inf", __imag__ result);
3383 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, plus_infty));
3384 check_isnan_exc ("real(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3385 __real__ result, INVALID_EXCEPTION);
3386 check_isnan ("imag(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3387 __imag__ result);
3388 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, plus_infty));
3389 check_isnan_exc ("real(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3390 __real__ result, INVALID_EXCEPTION);
3391 check_isnan ("imag(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3392 __imag__ result);
3393 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, minus_infty));
3394 check_isnan_exc ("real(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3395 __real__ result, INVALID_EXCEPTION);
3396 check_isnan ("imag(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3397 __imag__ result);
3398 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, minus_infty));
3399 check_isnan_exc ("real(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3400 __real__ result, INVALID_EXCEPTION);
3401 check_isnan ("imag(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3402 __imag__ result);
3404 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, nan_value));
3405 check_isnan ("real(ccosh(0 + i NaN)) = NaN", __real__ result);
3406 check ("imag(ccosh(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3407 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, nan_value));
3408 check_isnan ("real(ccosh(-0 + i NaN)) = NaN", __real__ result);
3409 check ("imag(ccosh(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3411 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, nan_value));
3412 check_isinfp ("real(ccosh(+Inf + i NaN)) = +Inf", __real__ result);
3413 check_isnan ("imag(ccosh(+Inf + i NaN)) = NaN", __imag__ result);
3414 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, nan_value));
3415 check_isinfp ("real(ccosh(-Inf + i NaN)) = +Inf", __real__ result);
3416 check_isnan ("imag(ccosh(-Inf + i NaN)) = NaN", __imag__ result);
3418 result = FUNC(ccosh) (BUILD_COMPLEX (9.0, nan_value));
3419 check_isnan_maybe_exc ("real(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3420 __real__ result, INVALID_EXCEPTION);
3421 check_isnan ("imag(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3422 __imag__ result);
3423 result = FUNC(ccosh) (BUILD_COMPLEX (-9.0, nan_value));
3424 check_isnan_maybe_exc ("real(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3425 __real__ result, INVALID_EXCEPTION);
3426 check_isnan ("imag(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3427 __imag__ result);
3429 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 0.0));
3430 check_isnan ("real(ccosh(NaN + i0)) = NaN", __real__ result);
3431 check ("imag(ccosh(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3432 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_zero));
3433 check_isnan ("real(ccosh(NaN - i0)) = NaN", __real__ result);
3434 check ("imag(ccosh(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3436 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 10.0));
3437 check_isnan_maybe_exc ("real(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3438 __real__ result, INVALID_EXCEPTION);
3439 check_isnan ("imag(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3440 __imag__ result);
3441 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, -10.0));
3442 check_isnan_maybe_exc ("real(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3443 __real__ result, INVALID_EXCEPTION);
3444 check_isnan ("imag(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3445 __imag__ result);
3447 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, plus_infty));
3448 check_isnan_maybe_exc ("real(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3449 __real__ result, INVALID_EXCEPTION);
3450 check_isnan ("imag(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3451 __imag__ result);
3452 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_infty));
3453 check_isnan_maybe_exc ("real(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3454 __real__ result, INVALID_EXCEPTION);
3455 check_isnan ("imag(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3456 __imag__ result);
3458 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, nan_value));
3459 check_isnan ("real(ccosh(NaN + i NaN)) = NaN", __real__ result);
3460 check_isnan ("imag(ccosh(NaN + i NaN)) = NaN", __imag__ result);
3462 result = FUNC(ccosh) (BUILD_COMPLEX (0.7, 1.2));
3463 check_eps ("real(ccosh(0.7 + i 1.2)) == 0.45482...", __real__ result,
3464 0.4548202223691477654L, CHOOSE(5e-17L, 6e-17, 9e-8));
3465 check_eps ("imag(ccosh(0.7 + i 1.2)) == 0.70702...", __imag__ result,
3466 0.7070296600921537682L, CHOOSE(7e-17L, 2e-16, 0));
3468 result = FUNC(ccosh) (BUILD_COMPLEX (-2, -3));
3469 check_eps ("real(ccosh(-2 - i 3)) == -3.72454...", __real__ result,
3470 -3.7245455049153225654L, CHOOSE(7e-19L, 0, 3e-7));
3471 check_eps ("imag(ccosh(-2 - i 3)) == -0.51182...", __imag__ result,
3472 0.5118225699873846088L, CHOOSE(3e-19L, 2e-16, 6e-8));
3476 static void
3477 cacos_test (void)
3479 __complex__ MATHTYPE result;
3481 result = FUNC(cacos) (BUILD_COMPLEX (0, 0));
3482 check ("real(cacos(0 + i0)) = pi/2", __real__ result, M_PI_2l);
3483 check ("imag(cacos(0 + i0)) = -0", __imag__ result, minus_zero);
3484 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, 0));
3485 check ("real(cacos(-0 + i0)) = pi/2", __real__ result, M_PI_2l);
3486 check ("imag(cacos(-0 + i0)) = -0", __imag__ result, minus_zero);
3487 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_zero));
3488 check ("real(cacos(0 - i0)) = pi/2", __real__ result, M_PI_2l);
3489 check ("imag(cacos(0 - i0)) = 0", __imag__ result, 0);
3490 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, minus_zero));
3491 check ("real(cacos(-0 - i0)) = pi/2", __real__ result, M_PI_2l);
3492 check ("imag(cacos(-0 - i0)) = 0", __imag__ result, 0);
3494 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, plus_infty));
3495 check ("real(cacos(-Inf + i Inf)) = 3*pi/4", __real__ result,
3496 M_PIl - M_PI_4l);
3497 check_isinfn ("imag(cacos(-Inf + i Inf)) = -Inf", __imag__ result);
3498 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_infty));
3499 check ("real(cacos(-Inf - i Inf)) = 3*pi/4", __real__ result,
3500 M_PIl - M_PI_4l);
3501 check_isinfp ("imag(cacos(-Inf - i Inf)) = +Inf", __imag__ result);
3503 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, plus_infty));
3504 check ("real(cacos(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4l);
3505 check_isinfn ("imag(cacos(+Inf + i Inf)) = -Inf", __imag__ result);
3506 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_infty));
3507 check ("real(cacos(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4l);
3508 check_isinfp ("imag(cacos(+Inf - i Inf)) = +Inf", __imag__ result);
3510 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, plus_infty));
3511 check ("real(cacos(-10.0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3512 check_isinfn ("imag(cacos(-10.0 + i Inf)) = -Inf", __imag__ result);
3513 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, minus_infty));
3514 check ("real(cacos(-10.0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3515 check_isinfp ("imag(cacos(-10.0 - i Inf)) = +Inf", __imag__ result);
3516 result = FUNC(cacos) (BUILD_COMPLEX (0, plus_infty));
3517 check ("real(cacos(0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3518 check_isinfn ("imag(cacos(0 + i Inf)) = -Inf", __imag__ result);
3519 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_infty));
3520 check ("real(cacos(0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3521 check_isinfp ("imag(cacos(0 - i Inf)) = +Inf", __imag__ result);
3522 result = FUNC(cacos) (BUILD_COMPLEX (0.1, plus_infty));
3523 check ("real(cacos(0.1 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3524 check_isinfn ("imag(cacos(0.1 + i Inf)) = -Inf", __imag__ result);
3525 result = FUNC(cacos) (BUILD_COMPLEX (0.1, minus_infty));
3526 check ("real(cacos(0.1 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3527 check_isinfp ("imag(cacos(0.1 - i Inf)) = +Inf", __imag__ result);
3529 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 0));
3530 check ("real(cacos(-Inf + i0)) = pi", __real__ result, M_PIl);
3531 check_isinfn ("imag(cacos(-Inf + i0)) = -Inf", __imag__ result);
3532 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_zero));
3533 check ("real(cacos(-Inf - i0)) = pi", __real__ result, M_PIl);
3534 check_isinfp ("imag(cacos(-Inf - i0)) = +Inf", __imag__ result);
3535 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 100));
3536 check ("real(cacos(-Inf + i100)) = pi", __real__ result, M_PIl);
3537 check_isinfn ("imag(cacos(-Inf + i100)) = -Inf", __imag__ result);
3538 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, -100));
3539 check ("real(cacos(-Inf - i100)) = pi", __real__ result, M_PIl);
3540 check_isinfp ("imag(cacos(-Inf - i100)) = +Inf", __imag__ result);
3542 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0));
3543 check ("real(cacos(+Inf + i0)) = 0", __real__ result, 0);
3544 check_isinfn ("imag(cacos(+Inf + i0)) = -Inf", __imag__ result);
3545 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_zero));
3546 check ("real(cacos(+Inf - i0)) = 0", __real__ result, 0);
3547 check_isinfp ("imag(cacos(+Inf - i0)) = +Inf", __imag__ result);
3548 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0.5));
3549 check ("real(cacos(+Inf + i0.5)) = 0", __real__ result, 0);
3550 check_isinfn ("imag(cacos(+Inf + i0.5)) = -Inf", __imag__ result);
3551 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, -0.5));
3552 check ("real(cacos(+Inf - i0.5)) = 0", __real__ result, 0);
3553 check_isinfp ("imag(cacos(+Inf - i0.5)) = +Inf", __imag__ result);
3555 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, nan_value));
3556 check_isnan ("real(cacos(+Inf + i NaN)) = NaN", __real__ result);
3557 check_isinfp ("imag(cacos(+Inf + i NaN)) = +-Inf",
3558 FUNC(fabs) (__imag__ result));
3559 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, nan_value));
3560 check_isnan ("real(cacos(-Inf + i NaN)) = NaN", __real__ result);
3561 check_isinfp ("imag(cacos(-Inf + i NaN)) = +-Inf",
3562 FUNC(fabs) (__imag__ result));
3564 result = FUNC(cacos) (BUILD_COMPLEX (0, nan_value));
3565 check ("real(cacos(0 + i NaN)) = pi/2", __real__ result, M_PI_2l);
3566 check_isnan ("imag(cacos(0 + i NaN)) = NaN", __imag__ result);
3567 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, nan_value));
3568 check ("real(cacos(-0 + i NaN)) = pi/2", __real__ result, M_PI_2l);
3569 check_isnan ("imag(cacos(-0 + i NaN)) = NaN", __imag__ result);
3571 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, plus_infty));
3572 check_isnan ("real(cacos(NaN + i Inf)) = NaN", __real__ result);
3573 check_isinfn ("imag(cacos(NaN + i Inf)) = -Inf", __imag__ result);
3574 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, minus_infty));
3575 check_isnan ("real(cacos(NaN - i Inf)) = NaN", __real__ result);
3576 check_isinfp ("imag(cacos(NaN - i Inf)) = +Inf", __imag__ result);
3578 result = FUNC(cacos) (BUILD_COMPLEX (10.5, nan_value));
3579 check_isnan_maybe_exc ("real(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3580 __real__ result, INVALID_EXCEPTION);
3581 check_isnan ("imag(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3582 __imag__ result);
3583 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3584 check_isnan_maybe_exc ("real(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3585 __real__ result, INVALID_EXCEPTION);
3586 check_isnan ("imag(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3587 __imag__ result);
3589 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, 0.75));
3590 check_isnan_maybe_exc ("real(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3591 __real__ result, INVALID_EXCEPTION);
3592 check_isnan ("imag(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3593 __imag__ result);
3594 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3595 check_isnan_maybe_exc ("real(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3596 __real__ result, INVALID_EXCEPTION);
3597 check_isnan ("imag(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3598 __imag__ result);
3600 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, nan_value));
3601 check_isnan ("real(cacos(NaN + i NaN)) = NaN", __real__ result);
3602 check_isnan ("imag(cacos(NaN + i NaN)) = NaN", __imag__ result);
3604 result = FUNC(cacos) (BUILD_COMPLEX (0.7, 1.2));
3605 check_eps ("real(cacos(0.7 + i 1.2)) == 1.13518...", __real__ result,
3606 1.1351827477151551089L, CHOOSE(2e-17L, 3e-16, 2e-7));
3607 check_eps ("imag(cacos(0.7 + i 1.2)) == -1.09276...", __imag__ result,
3608 -1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 3e-7));
3610 result = FUNC(cacos) (BUILD_COMPLEX (-2, -3));
3611 check_eps ("real(cacos(-2 - i 3)) == 2.14144...", __real__ result,
3612 2.1414491111159960199L, CHOOSE(3e-19L, 0, 0));
3613 check_eps ("imag(cacos(-2 - i 3)) == -1.98338...", __imag__ result,
3614 1.9833870299165354323L, CHOOSE(3e-19L, 0, 0));
3618 static void
3619 cacosh_test (void)
3621 __complex__ MATHTYPE result;
3623 result = FUNC(cacosh) (BUILD_COMPLEX (0, 0));
3624 check ("real(cacosh(0 + i0)) = 0", __real__ result, 0);
3625 check ("imag(cacosh(0 + i0)) = pi/2", __imag__ result, M_PI_2l);
3626 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, 0));
3627 check ("real(cacosh(-0 + i0)) = 0", __real__ result, 0);
3628 check ("imag(cacosh(-0 + i0)) = pi/2", __imag__ result, M_PI_2l);
3629 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_zero));
3630 check ("real(cacosh(0 - i0)) = 0", __real__ result, 0);
3631 check ("imag(cacosh(0 - i0)) = -pi/2", __imag__ result, -M_PI_2l);
3632 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3633 check ("real(cacosh(-0 - i0)) = 0", __real__ result, 0);
3634 check ("imag(cacosh(-0 - i0)) = -pi/2", __imag__ result, -M_PI_2l);
3636 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3637 check_isinfp ("real(cacosh(-Inf + i Inf)) = +Inf", __real__ result);
3638 check ("imag(cacosh(-Inf + i Inf)) = 3*pi/4", __imag__ result,
3639 M_PIl - M_PI_4l);
3640 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3641 check_isinfp ("real(cacosh(-Inf - i Inf)) = +Inf", __real__ result);
3642 check ("imag(cacosh(-Inf - i Inf)) = -3*pi/4", __imag__ result,
3643 M_PI_4l - M_PIl);
3645 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3646 check_isinfp ("real(cacosh(+Inf + i Inf)) = +Inf", __real__ result);
3647 check ("imag(cacosh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3648 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3649 check_isinfp ("real(cacosh(+Inf - i Inf)) = +Inf", __real__ result);
3650 check ("imag(cacosh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3652 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, plus_infty));
3653 check_isinfp ("real(cacosh(-10.0 + i Inf)) = +Inf", __real__ result);
3654 check ("imag(cacosh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3655 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, minus_infty));
3656 check_isinfp ("real(cacosh(-10.0 - i Inf)) = +Inf", __real__ result);
3657 check ("imag(cacosh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3658 result = FUNC(cacosh) (BUILD_COMPLEX (0, plus_infty));
3659 check_isinfp ("real(cacosh(0 + i Inf)) = +Inf", __real__ result);
3660 check ("imag(cacosh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3661 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_infty));
3662 check_isinfp ("real(cacosh(0 - i Inf)) = +Inf", __real__ result);
3663 check ("imag(cacosh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3664 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, plus_infty));
3665 check_isinfp ("real(cacosh(0.1 + i Inf)) = +Inf", __real__ result);
3666 check ("imag(cacosh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3667 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, minus_infty));
3668 check_isinfp ("real(cacosh(0.1 - i Inf)) = +Inf", __real__ result);
3669 check ("imag(cacosh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3671 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 0));
3672 check_isinfp ("real(cacosh(-Inf + i0)) = +Inf", __real__ result);
3673 check ("imag(cacosh(-Inf + i0)) = pi", __imag__ result, M_PIl);
3674 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3675 check_isinfp ("real(cacosh(-Inf - i0)) = +Inf", __real__ result);
3676 check ("imag(cacosh(-Inf - i0)) = -pi", __imag__ result, -M_PIl);
3677 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 100));
3678 check_isinfp ("real(cacosh(-Inf + i100)) = +Inf", __real__ result);
3679 check ("imag(cacosh(-Inf + i100)) = pi", __imag__ result, M_PIl);
3680 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, -100));
3681 check_isinfp ("real(cacosh(-Inf - i100)) = +Inf", __real__ result);
3682 check ("imag(cacosh(-Inf - i100)) = -pi", __imag__ result, -M_PIl);
3684 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0));
3685 check_isinfp ("real(cacosh(+Inf + i0)) = +Inf", __real__ result);
3686 check ("imag(cacosh(+Inf + i0)) = 0", __imag__ result, 0);
3687 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3688 check_isinfp ("real(cacosh(+Inf - i0)) = +Inf", __real__ result);
3689 check ("imag(cacosh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3690 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0.5));
3691 check_isinfp ("real(cacosh(+Inf + i0.5)) = +Inf", __real__ result);
3692 check ("imag(cacosh(+Inf + i0.5)) = 0", __imag__ result, 0);
3693 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, -0.5));
3694 check_isinfp ("real(cacosh(+Inf - i0.5)) = +Inf", __real__ result);
3695 check ("imag(cacosh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3697 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, nan_value));
3698 check_isinfp ("real(cacosh(+Inf + i NaN)) = +Inf", __real__ result);
3699 check_isnan ("imag(cacosh(+Inf + i NaN)) = NaN", __imag__ result);
3700 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, nan_value));
3701 check_isinfp ("real(cacosh(-Inf + i NaN)) = +Inf", __real__ result);
3702 check_isnan ("imag(cacosh(-Inf + i NaN)) = NaN", __imag__ result);
3704 result = FUNC(cacosh) (BUILD_COMPLEX (0, nan_value));
3705 check_isnan ("real(cacosh(0 + i NaN)) = NaN", __real__ result);
3706 check_isnan ("imag(cacosh(0 + i NaN)) = NaN", __imag__ result);
3707 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, nan_value));
3708 check_isnan ("real(cacosh(-0 + i NaN)) = NaN", __real__ result);
3709 check_isnan ("imag(cacosh(-0 + i NaN)) = NaN", __imag__ result);
3711 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, plus_infty));
3712 check_isinfp ("real(cacosh(NaN + i Inf)) = +Inf", __real__ result);
3713 check_isnan ("imag(cacosh(NaN + i Inf)) = NaN", __imag__ result);
3714 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, minus_infty));
3715 check_isinfp ("real(cacosh(NaN - i Inf)) = +Inf", __real__ result);
3716 check_isnan ("imag(cacosh(NaN - i Inf)) = NaN", __imag__ result);
3718 result = FUNC(cacosh) (BUILD_COMPLEX (10.5, nan_value));
3719 check_isnan_maybe_exc ("real(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3720 __real__ result, INVALID_EXCEPTION);
3721 check_isnan ("imag(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3722 __imag__ result);
3723 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3724 check_isnan_maybe_exc ("real(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3725 __real__ result, INVALID_EXCEPTION);
3726 check_isnan ("imag(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3727 __imag__ result);
3729 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, 0.75));
3730 check_isnan_maybe_exc ("real(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3731 __real__ result, INVALID_EXCEPTION);
3732 check_isnan ("imag(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3733 __imag__ result);
3734 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3735 check_isnan_maybe_exc ("real(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3736 __real__ result, INVALID_EXCEPTION);
3737 check_isnan ("imag(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3738 __imag__ result);
3740 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, nan_value));
3741 check_isnan ("real(cacosh(NaN + i NaN)) = NaN", __real__ result);
3742 check_isnan ("imag(cacosh(NaN + i NaN)) = NaN", __imag__ result);
3744 result = FUNC(cacosh) (BUILD_COMPLEX (0.7, 1.2));
3745 check_eps ("real(cacosh(0.7 + i 1.2)) == 1.09276...", __real__ result,
3746 1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 2e-7));
3747 check_eps ("imag(cacosh(0.7 + i 1.2)) == 1.13518...", __imag__ result,
3748 1.1351827477151551089L, CHOOSE(2e-17L, 0, 0));
3750 result = FUNC(cacosh) (BUILD_COMPLEX (-2, -3));
3751 check_eps ("real(cacosh(-2 - i 3)) == -1.98338...", __real__ result,
3752 -1.9833870299165354323L, CHOOSE (2e-18L, 3e-16, 9e-7));
3753 check_eps ("imag(cacosh(-2 - i 3)) == 2.14144...", __imag__ result,
3754 2.1414491111159960199L, CHOOSE (3e-19, 5e-16, 1e-6));
3758 static void
3759 casin_test (void)
3761 __complex__ MATHTYPE result;
3763 result = FUNC(casin) (BUILD_COMPLEX (0, 0));
3764 check ("real(casin(0 + i0)) = 0", __real__ result, 0);
3765 check ("imag(casin(0 + i0)) = 0", __imag__ result, 0);
3766 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, 0));
3767 check ("real(casin(-0 + i0)) = -0", __real__ result, minus_zero);
3768 check ("imag(casin(-0 + i0)) = 0", __imag__ result, 0);
3769 result = FUNC(casin) (BUILD_COMPLEX (0, minus_zero));
3770 check ("real(casin(0 - i0)) = 0", __real__ result, 0);
3771 check ("imag(casin(0 - i0)) = -0", __imag__ result, minus_zero);
3772 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_zero));
3773 check ("real(casin(-0 - i0)) = -0", __real__ result, minus_zero);
3774 check ("imag(casin(-0 - i0)) = -0", __imag__ result, minus_zero);
3776 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, plus_infty));
3777 check ("real(casin(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4l);
3778 check_isinfp ("imag(casin(+Inf + i Inf)) = +Inf", __imag__ result);
3779 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_infty));
3780 check ("real(casin(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4l);
3781 check_isinfn ("imag(casin(+Inf - i Inf)) = -Inf", __imag__ result);
3782 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, plus_infty));
3783 check ("real(casin(-Inf + i Inf)) = -pi/4", __real__ result, -M_PI_4l);
3784 check_isinfp ("imag(casin(-Inf + i Inf)) = +Inf", __imag__ result);
3785 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_infty));
3786 check ("real(casin(-Inf - i Inf)) = -pi/4", __real__ result, -M_PI_4l);
3787 check_isinfn ("imag(casin(-Inf - i Inf)) = -Inf", __imag__ result);
3789 result = FUNC(casin) (BUILD_COMPLEX (-10.0, plus_infty));
3790 check ("real(casin(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
3791 check_isinfp ("imag(casin(-10.0 + i Inf)) = +Inf", __imag__ result);
3792 result = FUNC(casin) (BUILD_COMPLEX (-10.0, minus_infty));
3793 check ("real(casin(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
3794 check_isinfn ("imag(casin(-10.0 - i Inf)) = -Inf", __imag__ result);
3795 result = FUNC(casin) (BUILD_COMPLEX (0, plus_infty));
3796 check ("real(casin(0 + i Inf)) = 0", __real__ result, 0.0);
3797 check_isinfp ("imag(casin(0 + i Inf)) = +Inf", __imag__ result);
3798 result = FUNC(casin) (BUILD_COMPLEX (0, minus_infty));
3799 check ("real(casin(0 - i Inf)) = 0", __real__ result, 0.0);
3800 check_isinfn ("imag(casin(0 - i Inf)) = -Inf", __imag__ result);
3801 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, plus_infty));
3802 check ("real(casin(-0 + i Inf)) = -0", __real__ result, minus_zero);
3803 check_isinfp ("imag(casin(-0 + i Inf)) = +Inf", __imag__ result);
3804 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_infty));
3805 check ("real(casin(-0 - i Inf)) = -0", __real__ result, minus_zero);
3806 check_isinfn ("imag(casin(-0 - i Inf)) = -Inf", __imag__ result);
3807 result = FUNC(casin) (BUILD_COMPLEX (0.1, plus_infty));
3808 check ("real(casin(0.1 + i Inf)) = 0", __real__ result, 0);
3809 check_isinfp ("imag(casin(0.1 + i Inf)) = +Inf", __imag__ result);
3810 result = FUNC(casin) (BUILD_COMPLEX (0.1, minus_infty));
3811 check ("real(casin(0.1 - i Inf)) = 0", __real__ result, 0);
3812 check_isinfn ("imag(casin(0.1 - i Inf)) = -Inf", __imag__ result);
3814 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 0));
3815 check ("real(casin(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2l);
3816 check_isinfp ("imag(casin(-Inf + i0)) = +Inf", __imag__ result);
3817 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_zero));
3818 check ("real(casin(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2l);
3819 check_isinfn ("imag(casin(-Inf - i0)) = -Inf", __imag__ result);
3820 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 100));
3821 check ("real(casin(-Inf + i100)) = -pi/2", __real__ result, -M_PI_2l);
3822 check_isinfp ("imag(casin(-Inf + i100)) = +Inf", __imag__ result);
3823 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, -100));
3824 check ("real(casin(-Inf - i100)) = -pi/2", __real__ result, -M_PI_2l);
3825 check_isinfn ("imag(casin(-Inf - i100)) = -Inf", __imag__ result);
3827 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0));
3828 check ("real(casin(+Inf + i0)) = pi/2", __real__ result, M_PI_2l);
3829 check_isinfp ("imag(casin(+Inf + i0)) = +Inf", __imag__ result);
3830 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_zero));
3831 check ("real(casin(+Inf - i0)) = pi/2", __real__ result, M_PI_2l);
3832 check_isinfn ("imag(casin(+Inf - i0)) = -Inf", __imag__ result);
3833 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0.5));
3834 check ("real(casin(+Inf + i0.5)) = pi/2", __real__ result, M_PI_2l);
3835 check_isinfp ("imag(casin(+Inf + i0.5)) = +Inf", __imag__ result);
3836 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, -0.5));
3837 check ("real(casin(+Inf - i0.5)) = pi/2", __real__ result, M_PI_2l);
3838 check_isinfn ("imag(casin(+Inf - i0.5)) = -Inf", __imag__ result);
3840 result = FUNC(casin) (BUILD_COMPLEX (nan_value, plus_infty));
3841 check_isnan ("real(casin(NaN + i Inf)) = NaN", __real__ result);
3842 check_isinfp ("imag(casin(NaN + i Inf)) = +Inf", __imag__ result);
3843 result = FUNC(casin) (BUILD_COMPLEX (nan_value, minus_infty));
3844 check_isnan ("real(casin(NaN - i Inf)) = NaN", __real__ result);
3845 check_isinfn ("imag(casin(NaN - i Inf)) = -Inf", __imag__ result);
3847 result = FUNC(casin) (BUILD_COMPLEX (0.0, nan_value));
3848 check ("real(casin(0 + i NaN)) = 0", __real__ result, 0.0);
3849 check_isnan ("imag(casin(0 + i NaN)) = NaN", __imag__ result);
3850 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, nan_value));
3851 check ("real(casin(-0 + i NaN)) = -0", __real__ result, minus_zero);
3852 check_isnan ("imag(casin(-0 + i NaN)) = NaN", __imag__ result);
3854 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, nan_value));
3855 check_isnan ("real(casin(+Inf + i NaN)) = NaN", __real__ result);
3856 check_isinfp ("imag(casin(+Inf + i NaN)) = +-Inf",
3857 FUNC(fabs) (__imag__ result));
3858 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, nan_value));
3859 check_isnan ("real(casin(-Inf + i NaN)) = NaN", __real__ result);
3860 check_isinfp ("imag(casin(-Inf + NaN)) = +-Inf",
3861 FUNC(fabs) (__imag__ result));
3863 result = FUNC(casin) (BUILD_COMPLEX (nan_value, 10.5));
3864 check_isnan_maybe_exc ("real(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3865 __real__ result, INVALID_EXCEPTION);
3866 check_isnan ("imag(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3867 __imag__ result);
3868 result = FUNC(casin) (BUILD_COMPLEX (nan_value, -10.5));
3869 check_isnan_maybe_exc ("real(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3870 __real__ result, INVALID_EXCEPTION);
3871 check_isnan ("imag(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3872 __imag__ result);
3874 result = FUNC(casin) (BUILD_COMPLEX (0.75, nan_value));
3875 check_isnan_maybe_exc ("real(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3876 __real__ result, INVALID_EXCEPTION);
3877 check_isnan ("imag(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3878 __imag__ result);
3879 result = FUNC(casin) (BUILD_COMPLEX (-0.75, nan_value));
3880 check_isnan_maybe_exc ("real(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3881 __real__ result, INVALID_EXCEPTION);
3882 check_isnan ("imag(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3883 __imag__ result);
3885 result = FUNC(casin) (BUILD_COMPLEX (nan_value, nan_value));
3886 check_isnan ("real(casin(NaN + i NaN)) = NaN", __real__ result);
3887 check_isnan ("imag(casin(NaN + i NaN)) = NaN", __imag__ result);
3889 result = FUNC(casin) (BUILD_COMPLEX (0.7, 1.2));
3890 check_eps ("real(casin(0.7 + i 1.2)) == 0.43561...", __real__ result,
3891 0.4356135790797415103L, CHOOSE(2e-17L, 2e-16, 2e-7));
3892 check_eps ("imag(casin(0.7 + i 1.2)) == 1.09276...", __imag__ result,
3893 1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 3e-7));
3895 result = FUNC(casin) (BUILD_COMPLEX (-2, -3));
3896 check_eps ("real(casin(-2 - i 3)) == -0.57065...", __real__ result,
3897 -0.5706527843210994007L, CHOOSE(4e-19L, 0, 0));
3898 check_eps ("imag(casin(-2 - i 3)) == -1.98338...", __imag__ result,
3899 -1.9833870299165354323L, CHOOSE(3e-19L, 0, 0));
3903 static void
3904 casinh_test (void)
3906 __complex__ MATHTYPE result;
3908 result = FUNC(casinh) (BUILD_COMPLEX (0, 0));
3909 check ("real(casinh(0 + i0)) = 0", __real__ result, 0);
3910 check ("imag(casinh(0 + i0)) = 0", __imag__ result, 0);
3911 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, 0));
3912 check ("real(casinh(-0 + i0)) = -0", __real__ result, minus_zero);
3913 check ("imag(casinh(-0 + i0)) = 0", __imag__ result, 0);
3914 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_zero));
3915 check ("real(casinh(0 - i0)) = 0", __real__ result, 0);
3916 check ("imag(casinh(0 - i0)) = -0", __imag__ result, minus_zero);
3917 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_zero));
3918 check ("real(casinh(-0 - i0)) = -0", __real__ result, minus_zero);
3919 check ("imag(casinh(-0 - i0)) = -0", __imag__ result, minus_zero);
3921 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, plus_infty));
3922 check_isinfp ("real(casinh(+Inf + i Inf)) = +Inf", __real__ result);
3923 check ("imag(casinh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3924 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_infty));
3925 check_isinfp ("real(casinh(+Inf - i Inf)) = +Inf", __real__ result);
3926 check ("imag(casinh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3927 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, plus_infty));
3928 check_isinfn ("real(casinh(-Inf + i Inf)) = -Inf", __real__ result);
3929 check ("imag(casinh(-Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3930 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_infty));
3931 check_isinfn ("real(casinh(-Inf - i Inf)) = -Inf", __real__ result);
3932 check ("imag(casinh(-Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3934 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, plus_infty));
3935 check_isinfn ("real(casinh(-10.0 + i Inf)) = -Inf", __real__ result);
3936 check ("imag(casinh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3937 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, minus_infty));
3938 check_isinfn ("real(casinh(-10.0 - i Inf)) = -Inf", __real__ result);
3939 check ("imag(casinh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3940 result = FUNC(casinh) (BUILD_COMPLEX (0, plus_infty));
3941 check_isinfp ("real(casinh(0 + i Inf)) = +Inf", __real__ result);
3942 check ("imag(casinh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3943 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_infty));
3944 check_isinfp ("real(casinh(0 - i Inf)) = +Inf", __real__ result);
3945 check ("imag(casinh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3946 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, plus_infty));
3947 check_isinfn ("real(casinh(-0 + i Inf)) = -Inf", __real__ result);
3948 check ("imag(casinh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3949 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_infty));
3950 check_isinfn ("real(casinh(-0 - i Inf)) = -Inf", __real__ result);
3951 check ("imag(casinh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3952 result = FUNC(casinh) (BUILD_COMPLEX (0.1, plus_infty));
3953 check_isinfp ("real(casinh(0.1 + i Inf)) = +Inf", __real__ result);
3954 check ("imag(casinh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3955 result = FUNC(casinh) (BUILD_COMPLEX (0.1, minus_infty));
3956 check_isinfp ("real(casinh(0.1 - i Inf)) = +Inf", __real__ result);
3957 check ("imag(casinh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3959 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 0));
3960 check_isinfn ("real(casinh(-Inf + i0)) = -Inf", __real__ result);
3961 check ("imag(casinh(-Inf + i0)) = 0", __imag__ result, 0);
3962 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_zero));
3963 check_isinfn ("real(casinh(-Inf - i0)) = -Inf", __real__ result);
3964 check ("imag(casinh(-Inf - i0)) = -0", __imag__ result, minus_zero);
3965 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 100));
3966 check_isinfn ("real(casinh(-Inf + i100)) = -Inf", __real__ result);
3967 check ("imag(casinh(-Inf + i100)) = 0", __imag__ result, 0);
3968 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, -100));
3969 check_isinfn ("real(casinh(-Inf - i100)) = -Inf", __real__ result);
3970 check ("imag(casinh(-Inf - i100)) = -0", __imag__ result, minus_zero);
3972 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0));
3973 check_isinfp ("real(casinh(+Inf + i0)) = +Inf", __real__ result);
3974 check ("imag(casinh(+Inf + i0)) = 0", __imag__ result, 0);
3975 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_zero));
3976 check_isinfp ("real(casinh(+Inf - i0)) = +Inf", __real__ result);
3977 check ("imag(casinh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3978 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0.5));
3979 check_isinfp ("real(casinh(+Inf + i0.5)) = +Inf", __real__ result);
3980 check ("imag(casinh(+Inf + i0.5)) = 0", __imag__ result, 0);
3981 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, -0.5));
3982 check_isinfp ("real(casinh(+Inf - i0.5)) = +Inf", __real__ result);
3983 check ("imag(casinh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3985 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, nan_value));
3986 check_isinfp ("real(casinh(+Inf + i NaN)) = +Inf", __real__ result);
3987 check_isnan ("imag(casinh(+Inf + i NaN)) = NaN", __imag__ result);
3988 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, nan_value));
3989 check_isinfn ("real(casinh(-Inf + i NaN)) = -Inf", __real__ result);
3990 check_isnan ("imag(casinh(-Inf + i NaN)) = NaN", __imag__ result);
3992 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0));
3993 check_isnan ("real(casinh(NaN + i0)) = NaN", __real__ result);
3994 check ("imag(casinh(NaN + i0)) = 0", __imag__ result, 0);
3995 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_zero));
3996 check_isnan ("real(casinh(NaN - i0)) = NaN", __real__ result);
3997 check ("imag(casinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3999 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, plus_infty));
4000 check_isinfp ("real(casinh(NaN + i Inf)) = +-Inf",
4001 FUNC(fabs) (__real__ result));
4002 check_isnan ("imag(casinh(NaN + i Inf)) = NaN", __imag__ result);
4003 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_infty));
4004 check_isinfp ("real(casinh(NaN - i Inf)) = +-Inf",
4005 FUNC(fabs) (__real__ result));
4006 check_isnan ("imag(casinh(NaN - i Inf)) = NaN", __imag__ result);
4008 result = FUNC(casinh) (BUILD_COMPLEX (10.5, nan_value));
4009 check_isnan_maybe_exc ("real(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4010 __real__ result, INVALID_EXCEPTION);
4011 check_isnan ("imag(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4012 __imag__ result);
4013 result = FUNC(casinh) (BUILD_COMPLEX (-10.5, nan_value));
4014 check_isnan_maybe_exc ("real(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4015 __real__ result, INVALID_EXCEPTION);
4016 check_isnan ("imag(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4017 __imag__ result);
4019 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0.75));
4020 check_isnan_maybe_exc ("real(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
4021 __real__ result, INVALID_EXCEPTION);
4022 check_isnan ("imag(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
4023 __imag__ result);
4024 result = FUNC(casinh) (BUILD_COMPLEX (-0.75, nan_value));
4025 check_isnan_maybe_exc ("real(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
4026 __real__ result, INVALID_EXCEPTION);
4027 check_isnan ("imag(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
4028 __imag__ result);
4030 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, nan_value));
4031 check_isnan ("real(casinh(NaN + i NaN)) = NaN", __real__ result);
4032 check_isnan ("imag(casinh(NaN + i NaN)) = NaN", __imag__ result);
4034 result = FUNC(casinh) (BUILD_COMPLEX (0.7, 1.2));
4035 check_eps ("real(casinh(0.7 + i 1.2)) == 0.97865...", __real__ result,
4036 0.9786545955936738768L, CHOOSE(5e-17L, 2e-16, 0));
4037 check_eps ("imag(casinh(0.7 + i 1.2)) == 0.91135...", __imag__ result,
4038 0.9113541895315601156L, CHOOSE(7e-19L, 2e-16, 2e-7));
4040 result = FUNC(casinh) (BUILD_COMPLEX (-2, -3));
4041 check_eps ("real(casinh(-2 - i 3)) == -1.96863...", __real__ result,
4042 -1.9686379257930962917L, CHOOSE(7e-19L, 2e-15, 3e-6));
4043 check_eps ("imag(casinh(-2 - i 3)) == -0.96465...", __imag__ result,
4044 -0.9646585044076027920L, CHOOSE(4e-19L, 2e-15, 4e-7));
4048 static void
4049 catan_test (void)
4051 __complex__ MATHTYPE result;
4053 result = FUNC(catan) (BUILD_COMPLEX (0, 0));
4054 check ("real(catan(0 + i0)) = 0", __real__ result, 0);
4055 check ("imag(catan(0 + i0)) = 0", __imag__ result, 0);
4056 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, 0));
4057 check ("real(catan(-0 + i0)) = -0", __real__ result, minus_zero);
4058 check ("imag(catan(-0 + i0)) = 0", __imag__ result, 0);
4059 result = FUNC(catan) (BUILD_COMPLEX (0, minus_zero));
4060 check ("real(catan(0 - i0)) = 0", __real__ result, 0);
4061 check ("imag(catan(0 - i0)) = -0", __imag__ result, minus_zero);
4062 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_zero));
4063 check ("real(catan(-0 - i0)) = -0", __real__ result, minus_zero);
4064 check ("imag(catan(-0 - i0)) = -0", __imag__ result, minus_zero);
4066 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, plus_infty));
4067 check ("real(catan(+Inf + i Inf)) = pi/2", __real__ result, M_PI_2l);
4068 check ("imag(catan(+Inf + i Inf)) = 0", __imag__ result, 0);
4069 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_infty));
4070 check ("real(catan(+Inf - i Inf)) = pi/2", __real__ result, M_PI_2l);
4071 check ("imag(catan(+Inf - i Inf)) = -0", __imag__ result, minus_zero);
4072 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, plus_infty));
4073 check ("real(catan(-Inf + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4074 check ("imag(catan(-Inf + i Inf)) = 0", __imag__ result, 0.0);
4075 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_infty));
4076 check ("real(catan(-Inf - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4077 check ("imag(catan(-Inf - i Inf)) = -0", __imag__ result, minus_zero);
4079 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, -10.0));
4080 check ("real(catan(+Inf - i10.0)) = pi/2", __real__ result, M_PI_2l);
4081 check ("imag(catan(+Inf - i10.0)) = -0", __imag__ result, minus_zero);
4082 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, -10.0));
4083 check ("real(catan(-Inf - i10.0)) = -pi/2", __real__ result, -M_PI_2l);
4084 check ("imag(catan(-Inf - i10.0)) = -0", __imag__ result, minus_zero);
4085 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_zero));
4086 check ("real(catan(Inf - i0)) = pi/2", __real__ result, M_PI_2l);
4087 check ("imag(catan(Inf - i0)) = -0", __imag__ result, minus_zero);
4088 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_zero));
4089 check ("real(catan(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2l);
4090 check ("imag(catan(-Inf - i0)) = -0", __imag__ result, minus_zero);
4091 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.0));
4092 check ("real(catan(Inf + i0)) = pi/2", __real__ result, M_PI_2l);
4093 check ("imag(catan(Inf + i0)) = 0", __imag__ result, 0.0);
4094 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.0));
4095 check ("real(catan(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2l);
4096 check ("imag(catan(-Inf + i0)) = 0", __imag__ result, 0.0);
4097 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.1));
4098 check ("real(catan(+Inf + i0.1)) = pi/2", __real__ result, M_PI_2l);
4099 check ("imag(catan(+Inf + i0.1)) = 0", __imag__ result, 0);
4100 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.1));
4101 check ("real(catan(-Inf + i0.1)) = -pi/2", __real__ result, -M_PI_2l);
4102 check ("imag(catan(-Inf + i0.1)) = 0", __imag__ result, 0);
4104 result = FUNC(catan) (BUILD_COMPLEX (0.0, minus_infty));
4105 check ("real(catan(0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
4106 check ("imag(catan(0 - i Inf)) = -0", __imag__ result, minus_zero);
4107 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_infty));
4108 check ("real(catan(-0 - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4109 check ("imag(catan(-0 - i Inf)) = -0", __imag__ result, minus_zero);
4110 result = FUNC(catan) (BUILD_COMPLEX (100.0, minus_infty));
4111 check ("real(catan(100 - i Inf)) = pi/2", __real__ result, M_PI_2l);
4112 check ("imag(catan(100 - i Inf)) = -0", __imag__ result, minus_zero);
4113 result = FUNC(catan) (BUILD_COMPLEX (-100.0, minus_infty));
4114 check ("real(catan(-100 - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4115 check ("imag(catan(-100 - i Inf)) = -0", __imag__ result, minus_zero);
4117 result = FUNC(catan) (BUILD_COMPLEX (0.0, plus_infty));
4118 check ("real(catan(0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
4119 check ("imag(catan(0 + i Inf)) = 0", __imag__ result, 0);
4120 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, plus_infty));
4121 check ("real(catan(-0 + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4122 check ("imag(catan(-0 + i Inf)) = 0", __imag__ result, 0);
4123 result = FUNC(catan) (BUILD_COMPLEX (0.5, plus_infty));
4124 check ("real(catan(0.5 + i Inf)) = pi/2", __real__ result, M_PI_2l);
4125 check ("imag(catan(0.5 + i Inf)) = 0", __imag__ result, 0);
4126 result = FUNC(catan) (BUILD_COMPLEX (-0.5, plus_infty));
4127 check ("real(catan(-0.5 + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4128 check ("imag(catan(-0.5 + i Inf)) = 0", __imag__ result, 0);
4130 result = FUNC(catan) (BUILD_COMPLEX (nan_value, 0.0));
4131 check_isnan ("real(catan(NaN + i0)) = NaN", __real__ result);
4132 check ("imag(catan(NaN + i0)) = 0", __imag__ result, 0.0);
4133 result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_zero));
4134 check_isnan ("real(catan(NaN - i0)) = NaN", __real__ result);
4135 check ("imag(catan(NaN - i0)) = -0", __imag__ result, minus_zero);
4137 result = FUNC(catan) (BUILD_COMPLEX (nan_value, plus_infty));
4138 check_isnan ("real(catan(NaN + i Inf)) = NaN", __real__ result);
4139 check ("imag(catan(NaN + i Inf)) = 0", __imag__ result, 0);
4140 result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_infty));
4141 check_isnan ("real(catan(NaN - i Inf)) = NaN", __real__ result);
4142 check ("imag(catan(NaN - i Inf)) = -0", __imag__ result, minus_zero);
4144 result = FUNC(catan) (BUILD_COMPLEX (0.0, nan_value));
4145 check_isnan ("real(catan(0 + i NaN)) = NaN", __real__ result);
4146 check_isnan ("imag(catan(0 + i NaN)) = NaN", __imag__ result);
4147 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, nan_value));
4148 check_isnan ("real(catan(-0 + i NaN)) = NaN", __real__ result);
4149 check_isnan ("imag(catan(-0 + i NaN)) = NaN", __imag__ result);
4151 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, nan_value));
4152 check ("real(catan(+Inf + i NaN)) = pi/2", __real__ result, M_PI_2l);
4153 check ("imag(catan(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4154 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, nan_value));
4155 check ("real(catan(-Inf + i NaN)) = -pi/2", __real__ result, -M_PI_2l);
4156 check ("imag(catan(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4158 result = FUNC(catan) (BUILD_COMPLEX (nan_value, 10.5));
4159 check_isnan_maybe_exc ("real(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
4160 __real__ result, INVALID_EXCEPTION);
4161 check_isnan ("imag(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
4162 __imag__ result);
4163 result = FUNC(catan) (BUILD_COMPLEX (nan_value, -10.5));
4164 check_isnan_maybe_exc ("real(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
4165 __real__ result, INVALID_EXCEPTION);
4166 check_isnan ("imag(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
4167 __imag__ result);
4169 result = FUNC(catan) (BUILD_COMPLEX (0.75, nan_value));
4170 check_isnan_maybe_exc ("real(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
4171 __real__ result, INVALID_EXCEPTION);
4172 check_isnan ("imag(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
4173 __imag__ result);
4174 result = FUNC(catan) (BUILD_COMPLEX (-0.75, nan_value));
4175 check_isnan_maybe_exc ("real(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
4176 __real__ result, INVALID_EXCEPTION);
4177 check_isnan ("imag(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
4178 __imag__ result);
4180 result = FUNC(catan) (BUILD_COMPLEX (nan_value, nan_value));
4181 check_isnan ("real(catan(NaN + i NaN)) = NaN", __real__ result);
4182 check_isnan ("imag(catan(NaN + i NaN)) = NaN", __imag__ result);
4184 result = FUNC(catan) (BUILD_COMPLEX (0.7, 1.2));
4185 check_eps ("real(catan(0.7 + i 1.2)) == 1.07857...", __real__ result,
4186 1.0785743834118921877L, CHOOSE (3e-17, 0, 5e-7));
4187 check_eps ("imag(catan(0.7 + i 1.2)) == 0.57705...", __imag__ result,
4188 0.5770573776534306764L, CHOOSE(3e-17L, 2e-16, 6e-8));
4190 result = FUNC(catan) (BUILD_COMPLEX (-2, -3));
4191 check_eps ("real(catan(-2 - i 3)) == -1.40992...", __real__ result,
4192 -1.4099210495965755225L, CHOOSE(0, 0, 4e-7));
4193 check_eps ("imag(catan(-2 - i 3)) == -0.22907...", __imag__ result,
4194 -0.2290726829685387662L, CHOOSE(1.1e-19L, 3e-17, 2e-8));
4198 static void
4199 catanh_test (void)
4201 __complex__ MATHTYPE result;
4203 result = FUNC(catanh) (BUILD_COMPLEX (0, 0));
4204 check ("real(catanh(0 + i0)) = 0", __real__ result, 0);
4205 check ("imag(catanh(0 + i0)) = 0", __imag__ result, 0);
4206 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, 0));
4207 check ("real(catanh(-0 + i0)) = -0", __real__ result, minus_zero);
4208 check ("imag(catanh(-0 + i0)) = 0", __imag__ result, 0);
4209 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_zero));
4210 check ("real(catanh(0 - i0)) = 0", __real__ result, 0);
4211 check ("imag(catanh(0 - i0)) = -0", __imag__ result, minus_zero);
4212 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4213 check ("real(catanh(-0 - i0)) = -0", __real__ result, minus_zero);
4214 check ("imag(catanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4216 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, plus_infty));
4217 check ("real(catanh(+Inf + i Inf)) = 0", __real__ result, 0);
4218 check ("imag(catanh(+Inf + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4219 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_infty));
4220 check ("real(catanh(+Inf - i Inf)) = 0", __real__ result, 0);
4221 check ("imag(catanh(+Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4222 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, plus_infty));
4223 check ("real(catanh(-Inf + i Inf)) = -0", __real__ result, minus_zero);
4224 check ("imag(catanh(-Inf + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4225 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_infty));
4226 check ("real(catanh(-Inf - i Inf)) = -0", __real__ result, minus_zero);
4227 check ("imag(catanh(-Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4229 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, plus_infty));
4230 check ("real(catanh(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
4231 check ("imag(catanh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4232 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, minus_infty));
4233 check ("real(catanh(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
4234 check ("imag(catanh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4235 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4236 check ("real(catanh(-0 + i Inf)) = -0", __real__ result, minus_zero);
4237 check ("imag(catanh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4238 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4239 check ("real(catanh(-0 - i Inf)) = -0", __real__ result, minus_zero);
4240 check ("imag(catanh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4241 result = FUNC(catanh) (BUILD_COMPLEX (0, plus_infty));
4242 check ("real(catanh(0 + i Inf)) = 0", __real__ result, 0);
4243 check ("imag(catanh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4244 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_infty));
4245 check ("real(catanh(0 - i Inf)) = 0", __real__ result, 0);
4246 check ("imag(catanh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4247 result = FUNC(catanh) (BUILD_COMPLEX (0.1, plus_infty));
4248 check ("real(catanh(0.1 + i Inf)) = 0", __real__ result, 0);
4249 check ("imag(catanh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4250 result = FUNC(catanh) (BUILD_COMPLEX (0.1, minus_infty));
4251 check ("real(catanh(0.1 - i Inf)) = 0", __real__ result, 0);
4252 check ("imag(catanh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4254 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 0));
4255 check ("real(catanh(-Inf + i0)) = -0", __real__ result, minus_zero);
4256 check ("imag(catanh(-Inf + i0)) = pi/2", __imag__ result, M_PI_2l);
4257 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4258 check ("real(catanh(-Inf - i0)) = -0", __real__ result, minus_zero);
4259 check ("imag(catanh(-Inf - i0)) = -pi/2", __imag__ result, -M_PI_2l);
4260 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 100));
4261 check ("real(catanh(-Inf + i100)) = -0", __real__ result, minus_zero);
4262 check ("imag(catanh(-Inf + i100)) = pi/2", __imag__ result, M_PI_2l);
4263 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, -100));
4264 check ("real(catanh(-Inf - i100)) = -0", __real__ result, minus_zero);
4265 check ("imag(catanh(-Inf - i100)) = -pi/2", __imag__ result, -M_PI_2l);
4267 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0));
4268 check ("real(catanh(+Inf + i0)) = 0", __real__ result, 0);
4269 check ("imag(catanh(+Inf + i0)) = pi/2", __imag__ result, M_PI_2l);
4270 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4271 check ("real(catanh(+Inf - i0)) = 0", __real__ result, 0);
4272 check ("imag(catanh(+Inf - i0)) = -pi/2", __imag__ result, -M_PI_2l);
4273 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0.5));
4274 check ("real(catanh(+Inf + i0.5)) = 0", __real__ result, 0);
4275 check ("imag(catanh(+Inf + i0.5)) = pi/2", __imag__ result, M_PI_2l);
4276 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, -0.5));
4277 check ("real(catanh(+Inf - i0.5)) = 0", __real__ result, 0);
4278 check ("imag(catanh(+Inf - i0.5)) = -pi/2", __imag__ result, -M_PI_2l);
4280 result = FUNC(catanh) (BUILD_COMPLEX (0, nan_value));
4281 check ("real(catanh(0 + i NaN)) = 0", __real__ result, 0);
4282 check_isnan ("imag(catanh(0 + i NaN)) = NaN", __imag__ result);
4283 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, nan_value));
4284 check ("real(catanh(-0 + i NaN)) = -0", __real__ result, minus_zero);
4285 check_isnan ("imag(catanh(-0 + i NaN)) = NaN", __imag__ result);
4287 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, nan_value));
4288 check ("real(catanh(+Inf + i NaN)) = 0", __real__ result, 0);
4289 check_isnan ("imag(catanh(+Inf + i NaN)) = NaN", __imag__ result);
4290 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, nan_value));
4291 check ("real(catanh(-Inf + i NaN)) = -0", __real__ result, minus_zero);
4292 check_isnan ("imag(catanh(-Inf + i NaN)) = NaN", __imag__ result);
4294 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0));
4295 check_isnan ("real(catanh(NaN + i0)) = NaN", __real__ result);
4296 check_isnan ("imag(catanh(NaN + i0)) = NaN", __imag__ result);
4297 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_zero));
4298 check_isnan ("real(catanh(NaN - i0)) = NaN", __real__ result);
4299 check_isnan ("imag(catanh(NaN - i0)) = NaN", __imag__ result);
4301 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, plus_infty));
4302 check ("real(catanh(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4303 check ("imag(catanh(NaN + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4304 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_infty));
4305 check ("real(catanh(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4306 check ("imag(catanh(NaN - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4308 result = FUNC(catanh) (BUILD_COMPLEX (10.5, nan_value));
4309 check_isnan_maybe_exc ("real(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4310 __real__ result, INVALID_EXCEPTION);
4311 check_isnan ("imag(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4312 __imag__ result);
4313 result = FUNC(catanh) (BUILD_COMPLEX (-10.5, nan_value));
4314 check_isnan_maybe_exc ("real(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4315 __real__ result, INVALID_EXCEPTION);
4316 check_isnan ("imag(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4317 __imag__ result);
4319 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0.75));
4320 check_isnan_maybe_exc ("real(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4321 __real__ result, INVALID_EXCEPTION);
4322 check_isnan ("imag(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4323 __imag__ result);
4324 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, -0.75));
4325 check_isnan_maybe_exc ("real(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4326 __real__ result, INVALID_EXCEPTION);
4327 check_isnan ("imag(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4328 __imag__ result);
4330 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, nan_value));
4331 check_isnan ("real(catanh(NaN + i NaN)) = NaN", __real__ result);
4332 check_isnan ("imag(catanh(NaN + i NaN)) = NaN", __imag__ result);
4334 result = FUNC(catanh) (BUILD_COMPLEX (0.7, 1.2));
4335 check_eps ("real(catanh(0.7 + i 1.2)) == 0.26007...", __real__ result,
4336 0.2600749516525135959L, CHOOSE (2e-18, 6e-17, 0));
4337 check_eps ("imag(catanh(0.7 + i 1.2)) == 0.97024...", __imag__ result,
4338 0.9702403077950989849L, CHOOSE (3e-17, 2e-16, 4e-7));
4340 result = FUNC(catanh) (BUILD_COMPLEX (-2, -3));
4341 check_eps ("real(catanh(-2 - i 3)) == -0.14694...", __real__ result,
4342 -0.1469466662255297520L, CHOOSE (9e-20L, 2e-16, 2e-8));
4343 check_eps ("imag(catanh(-2 - i 3)) == -1.33897...", __imag__ result,
4344 -1.3389725222944935611L, CHOOSE (7e-19L, 0, 5e-7));
4348 static void
4349 ctan_test (void)
4351 __complex__ MATHTYPE result;
4353 result = FUNC(ctan) (BUILD_COMPLEX (0, 0));
4354 check ("real(ctan(0 + i0)) = 0", __real__ result, 0);
4355 check ("imag(ctan(0 + i0)) = 0", __imag__ result, 0);
4356 result = FUNC(ctan) (BUILD_COMPLEX (0, minus_zero));
4357 check ("real(ctan(0 - i0)) = 0", __real__ result, 0);
4358 check ("imag(ctan(0 - i0)) = -0", __imag__ result, minus_zero);
4359 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, 0));
4360 check ("real(ctan(-0 + i0)) = -0", __real__ result, minus_zero);
4361 check ("imag(ctan(-0 + i0)) = 0", __imag__ result, 0);
4362 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_zero));
4363 check ("real(ctan(-0 - i0)) = -0", __real__ result, minus_zero);
4364 check ("imag(ctan(-0 - i0)) = -0", __imag__ result, minus_zero);
4367 result = FUNC(ctan) (BUILD_COMPLEX (0, plus_infty));
4368 check ("real(ctan(0 + i Inf)) = 0", __real__ result, 0);
4369 check ("imag(ctan(0 + i Inf)) = 1", __imag__ result, 1);
4370 result = FUNC(ctan) (BUILD_COMPLEX (1, plus_infty));
4371 check ("real(ctan(1 + i Inf)) = 0", __real__ result, 0);
4372 check ("imag(ctan(1 + i Inf)) = 1", __imag__ result, 1);
4373 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, plus_infty));
4374 check ("real(ctan(-0 + i Inf)) = -0", __real__ result, minus_zero);
4375 check ("imag(ctan(-0 + i Inf)) = 1", __imag__ result, 1);
4376 result = FUNC(ctan) (BUILD_COMPLEX (-1, plus_infty));
4377 check ("real(ctan(-1 + i Inf)) = -0", __real__ result, minus_zero);
4378 check ("imag(ctan(-1 + i Inf)) = 1", __imag__ result, 1);
4380 result = FUNC(ctan) (BUILD_COMPLEX (0, minus_infty));
4381 check ("real(ctan(0 - i Inf)) = 0", __real__ result, 0);
4382 check ("imag(ctan(0 - i Inf)) = -1", __imag__ result, -1);
4383 result = FUNC(ctan) (BUILD_COMPLEX (1, minus_infty));
4384 check ("real(ctan(1 - i Inf)) = 0", __real__ result, 0);
4385 check ("imag(ctan(1 - i Inf)) = -1", __imag__ result, -1);
4386 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_infty));
4387 check ("real(ctan(-0 - i Inf)) = -0", __real__ result, minus_zero);
4388 check ("imag(ctan(-0 - i Inf)) = -1", __imag__ result, -1);
4389 result = FUNC(ctan) (BUILD_COMPLEX (-1, minus_infty));
4390 check ("real(ctan(-1 - i Inf)) = -0", __real__ result, minus_zero);
4391 check ("imag(ctan(-1 - i Inf)) = -1", __imag__ result, -1);
4393 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 0));
4394 check_isnan_exc ("real(ctan(Inf + i 0)) = NaN plus invalid exception",
4395 __real__ result, INVALID_EXCEPTION);
4396 check_isnan ("imag(ctan(Inf + i 0)) = NaN plus invalid exception",
4397 __imag__ result);
4398 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 2));
4399 check_isnan_exc ("real(ctan(Inf + i 2)) = NaN plus invalid exception",
4400 __real__ result, INVALID_EXCEPTION);
4401 check_isnan ("imag(ctan(Inf + i 2)) = NaN plus invalid exception",
4402 __imag__ result);
4403 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 0));
4404 check_isnan_exc ("real(ctan(-Inf + i 0)) = NaN plus invalid exception",
4405 __real__ result, INVALID_EXCEPTION);
4406 check_isnan ("imag(ctan(-Inf + i 0)) = NaN plus invalid exception",
4407 __imag__ result);
4408 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 2));
4409 check_isnan_exc ("real(ctan(- Inf + i 2)) = NaN plus invalid exception",
4410 __real__ result, INVALID_EXCEPTION);
4411 check_isnan ("imag(ctan(- Inf + i 2)) = NaN plus invalid exception",
4412 __imag__ result);
4413 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, minus_zero));
4414 check_isnan_exc ("real(ctan(Inf - i 0)) = NaN plus invalid exception",
4415 __real__ result, INVALID_EXCEPTION);
4416 check_isnan ("imag(ctan(Inf - i 0)) = NaN plus invalid exception",
4417 __imag__ result);
4418 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, -2));
4419 check_isnan_exc ("real(ctan(Inf - i 2)) = NaN plus invalid exception",
4420 __real__ result, INVALID_EXCEPTION);
4421 check_isnan ("imag(ctan(Inf - i 2)) = NaN plus invalid exception",
4422 __imag__ result);
4423 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, minus_zero));
4424 check_isnan_exc ("real(ctan(-Inf - i 0)) = NaN plus invalid exception",
4425 __real__ result, INVALID_EXCEPTION);
4426 check_isnan ("imag(ctan(-Inf - i 0)) = NaN plus invalid exception",
4427 __imag__ result);
4428 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, -2));
4429 check_isnan_exc ("real(ctan(-Inf - i 2)) = NaN plus invalid exception",
4430 __real__ result, INVALID_EXCEPTION);
4431 check_isnan ("imag(ctan(-Inf - i 2)) = NaN plus invalid exception",
4432 __imag__ result);
4434 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, plus_infty));
4435 check ("real(ctan(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4436 check ("imag(ctan(NaN + i Inf)) = 1", __imag__ result, 1);
4437 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_infty));
4438 check ("real(ctan(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4439 check ("imag(ctan(NaN - i Inf)) = -1", __imag__ result, -1);
4441 result = FUNC(ctan) (BUILD_COMPLEX (0, nan_value));
4442 check ("real(ctan(0 + i NaN)) = 0", __real__ result, 0);
4443 check_isnan ("imag(ctan(0 + i NaN)) = NaN", __imag__ result);
4444 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, nan_value));
4445 check ("real(ctan(-0 + i NaN)) = -0", __real__ result, minus_zero);
4446 check_isnan ("imag(ctan(-0 + i NaN)) = NaN", __imag__ result);
4448 result = FUNC(ctan) (BUILD_COMPLEX (0.5, nan_value));
4449 check_isnan_maybe_exc ("real(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4450 __real__ result, INVALID_EXCEPTION);
4451 check_isnan ("imag(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4452 __imag__ result);
4453 result = FUNC(ctan) (BUILD_COMPLEX (-4.5, nan_value));
4454 check_isnan_maybe_exc ("real(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4455 __real__ result, INVALID_EXCEPTION);
4456 check_isnan ("imag(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4457 __imag__ result);
4459 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 0));
4460 check_isnan_maybe_exc ("real(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4461 __real__ result, INVALID_EXCEPTION);
4462 check_isnan ("imag(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4463 __imag__ result);
4464 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 5));
4465 check_isnan_maybe_exc ("real(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4466 __real__ result, INVALID_EXCEPTION);
4467 check_isnan ("imag(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4468 __imag__ result);
4469 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_zero));
4470 check_isnan_maybe_exc ("real(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4471 __real__ result, INVALID_EXCEPTION);
4472 check_isnan ("imag(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4473 __imag__ result);
4474 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, -0.25));
4475 check_isnan_maybe_exc ("real(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4476 __real__ result, INVALID_EXCEPTION);
4477 check_isnan ("imag(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4478 __imag__ result);
4480 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, nan_value));
4481 check_isnan ("real(ctan(NaN + i NaN)) = NaN", __real__ result);
4482 check_isnan ("imag(ctan(NaN + i NaN)) = NaN", __imag__ result);
4484 result = FUNC(ctan) (BUILD_COMPLEX (0.7, 1.2));
4485 check_eps ("real(ctan(0.7 + i 1.2)) == 0.17207...", __real__ result,
4486 0.1720734197630349001L, CHOOSE(1e-17L, 3e-17, 2e-8));
4487 check_eps ("imag(ctan(0.7 + i 1.2)) == 0.95448...", __imag__ result,
4488 0.9544807059989405538L, CHOOSE(2e-17L, 2e-16, 6e-8));
4490 result = FUNC(ctan) (BUILD_COMPLEX (-2, -3));
4491 check_eps ("real(ctan(-2 - i 3)) == -0.00376...", __real__ result,
4492 0.0037640256415042482L, CHOOSE(1e-19L, 5e-19, 0));
4493 check_eps ("imag(ctan(-2 - i 3)) == -1.00323...", __imag__ result,
4494 -1.0032386273536098014L, CHOOSE(2e-19L, 0, 2e-7));
4498 static void
4499 ctanh_test (void)
4501 __complex__ MATHTYPE result;
4503 result = FUNC(ctanh) (BUILD_COMPLEX (0, 0));
4504 check ("real(ctanh(0 + i0)) = 0", __real__ result, 0);
4505 check ("imag(ctanh(0 + i0)) = 0", __imag__ result, 0);
4506 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_zero));
4507 check ("real(ctanh(0 - i0)) = 0", __real__ result, 0);
4508 check ("imag(ctanh(0 - i0)) = -0", __imag__ result, minus_zero);
4509 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, 0));
4510 check ("real(ctanh(-0 + i0)) = -0", __real__ result, minus_zero);
4511 check ("imag(ctanh(-0 + i0)) = 0", __imag__ result, 0);
4512 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4513 check ("real(ctanh(-0 - i0)) = -0", __real__ result, minus_zero);
4514 check ("imag(ctanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4516 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 0));
4517 check ("real(ctanh(+Inf + i0)) = 1", __real__ result, 1);
4518 check ("imag(ctanh(+Inf + i0)) = 0", __imag__ result, 0);
4519 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 1));
4520 check ("real(ctanh(+Inf + i1)) = 1", __real__ result, 1);
4521 check ("imag(ctanh(+Inf + i1)) = 0", __imag__ result, 0);
4522 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4523 check ("real(ctanh(+Inf - i0)) = 1", __real__ result, 1);
4524 check ("imag(ctanh(+Inf - i0)) = -0", __imag__ result, minus_zero);
4525 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, -1));
4526 check ("real(ctanh(+Inf - i1)) = 1", __real__ result, 1);
4527 check ("imag(ctanh(+Inf - i1)) = -0", __imag__ result, minus_zero);
4528 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 0));
4529 check ("real(ctanh(-Inf + i0)) = -1", __real__ result, -1);
4530 check ("imag(ctanh(-Inf + i0)) = 0", __imag__ result, 0);
4531 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 1));
4532 check ("real(ctanh(-Inf + i1)) = -1", __real__ result, -1);
4533 check ("imag(ctanh(-Inf + i1)) = 0", __imag__ result, 0);
4534 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4535 check ("real(ctanh(-Inf - i0)) = -1", __real__ result, -1);
4536 check ("imag(ctanh(-Inf - i0)) = -0", __imag__ result, minus_zero);
4537 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, -1));
4538 check ("real(ctanh(-Inf - i1)) = -1", __real__ result, -1);
4539 check ("imag(ctanh(-Inf - i1)) = -0", __imag__ result, minus_zero);
4541 result = FUNC(ctanh) (BUILD_COMPLEX (0, plus_infty));
4542 check_isnan_exc ("real(ctanh(0 + i Inf)) = NaN plus invalid exception",
4543 __real__ result, INVALID_EXCEPTION);
4544 check_isnan ("imag(ctanh(0 + i Inf)) = NaN plus invalid exception",
4545 __imag__ result);
4546 result = FUNC(ctanh) (BUILD_COMPLEX (2, plus_infty));
4547 check_isnan_exc ("real(ctanh(2 + i Inf)) = NaN plus invalid exception",
4548 __real__ result, INVALID_EXCEPTION);
4549 check_isnan ("imag(ctanh(2 + i Inf)) = NaN plus invalid exception",
4550 __imag__ result);
4551 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_infty));
4552 check_isnan_exc ("real(ctanh(0 - i Inf)) = NaN plus invalid exception",
4553 __real__ result, INVALID_EXCEPTION);
4554 check_isnan ("imag(ctanh(0 - i Inf)) = NaN plus invalid exception",
4555 __imag__ result);
4556 result = FUNC(ctanh) (BUILD_COMPLEX (2, minus_infty));
4557 check_isnan_exc ("real(ctanh(2 - i Inf)) = NaN plus invalid exception",
4558 __real__ result, INVALID_EXCEPTION);
4559 check_isnan ("imag(ctanh(2 - i Inf)) = NaN plus invalid exception",
4560 __imag__ result);
4561 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4562 check_isnan_exc ("real(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4563 __real__ result, INVALID_EXCEPTION);
4564 check_isnan ("imag(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4565 __imag__ result);
4566 result = FUNC(ctanh) (BUILD_COMPLEX (-2, plus_infty));
4567 check_isnan_exc ("real(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4568 __real__ result, INVALID_EXCEPTION);
4569 check_isnan ("imag(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4570 __imag__ result);
4571 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4572 check_isnan_exc ("real(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4573 __real__ result, INVALID_EXCEPTION);
4574 check_isnan ("imag(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4575 __imag__ result);
4576 result = FUNC(ctanh) (BUILD_COMPLEX (-2, minus_infty));
4577 check_isnan_exc ("real(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4578 __real__ result, INVALID_EXCEPTION);
4579 check_isnan ("imag(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4580 __imag__ result);
4582 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, nan_value));
4583 check ("real(ctanh(+Inf + i NaN)) = 1", __real__ result, 1);
4584 check ("imag(ctanh(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4585 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, nan_value));
4586 check ("real(ctanh(-Inf + i NaN)) = -1", __real__ result, -1);
4587 check ("imag(ctanh(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4589 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0));
4590 check_isnan ("real(ctanh(NaN + i0)) = NaN", __real__ result);
4591 check ("imag(ctanh(NaN + i0)) = 0", __imag__ result, 0);
4592 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, minus_zero));
4593 check_isnan ("real(ctanh(NaN - i0)) = NaN", __real__ result);
4594 check ("imag(ctanh(NaN - i0)) = -0", __imag__ result, minus_zero);
4596 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0.5));
4597 check_isnan_maybe_exc ("real(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4598 __real__ result, INVALID_EXCEPTION);
4599 check_isnan ("imag(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4600 __imag__ result);
4601 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, -4.5));
4602 check_isnan_maybe_exc ("real(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4603 __real__ result, INVALID_EXCEPTION);
4604 check_isnan ("imag(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4605 __imag__ result);
4607 result = FUNC(ctanh) (BUILD_COMPLEX (0, nan_value));
4608 check_isnan_maybe_exc ("real(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4609 __real__ result, INVALID_EXCEPTION);
4610 check_isnan ("imag(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4611 __imag__ result);
4612 result = FUNC(ctanh) (BUILD_COMPLEX (5, nan_value));
4613 check_isnan_maybe_exc ("real(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4614 __real__ result, INVALID_EXCEPTION);
4615 check_isnan ("imag(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4616 __imag__ result);
4617 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, nan_value));
4618 check_isnan_maybe_exc ("real(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4619 __real__ result, INVALID_EXCEPTION);
4620 check_isnan ("imag(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4621 __imag__ result);
4622 result = FUNC(ctanh) (BUILD_COMPLEX (-0.25, nan_value));
4623 check_isnan_maybe_exc ("real(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4624 __real__ result, INVALID_EXCEPTION);
4625 check_isnan ("imag(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4626 __imag__ result);
4628 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, nan_value));
4629 check_isnan ("real(ctanh(NaN + i NaN)) = NaN", __real__ result);
4630 check_isnan ("imag(ctanh(NaN + i NaN)) = NaN", __imag__ result);
4632 result = FUNC(ctanh) (BUILD_COMPLEX (0, M_PI_4l));
4633 check ("real(ctanh (0 + i pi/4)) == 0", __real__ result, 0);
4634 check_eps ("imag(ctanh (0 + i pi/4)) == 1", __imag__ result, 1,
4635 CHOOSE (0, 2e-16, 2e-7));
4637 result = FUNC(ctanh) (BUILD_COMPLEX (0.7, 1.2));
4638 check_eps ("real(ctanh(0.7 + i 1.2)) == 1.34721...", __real__ result,
4639 1.3472197399061191630L, CHOOSE(4e-17L, 5e-16, 2e-7));
4640 check_eps ("imag(ctanh(0.7 + i 1.2)) == -0.47786...", __imag__ result,
4641 0.4778641038326365540L, CHOOSE(9e-17L, 2e-16, 9e-8));
4643 result = FUNC(ctanh) (BUILD_COMPLEX (-2, -3));
4644 check_eps ("real(ctanh(-2 - i 3)) == -0.96538...", __real__ result,
4645 -0.9653858790221331242L, CHOOSE(2e-19L, 2e-16, 2e-7));
4646 check_eps ("imag(ctanh(-2 - i 3)) == 0.00988...", __imag__ result,
4647 0.0098843750383224937L, CHOOSE(7e-20L, 2e-16, 1e-9));
4651 static void
4652 clog_test (void)
4654 __complex__ MATHTYPE result;
4656 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, 0));
4657 check_isinfn_exc ("real(clog(-0 + i0)) = -Inf plus divide-by-zero exception",
4658 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4659 check ("imag(clog(-0 + i0)) = pi plus divide-by-zero exception",
4660 __imag__ result, M_PIl);
4661 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_zero));
4662 check_isinfn_exc ("real(clog(-0 - i0)) = -Inf plus divide-by-zero exception",
4663 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4664 check ("imag(clog(-0 - i0)) = -pi plus divide-by-zero exception",
4665 __imag__ result, -M_PIl);
4667 result = FUNC(clog) (BUILD_COMPLEX (0, 0));
4668 check_isinfn_exc ("real(clog(0 + i0)) = -Inf plus divide-by-zero exception",
4669 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4670 check ("imag(clog(0 + i0)) = 0 plus divide-by-zero exception",
4671 __imag__ result, 0);
4672 result = FUNC(clog) (BUILD_COMPLEX (0, minus_zero));
4673 check_isinfn_exc ("real(clog(0 - i0)) = -Inf plus divide-by-zero exception",
4674 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4675 check ("imag(clog(0 - i0)) = -0 plus divide-by-zero exception",
4676 __imag__ result, minus_zero);
4678 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, plus_infty));
4679 check_isinfp ("real(clog(-Inf + i Inf)) = +Inf", __real__ result);
4680 check ("imag(clog(-Inf + i Inf)) = 3*pi/4", __imag__ result,
4681 M_PIl - M_PI_4l);
4682 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_infty));
4683 check_isinfp ("real(clog(-Inf - i Inf)) = +Inf", __real__ result);
4684 check ("imag(clog(-Inf - i Inf)) = -3*pi/4", __imag__ result,
4685 M_PI_4l - M_PIl);
4687 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, plus_infty));
4688 check_isinfp ("real(clog(+Inf + i Inf)) = +Inf", __real__ result);
4689 check ("imag(clog(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
4690 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_infty));
4691 check_isinfp ("real(clog(+Inf - i Inf)) = +Inf", __real__ result);
4692 check ("imag(clog(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
4694 result = FUNC(clog) (BUILD_COMPLEX (0, plus_infty));
4695 check_isinfp ("real(clog(0 + i Inf)) = +Inf", __real__ result);
4696 check ("imag(clog(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4697 result = FUNC(clog) (BUILD_COMPLEX (3, plus_infty));
4698 check_isinfp ("real(clog(3 + i Inf)) = +Inf", __real__ result);
4699 check ("imag(clog(3 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4700 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, plus_infty));
4701 check_isinfp ("real(clog(-0 + i Inf)) = +Inf", __real__ result);
4702 check ("imag(clog(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4703 result = FUNC(clog) (BUILD_COMPLEX (-3, plus_infty));
4704 check_isinfp ("real(clog(-3 + i Inf)) = +Inf", __real__ result);
4705 check ("imag(clog(-3 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4706 result = FUNC(clog) (BUILD_COMPLEX (0, minus_infty));
4707 check_isinfp ("real(clog(0 - i Inf)) = +Inf", __real__ result);
4708 check ("imag(clog(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4709 result = FUNC(clog) (BUILD_COMPLEX (3, minus_infty));
4710 check_isinfp ("real(clog(3 - i Inf)) = +Inf", __real__ result);
4711 check ("imag(clog(3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4712 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_infty));
4713 check_isinfp ("real(clog(-0 - i Inf)) = +Inf", __real__ result);
4714 check ("imag(clog(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4715 result = FUNC(clog) (BUILD_COMPLEX (-3, minus_infty));
4716 check_isinfp ("real(clog(-3 - i Inf)) = +Inf", __real__ result);
4717 check ("imag(clog(-3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4719 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 0));
4720 check_isinfp ("real(clog(-Inf + i0)) = +Inf", __real__ result);
4721 check ("imag(clog(-Inf + i0)) = pi", __imag__ result, M_PIl);
4722 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 1));
4723 check_isinfp ("real(clog(-Inf + i1)) = +Inf", __real__ result);
4724 check ("imag(clog(-Inf + i1)) = pi", __imag__ result, M_PIl);
4725 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_zero));
4726 check_isinfp ("real(clog(-Inf - i0)) = +Inf", __real__ result);
4727 check ("imag(clog(-Inf - i0)) = -pi", __imag__ result, -M_PIl);
4728 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, -1));
4729 check_isinfp ("real(clog(-Inf - i1)) = +Inf", __real__ result);
4730 check ("imag(clog(-Inf - i1)) = -pi", __imag__ result, -M_PIl);
4732 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 0));
4733 check_isinfp ("real(clog(+Inf + i0)) = +Inf", __real__ result);
4734 check ("imag(clog(+Inf + i0)) = 0", __imag__ result, 0);
4735 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 1));
4736 check_isinfp ("real(clog(+Inf + i1)) = +Inf", __real__ result);
4737 check ("imag(clog(+Inf + i1)) = 0", __imag__ result, 0);
4738 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_zero));
4739 check_isinfp ("real(clog(+Inf - i0)) = +Inf", __real__ result);
4740 check ("imag(clog(+Inf - i0)) = -0", __imag__ result, minus_zero);
4741 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, -1));
4742 check_isinfp ("real(clog(+Inf - i1)) = +Inf", __real__ result);
4743 check ("imag(clog(+Inf - i1)) = -0", __imag__ result, minus_zero);
4745 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, nan_value));
4746 check_isinfp ("real(clog(+Inf + i NaN)) = +Inf", __real__ result);
4747 check_isnan ("imag(clog(+Inf + i NaN)) = NaN", __imag__ result);
4748 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, nan_value));
4749 check_isinfp ("real(clog(-Inf + i NaN)) = +Inf", __real__ result);
4750 check_isnan ("imag(clog(-Inf + i NaN)) = NaN", __imag__ result);
4752 result = FUNC(clog) (BUILD_COMPLEX (nan_value, plus_infty));
4753 check_isinfp ("real(clog(NaN + i Inf)) = +Inf", __real__ result);
4754 check_isnan ("imag(clog(NaN + i Inf)) = NaN", __imag__ result);
4755 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_infty));
4756 check_isinfp ("real(clog(NaN - i Inf)) = +Inf", __real__ result);
4757 check_isnan ("imag(clog(NaN - i Inf)) = NaN", __imag__ result);
4759 result = FUNC(clog) (BUILD_COMPLEX (0, nan_value));
4760 check_isnan_maybe_exc ("real(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4761 __real__ result, INVALID_EXCEPTION);
4762 check_isnan ("imag(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4763 __imag__ result);
4764 result = FUNC(clog) (BUILD_COMPLEX (3, nan_value));
4765 check_isnan_maybe_exc ("real(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4766 __real__ result, INVALID_EXCEPTION);
4767 check_isnan ("imag(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4768 __imag__ result);
4769 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, nan_value));
4770 check_isnan_maybe_exc ("real(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4771 __real__ result, INVALID_EXCEPTION);
4772 check_isnan ("imag(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4773 __imag__ result);
4774 result = FUNC(clog) (BUILD_COMPLEX (-3, nan_value));
4775 check_isnan_maybe_exc ("real(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4776 __real__ result, INVALID_EXCEPTION);
4777 check_isnan ("imag(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4778 __imag__ result);
4780 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 0));
4781 check_isnan_maybe_exc ("real(clog(NaN + i0)) = NaN plus maybe invalid exception",
4782 __real__ result, INVALID_EXCEPTION);
4783 check_isnan ("imag(clog(NaN + i0)) = NaN plus maybe invalid exception",
4784 __imag__ result);
4785 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 5));
4786 check_isnan_maybe_exc ("real(clog(NaN + i5)) = NaN plus maybe invalid exception",
4787 __real__ result, INVALID_EXCEPTION);
4788 check_isnan ("imag(clog(NaN + i5)) = NaN plus maybe invalid exception",
4789 __imag__ result);
4790 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_zero));
4791 check_isnan_maybe_exc ("real(clog(NaN - i0)) = NaN plus maybe invalid exception",
4792 __real__ result, INVALID_EXCEPTION);
4793 check_isnan ("imag(clog(NaN - i0)) = NaN plus maybe invalid exception",
4794 __imag__ result);
4795 result = FUNC(clog) (BUILD_COMPLEX (nan_value, -5));
4796 check_isnan_maybe_exc ("real(clog(NaN - i5)) = NaN plus maybe invalid exception",
4797 __real__ result, INVALID_EXCEPTION);
4798 check_isnan ("imag(clog(NaN - i5)) = NaN plus maybe invalid exception",
4799 __imag__ result);
4801 result = FUNC(clog) (BUILD_COMPLEX (nan_value, nan_value));
4802 check_isnan ("real(clog(NaN + i NaN)) = NaN", __real__ result);
4803 check_isnan ("imag(clog(NaN + i NaN)) = NaN", __imag__ result);
4805 result = FUNC(clog) (BUILD_COMPLEX (0.7, 1.2));
4806 check_eps ("real(clog(0.7 + i 1.2)) == 0.32876...", __real__ result,
4807 0.3287600014583970919L, CHOOSE(5e-17L, 6e-17, 3e-8));
4808 check_eps ("imag(clog(0.7 + i 1.2)) == 1.04272...", __imag__ result,
4809 1.0427218783685369524L, CHOOSE(2e-17L, 0, 0));
4811 result = FUNC(clog) (BUILD_COMPLEX (-2, -3));
4812 check_eps ("real(clog(-2 - i 3)) == 1.28247...", __real__ result,
4813 1.2824746787307683680L, CHOOSE(3e-19L, 0, 0));
4814 check_eps ("imag(clog(-2 - i 3)) == -2.15879...", __imag__ result,
4815 -2.1587989303424641704L, CHOOSE(2e-18L, 5e-16, 8e-7));
4819 static void
4820 clog10_test (void)
4822 __complex__ MATHTYPE result;
4824 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, 0));
4825 check_isinfn_exc ("real(clog10(-0 + i0)) = -Inf plus divide-by-zero exception",
4826 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4827 check ("imag(clog10(-0 + i0)) = pi plus divide-by-zero exception",
4828 __imag__ result, M_PIl);
4829 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_zero));
4830 check_isinfn_exc ("real(clog10(-0 - i0)) = -Inf plus divide-by-zero exception",
4831 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4832 check ("imag(clog10(-0 - i0)) = -pi plus divide-by-zero exception",
4833 __imag__ result, -M_PIl);
4835 result = FUNC(clog10) (BUILD_COMPLEX (0, 0));
4836 check_isinfn_exc ("real(clog10(0 + i0)) = -Inf plus divide-by-zero exception",
4837 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4838 check ("imag(clog10(0 + i0)) = 0 plus divide-by-zero exception",
4839 __imag__ result, 0);
4840 result = FUNC(clog10) (BUILD_COMPLEX (0, minus_zero));
4841 check_isinfn_exc ("real(clog10(0 - i0)) = -Inf plus divide-by-zero exception",
4842 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4843 check ("imag(clog10(0 - i0)) = -0 plus divide-by-zero exception",
4844 __imag__ result, minus_zero);
4846 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, plus_infty));
4847 check_isinfp ("real(clog10(-Inf + i Inf)) = +Inf", __real__ result);
4848 check_eps ("imag(clog10(-Inf + i Inf)) = 3*pi/4*M_LOG10E", __imag__ result,
4849 (M_PIl - M_PI_4l) * M_LOG10El, CHOOSE (0, 3e-16, 0));
4850 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_infty));
4851 check_isinfp ("real(clog10(-Inf - i Inf)) = +Inf", __real__ result);
4852 check_eps ("imag(clog10(-Inf - i Inf)) = -3*pi/4*M_LOG10E", __imag__ result,
4853 (M_PI_4l - M_PIl) * M_LOG10El, CHOOSE (0, 3e-16, 0));
4855 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, plus_infty));
4856 check_isinfp ("real(clog10(+Inf + i Inf)) = +Inf", __real__ result);
4857 check_eps ("imag(clog10(+Inf + i Inf)) = pi/4*M_LOG10E", __imag__ result,
4858 M_PI_4l * M_LOG10El, CHOOSE (0, 6e-17, 3e-8));
4859 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_infty));
4860 check_isinfp ("real(clog10(+Inf - i Inf)) = +Inf", __real__ result);
4861 check_eps ("imag(clog10(+Inf - i Inf)) = -pi/4*M_LOG10E", __imag__ result,
4862 -M_PI_4l * M_LOG10El, CHOOSE (0, 6e-17, 3e-8));
4864 result = FUNC(clog10) (BUILD_COMPLEX (0, plus_infty));
4865 check_isinfp ("real(clog10(0 + i Inf)) = +Inf", __real__ result);
4866 check_eps ("imag(clog10(0 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4867 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4868 result = FUNC(clog10) (BUILD_COMPLEX (3, plus_infty));
4869 check_isinfp ("real(clog10(3 + i Inf)) = +Inf", __real__ result);
4870 check_eps ("imag(clog10(3 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4871 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4872 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, plus_infty));
4873 check_isinfp ("real(clog10(-0 + i Inf)) = +Inf", __real__ result);
4874 check_eps ("imag(clog10(-0 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4875 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4876 result = FUNC(clog10) (BUILD_COMPLEX (-3, plus_infty));
4877 check_isinfp ("real(clog10(-3 + i Inf)) = +Inf", __real__ result);
4878 check_eps ("imag(clog10(-3 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4879 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4880 result = FUNC(clog10) (BUILD_COMPLEX (0, minus_infty));
4881 check_isinfp ("real(clog10(0 - i Inf)) = +Inf", __real__ result);
4882 check_eps ("imag(clog10(0 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4883 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4884 result = FUNC(clog10) (BUILD_COMPLEX (3, minus_infty));
4885 check_isinfp ("real(clog10(3 - i Inf)) = +Inf", __real__ result);
4886 check_eps ("imag(clog10(3 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4887 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4888 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_infty));
4889 check_isinfp ("real(clog10(-0 - i Inf)) = +Inf", __real__ result);
4890 check_eps ("imag(clog10(-0 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4891 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4892 result = FUNC(clog10) (BUILD_COMPLEX (-3, minus_infty));
4893 check_isinfp ("real(clog10(-3 - i Inf)) = +Inf", __real__ result);
4894 check_eps ("imag(clog10(-3 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4895 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4897 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 0));
4898 check_isinfp ("real(clog10(-Inf + i0)) = +Inf", __real__ result);
4899 check_eps ("imag(clog10(-Inf + i0)) = pi*M_LOG10E", __imag__ result,
4900 M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4901 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 1));
4902 check_isinfp ("real(clog10(-Inf + i1)) = +Inf", __real__ result);
4903 check_eps ("imag(clog10(-Inf + i1)) = pi*M_LOG10E", __imag__ result,
4904 M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4905 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_zero));
4906 check_isinfp ("real(clog10(-Inf - i0)) = +Inf", __real__ result);
4907 check_eps ("imag(clog10(-Inf - i0)) = -pi*M_LOG10E", __imag__ result,
4908 -M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4909 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, -1));
4910 check_isinfp ("real(clog10(-Inf - i1)) = +Inf", __real__ result);
4911 check_eps ("imag(clog10(-Inf - i1)) = -pi*M_LOG10E", __imag__ result,
4912 -M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4914 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 0));
4915 check_isinfp ("real(clog10(+Inf + i0)) = +Inf", __real__ result);
4916 check ("imag(clog10(+Inf + i0)) = 0", __imag__ result, 0);
4917 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 1));
4918 check_isinfp ("real(clog10(+Inf + i1)) = +Inf", __real__ result);
4919 check ("imag(clog10(+Inf + i1)) = 0", __imag__ result, 0);
4920 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_zero));
4921 check_isinfp ("real(clog10(+Inf - i0)) = +Inf", __real__ result);
4922 check ("imag(clog10(+Inf - i0)) = -0", __imag__ result, minus_zero);
4923 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, -1));
4924 check_isinfp ("real(clog10(+Inf - i1)) = +Inf", __real__ result);
4925 check ("imag(clog10(+Inf - i1)) = -0", __imag__ result, minus_zero);
4927 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, nan_value));
4928 check_isinfp ("real(clog10(+Inf + i NaN)) = +Inf", __real__ result);
4929 check_isnan ("imag(clog10(+Inf + i NaN)) = NaN", __imag__ result);
4930 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, nan_value));
4931 check_isinfp ("real(clog10(-Inf + i NaN)) = +Inf", __real__ result);
4932 check_isnan ("imag(clog10(-Inf + i NaN)) = NaN", __imag__ result);
4934 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, plus_infty));
4935 check_isinfp ("real(clog10(NaN + i Inf)) = +Inf", __real__ result);
4936 check_isnan ("imag(clog10(NaN + i Inf)) = NaN", __imag__ result);
4937 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_infty));
4938 check_isinfp ("real(clog10(NaN - i Inf)) = +Inf", __real__ result);
4939 check_isnan ("imag(clog10(NaN - i Inf)) = NaN", __imag__ result);
4941 result = FUNC(clog10) (BUILD_COMPLEX (0, nan_value));
4942 check_isnan_maybe_exc ("real(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4943 __real__ result, INVALID_EXCEPTION);
4944 check_isnan ("imag(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4945 __imag__ result);
4946 result = FUNC(clog10) (BUILD_COMPLEX (3, nan_value));
4947 check_isnan_maybe_exc ("real(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4948 __real__ result, INVALID_EXCEPTION);
4949 check_isnan ("imag(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4950 __imag__ result);
4951 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, nan_value));
4952 check_isnan_maybe_exc ("real(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4953 __real__ result, INVALID_EXCEPTION);
4954 check_isnan ("imag(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4955 __imag__ result);
4956 result = FUNC(clog10) (BUILD_COMPLEX (-3, nan_value));
4957 check_isnan_maybe_exc ("real(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4958 __real__ result, INVALID_EXCEPTION);
4959 check_isnan ("imag(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4960 __imag__ result);
4962 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 0));
4963 check_isnan_maybe_exc ("real(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4964 __real__ result, INVALID_EXCEPTION);
4965 check_isnan ("imag(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4966 __imag__ result);
4967 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 5));
4968 check_isnan_maybe_exc ("real(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4969 __real__ result, INVALID_EXCEPTION);
4970 check_isnan ("imag(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4971 __imag__ result);
4972 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_zero));
4973 check_isnan_maybe_exc ("real(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4974 __real__ result, INVALID_EXCEPTION);
4975 check_isnan ("imag(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4976 __imag__ result);
4977 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, -5));
4978 check_isnan_maybe_exc ("real(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4979 __real__ result, INVALID_EXCEPTION);
4980 check_isnan ("imag(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4981 __imag__ result);
4983 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, nan_value));
4984 check_isnan ("real(clog10(NaN + i NaN)) = NaN", __real__ result);
4985 check_isnan ("imag(clog10(NaN + i NaN)) = NaN", __imag__ result);
4987 result = FUNC(clog10) (BUILD_COMPLEX (0.7, 1.2));
4988 check_eps ("real(clog10(0.7 + i 1.2)) == 0.14277...", __real__ result,
4989 0.1427786545038868803L, CHOOSE(2e-17L, 6e-17, 2e-8));
4990 check_eps ("imag(clog10(0.7 + i 1.2)) == 0.45284...", __imag__ result,
4991 0.4528483579352493248L, CHOOSE(6e-18, 6e-17, 3e-8));
4993 result = FUNC(clog10) (BUILD_COMPLEX (-2, -3));
4994 check_eps ("real(clog10(-2 - i 3)) == 0.55697...", __real__ result,
4995 0.5569716761534183846L, CHOOSE(6e-20L, 0, 0));
4996 check_eps ("imag(clog10(-2 - i 3)) == -0.93755...", __imag__ result,
4997 -0.9375544629863747085L, CHOOSE (7e-19L, 2e-16, 3e-7));
5001 static void
5002 csqrt_test (void)
5004 __complex__ MATHTYPE result;
5006 result = FUNC(csqrt) (BUILD_COMPLEX (0, 0));
5007 check ("real(csqrt(0 + i0)) = 0", __real__ result, 0);
5008 check ("imag(csqrt(0 + i0)) = 0", __imag__ result, 0);
5009 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_zero));
5010 check ("real(csqrt(0 - i0)) = 0", __real__ result, 0);
5011 check ("imag(csqrt(0 - i0)) = -0", __imag__ result, minus_zero);
5012 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, 0));
5013 check ("real(csqrt(-0 + i0)) = 0", __real__ result, 0);
5014 check ("imag(csqrt(-0 + i0)) = 0", __imag__ result, 0);
5015 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_zero));
5016 check ("real(csqrt(-0 - i0)) = 0", __real__ result, 0);
5017 check ("imag(csqrt(-0 - i0)) = -0", __imag__ result, minus_zero);
5019 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 0));
5020 check ("real(csqrt(-Inf + i0)) = 0", __real__ result, 0);
5021 check_isinfp ("imag(csqrt(-Inf + i0)) = +Inf", __imag__ result);
5022 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 6));
5023 check ("real(csqrt(-Inf + i6)) = 0", __real__ result, 0);
5024 check_isinfp ("imag(csqrt(-Inf + i6)) = +Inf", __imag__ result);
5025 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_zero));
5026 check ("real(csqrt(-Inf - i0)) = 0", __real__ result, 0);
5027 check_isinfn ("imag(csqrt(-Inf - i0)) = -Inf", __imag__ result);
5028 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, -6));
5029 check ("real(csqrt(-Inf - i6)) = 0", __real__ result, 0);
5030 check_isinfn ("imag(csqrt(-Inf - i6)) = -Inf", __imag__ result);
5032 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 0));
5033 check_isinfp ("real(csqrt(+Inf + i0)) = +Inf", __real__ result);
5034 check ("imag(csqrt(+Inf + i0)) = 0", __imag__ result, 0);
5035 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 6));
5036 check_isinfp ("real(csqrt(+Inf + i6)) = +Inf", __real__ result);
5037 check ("imag(csqrt(+Inf + i6)) = 0", __imag__ result, 0);
5038 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_zero));
5039 check_isinfp ("real(csqrt(+Inf - i0)) = +Inf", __real__ result);
5040 check ("imag(csqrt(+Inf - i0)) = -0", __imag__ result, minus_zero);
5041 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, -6));
5042 check_isinfp ("real(csqrt(+Inf - i6)) = +Inf", __real__ result);
5043 check ("imag(csqrt(+Inf - i6)) = -0", __imag__ result, minus_zero);
5045 result = FUNC(csqrt) (BUILD_COMPLEX (0, plus_infty));
5046 check_isinfp ("real(csqrt(0 + i Inf)) = +Inf", __real__ result);
5047 check_isinfp ("imag(csqrt(0 + i Inf)) = +Inf", __imag__ result);
5048 result = FUNC(csqrt) (BUILD_COMPLEX (4, plus_infty));
5049 check_isinfp ("real(csqrt(4 + i Inf)) = +Inf", __real__ result);
5050 check_isinfp ("imag(csqrt(4 + i Inf)) = +Inf", __imag__ result);
5051 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, plus_infty));
5052 check_isinfp ("real(csqrt(+Inf + i Inf)) = +Inf", __real__ result);
5053 check_isinfp ("imag(csqrt(+Inf + i Inf)) = +Inf", __imag__ result);
5054 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, plus_infty));
5055 check_isinfp ("real(csqrt(-0 + i Inf)) = +Inf", __real__ result);
5056 check_isinfp ("imag(csqrt(-0 + i Inf)) = +Inf", __imag__ result);
5057 result = FUNC(csqrt) (BUILD_COMPLEX (-4, plus_infty));
5058 check_isinfp ("real(csqrt(-4 + i Inf)) = +Inf", __real__ result);
5059 check_isinfp ("imag(csqrt(-4 + i Inf)) = +Inf", __imag__ result);
5060 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, plus_infty));
5061 check_isinfp ("real(csqrt(-Inf + i Inf)) = +Inf", __real__ result);
5062 check_isinfp ("imag(csqrt(-Inf + i Inf)) = +Inf", __imag__ result);
5063 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_infty));
5064 check_isinfp ("real(csqrt(0 - i Inf)) = +Inf", __real__ result);
5065 check_isinfn ("imag(csqrt(0 - i Inf)) = -Inf", __imag__ result);
5066 result = FUNC(csqrt) (BUILD_COMPLEX (4, minus_infty));
5067 check_isinfp ("real(csqrt(4 - i Inf)) = +Inf", __real__ result);
5068 check_isinfn ("imag(csqrt(4 - i Inf)) = -Inf", __imag__ result);
5069 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_infty));
5070 check_isinfp ("real(csqrt(+Inf - i Inf)) = +Inf", __real__ result);
5071 check_isinfn ("imag(csqrt(+Inf - i Inf)) = -Inf", __imag__ result);
5072 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_infty));
5073 check_isinfp ("real(csqrt(-0 - i Inf)) = +Inf", __real__ result);
5074 check_isinfn ("imag(csqrt(-0 - i Inf)) = -Inf", __imag__ result);
5075 result = FUNC(csqrt) (BUILD_COMPLEX (-4, minus_infty));
5076 check_isinfp ("real(csqrt(-4 - i Inf)) = +Inf", __real__ result);
5077 check_isinfn ("imag(csqrt(-4 - i Inf)) = -Inf", __imag__ result);
5078 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_infty));
5079 check_isinfp ("real(csqrt(-Inf - i Inf)) = +Inf", __real__ result);
5080 check_isinfn ("imag(csqrt(-Inf - i Inf)) = -Inf", __imag__ result);
5082 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, nan_value));
5083 check_isnan ("real(csqrt(-Inf + i NaN)) = NaN", __real__ result);
5084 check_isinfp ("imag(csqrt(-Inf + i NaN)) = +-Inf",
5085 FUNC(fabs) (__imag__ result));
5087 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, nan_value));
5088 check_isinfp ("real(csqrt(+Inf + i NaN)) = +Inf", __real__ result);
5089 check_isnan ("imag(csqrt(+Inf + i NaN)) = NaN", __imag__ result);
5091 result = FUNC(csqrt) (BUILD_COMPLEX (0, nan_value));
5092 check_isnan_maybe_exc ("real(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
5093 __real__ result, INVALID_EXCEPTION);
5094 check_isnan ("imag(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
5095 __imag__ result);
5096 result = FUNC(csqrt) (BUILD_COMPLEX (1, nan_value));
5097 check_isnan_maybe_exc ("real(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
5098 __real__ result, INVALID_EXCEPTION);
5099 check_isnan ("imag(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
5100 __imag__ result);
5101 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, nan_value));
5102 check_isnan_maybe_exc ("real(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
5103 __real__ result, INVALID_EXCEPTION);
5104 check_isnan ("imag(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
5105 __imag__ result);
5106 result = FUNC(csqrt) (BUILD_COMPLEX (-1, nan_value));
5107 check_isnan_maybe_exc ("real(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
5108 __real__ result, INVALID_EXCEPTION);
5109 check_isnan ("imag(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
5110 __imag__ result);
5112 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 0));
5113 check_isnan_maybe_exc ("real(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
5114 __real__ result, INVALID_EXCEPTION);
5115 check_isnan ("imag(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
5116 __imag__ result);
5117 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 8));
5118 check_isnan_maybe_exc ("real(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
5119 __real__ result, INVALID_EXCEPTION);
5120 check_isnan ("imag(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
5121 __imag__ result);
5122 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, minus_zero));
5123 check_isnan_maybe_exc ("real(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
5124 __real__ result, INVALID_EXCEPTION);
5125 check_isnan ("imag(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
5126 __imag__ result);
5127 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, -8));
5128 check_isnan_maybe_exc ("real(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
5129 __real__ result, INVALID_EXCEPTION);
5130 check_isnan ("imag(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
5131 __imag__ result);
5133 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, nan_value));
5134 check_isnan ("real(csqrt(NaN + i NaN)) = NaN", __real__ result);
5135 check_isnan ("imag(csqrt(NaN + i NaN)) = NaN", __imag__ result);
5137 result = FUNC(csqrt) (BUILD_COMPLEX (16.0, -30.0));
5138 check ("real(csqrt(16 - 30i)) = 5", __real__ result, 5.0);
5139 check ("imag(csqrt(16 - 30i)) = -3", __imag__ result, -3.0);
5141 result = FUNC(csqrt) (BUILD_COMPLEX (-1, 0));
5142 check ("real(csqrt(1 + i0) = 0", __real__ result, 0);
5143 check ("imag(csqrt(1 + i0) = 1", __imag__ result, 1);
5145 result = FUNC(csqrt) (BUILD_COMPLEX (0, 2));
5146 check ("real(csqrt(0 + i 2) = 1", __real__ result, 1);
5147 check ("imag(csqrt(0 + i 2) = 1", __imag__ result, 1);
5149 result = FUNC(csqrt) (BUILD_COMPLEX (119, 120));
5150 check ("real(csqrt(119 + i 120) = 12", __real__ result, 12);
5151 check ("imag(csqrt(119 + i 120) = 5", __imag__ result, 5);
5153 result = FUNC(csqrt) (BUILD_COMPLEX (0.7, 1.2));
5154 check_eps ("real(csqrt(0.7 + i 1.2)) == 1.02206...", __real__ result,
5155 1.0220676100300264507L, CHOOSE(3e-17L, 3e-16, 2e-7));
5156 check_eps ("imag(csqrt(0.7 + i 1.2)) == 0.58704...", __imag__ result,
5157 0.5870453129635652115L, CHOOSE(7e-18L, 0, 6e-8));
5159 result = FUNC(csqrt) (BUILD_COMPLEX (-2, -3));
5160 check_eps ("real(csqrt(-2 - i 3)) == 0.89597...", __real__ result,
5161 0.8959774761298381247L, CHOOSE(6e-16L, 4e-16, 6e-8));
5162 check_eps ("imag(csqrt(-2 - i 3)) == -1.67414...", __imag__ result,
5163 -1.6741492280355400404L, CHOOSE(0, 5e-16, 0));
5165 result = FUNC(csqrt) (BUILD_COMPLEX (-2, 3));
5166 check_eps ("real(csqrt(-2 + i 3)) == 0.89597...", __real__ result,
5167 0.8959774761298381247L, CHOOSE(6e-20L, 4e-16, 6e-8));
5168 check_eps ("imag(csqrt(-2 + i 3)) == 1.67414...", __imag__ result,
5169 1.6741492280355400404L, CHOOSE(0, 5e-16, 0));
5173 static void
5174 cpow_test (void)
5176 __complex__ MATHTYPE result;
5178 result = FUNC (cpow) (BUILD_COMPLEX (1, 0), BUILD_COMPLEX (0, 0));
5179 check ("real(cpow (1 + i0), (0 + i0)) == 0", __real__ result, 1);
5180 check ("imag(cpow (1 + i0), (0 + i0)) == 0", __imag__ result, 0);
5182 result = FUNC (cpow) (BUILD_COMPLEX (2, 0), BUILD_COMPLEX (10, 0));
5183 check_eps ("real(cpow (2 + i0), (10 + i0)) == 1024", __real__ result, 1024,
5184 CHOOSE (2e-16L, 0, 0));
5185 check ("imag(cpow (2 + i0), (10 + i0)) == 0", __imag__ result, 0);
5187 result = FUNC (cpow) (BUILD_COMPLEX (M_El, 0), BUILD_COMPLEX (0, 2 * M_PIl));
5188 check_eps ("real(cpow (e + i0), (0 + i 2*PI)) == 1", __real__ result, 1,
5189 CHOOSE (0, 0, 6e-8));
5190 check_eps ("imag(cpow (e + i0), (0 + i 2*PI)) == 0", __imag__ result, 0,
5191 CHOOSE (3e-18L, 3e-16, 4e-7));
5193 result = FUNC (cpow) (BUILD_COMPLEX (2, 3), BUILD_COMPLEX (4, 0));
5194 check_eps ("real(cpow (2 + i3), (4 + i0)) == -119", __real__ result, -119,
5195 CHOOSE (9e-16L, 2e-14, 4e-5));
5196 check_eps ("imag(cpow (2 + i3), (4 + i0)) == -120", __imag__ result, -120,
5197 CHOOSE (1e-15L, 0, 5e-5));
5201 static void
5202 cabs_test (void)
5204 /* cabs (x + iy) is specified as hypot (x,y) */
5205 MATHTYPE a;
5206 a = random_greater (0);
5207 check_isinfp_ext ("cabs (+inf + i x) == +inf",
5208 FUNC(cabs) (BUILD_COMPLEX (plus_infty, a)), a);
5209 check_isinfp_ext ("cabs (-inf + i x) == +inf",
5210 FUNC(cabs) (BUILD_COMPLEX (minus_infty, a)), a);
5212 check_isinfp ("cabs (+inf+ iNaN) == +inf",
5213 FUNC(cabs) (BUILD_COMPLEX(minus_infty, nan_value)));
5214 check_isinfp ("cabs (-inf+ iNaN) == +inf",
5215 FUNC(cabs) (BUILD_COMPLEX(minus_infty, nan_value)));
5217 check_isnan ("cabs (NaN+ iNaN) == NaN",
5218 FUNC(cabs) (BUILD_COMPLEX(nan_value, nan_value)));
5220 a = FUNC(cabs) (BUILD_COMPLEX (12.4L, 0.7L));
5221 check ("cabs (x,y) == cabs (y,x)",
5222 FUNC(cabs) (BUILD_COMPLEX(0.7L, 12.4L)), a);
5223 check ("cabs (x,y) == cabs (-x,y)",
5224 FUNC(cabs) (BUILD_COMPLEX(-12.4L, 0.7L)), a);
5225 check ("cabs (x,y) == cabs (-y,x)",
5226 FUNC(cabs) (BUILD_COMPLEX(-0.7L, 12.4L)), a);
5227 check ("cabs (x,y) == cabs (-x,-y)",
5228 FUNC(cabs) (BUILD_COMPLEX(-12.4L, -0.7L)), a);
5229 check ("cabs (x,y) == cabs (-y,-x)",
5230 FUNC(cabs) (BUILD_COMPLEX(-0.7L, -12.4L)), a);
5231 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-0.7L, 0)), 0.7L);
5232 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(0.7L, 0)), 0.7L);
5233 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-1.0L, 0)), 1.0L);
5234 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(1.0L, 0)), 1.0L);
5235 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-5.7e7L, 0)),
5236 5.7e7L);
5237 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(5.7e7L, 0)),
5238 5.7e7L);
5240 check_eps ("cabs (0.7 + i 1.2) == 1.38924...", FUNC(cabs) (BUILD_COMPLEX(0.7, 1.2)),
5241 1.3892443989449804508L, CHOOSE(7e-17L, 3e-16, 0));
5245 static void
5246 carg_test (void)
5248 /* carg (x + iy) is specified as atan2 (y, x) */
5249 MATHTYPE x;
5251 x = random_greater (0);
5252 check ("carg (x + i 0) == 0 for x > 0",
5253 FUNC(carg) (BUILD_COMPLEX(x, 0)), 0);
5254 x = random_greater (0);
5255 check ("carg (x - i 0) == -0 for x > 0",
5256 FUNC(carg) (BUILD_COMPLEX(x, minus_zero)), minus_zero);
5258 check ("carg (+0 + i 0) == +0", FUNC(carg) (BUILD_COMPLEX(0, 0)), 0);
5259 check ("carg (+0 - i 0) == -0", FUNC(carg) (BUILD_COMPLEX(0, minus_zero)),
5260 minus_zero);
5262 x = -random_greater (0);
5263 check ("carg (x + i 0) == +pi for x < 0", FUNC(carg) (BUILD_COMPLEX(x, 0)),
5264 M_PIl);
5266 x = -random_greater (0);
5267 check ("carg (x - i 0) == -pi for x < 0",
5268 FUNC(carg) (BUILD_COMPLEX(x, minus_zero)), -M_PIl);
5270 check ("carg (-0 + i 0) == +pi", FUNC(carg) (BUILD_COMPLEX(minus_zero, 0)),
5271 M_PIl);
5272 check ("carg (-0 - i 0) == -pi",
5273 FUNC(carg) (BUILD_COMPLEX(minus_zero, minus_zero)), -M_PIl);
5275 x = random_greater (0);
5276 check ("carg (+0 + i y) == pi/2 for y > 0", FUNC(carg) (BUILD_COMPLEX(0, x)),
5277 M_PI_2l);
5279 x = random_greater (0);
5280 check ("carg (-0 + i y) == pi/2 for y > 0",
5281 FUNC(carg) (BUILD_COMPLEX(minus_zero, x)), M_PI_2l);
5283 x = random_less (0);
5284 check ("carg (+0 + i y) == -pi/2 for y < 0", FUNC(carg) (BUILD_COMPLEX(0, x)),
5285 -M_PI_2l);
5287 x = random_less (0);
5288 check ("carg (-0 + i y) == -pi/2 for y < 0",
5289 FUNC(carg) (BUILD_COMPLEX(minus_zero, x)), -M_PI_2l);
5291 x = random_greater (0);
5292 check ("carg (inf + i y) == +0 for finite y > 0",
5293 FUNC(carg) (BUILD_COMPLEX(plus_infty, x)), 0);
5295 x = -random_greater (0);
5296 check ("carg (inf + i y) == -0 for finite y < 0",
5297 FUNC(carg) (BUILD_COMPLEX(plus_infty, x)), minus_zero);
5299 x = random_value (-1e4, 1e4);
5300 check ("carg(x + i inf) == pi/2 for finite x",
5301 FUNC(carg) (BUILD_COMPLEX(x, plus_infty)), M_PI_2l);
5303 x = random_value (-1e4, 1e4);
5304 check ("carg(x - i inf) == -pi/2 for finite x",
5305 FUNC(carg) (BUILD_COMPLEX(x, minus_infty)), -M_PI_2l);
5307 x = random_greater (0);
5308 check ("carg (-inf + i y) == +pi for finite y > 0",
5309 FUNC(carg) (BUILD_COMPLEX(minus_infty, x)), M_PIl);
5311 x = -random_greater (0);
5312 check ("carg (-inf + i y) == -pi for finite y < 0",
5313 FUNC(carg) (BUILD_COMPLEX(minus_infty, x)), -M_PIl);
5315 check ("carg (+inf + i inf) == +pi/4",
5316 FUNC(carg) (BUILD_COMPLEX(plus_infty, plus_infty)), M_PI_4l);
5318 check ("carg (+inf -i inf) == -pi/4",
5319 FUNC(carg) (BUILD_COMPLEX(plus_infty, minus_infty)), -M_PI_4l);
5321 check ("carg (-inf +i inf) == +3*pi/4",
5322 FUNC(carg) (BUILD_COMPLEX(minus_infty, plus_infty)), 3 * M_PI_4l);
5324 check ("carg (-inf -i inf) == -3*pi/4",
5325 FUNC(carg) (BUILD_COMPLEX(minus_infty, minus_infty)), -3 * M_PI_4l);
5330 static void
5331 nearbyint_test (void)
5333 check ("nearbyint(+0) = 0", FUNC(nearbyint) (0.0), 0.0);
5334 check ("nearbyint(-0) = -0", FUNC(nearbyint) (minus_zero), minus_zero);
5335 check_isinfp ("nearbyint(+Inf) = +Inf", FUNC(nearbyint) (plus_infty));
5336 check_isinfn ("nearbyint(-Inf) = -Inf", FUNC(nearbyint) (minus_infty));
5340 static void
5341 rint_test (void)
5343 check ("rint(0) = 0", FUNC(rint) (0.0), 0.0);
5344 check ("rint(-0) = -0", FUNC(rint) (minus_zero), minus_zero);
5345 check_isinfp ("rint(+Inf) = +Inf", FUNC(rint) (plus_infty));
5346 check_isinfn ("rint(-Inf) = -Inf", FUNC(rint) (minus_infty));
5350 static void
5351 lrint_test (void)
5353 /* XXX this test is incomplete. We need to have a way to specifiy
5354 the rounding method and test the critical cases. So far, only
5355 unproblematic numbers are tested. */
5357 check_long ("lrint(0) = 0", FUNC(lrint) (0.0), 0);
5358 check_long ("lrint(-0) = 0", FUNC(lrint) (minus_zero), 0);
5359 check_long ("lrint(0.2) = 0", FUNC(lrint) (0.2), 0);
5360 check_long ("lrint(-0.2) = 0", FUNC(lrint) (-0.2), 0);
5362 check_long ("lrint(1.4) = 1", FUNC(lrint) (1.4), 1);
5363 check_long ("lrint(-1.4) = -1", FUNC(lrint) (-1.4), -1);
5365 check_long ("lrint(8388600.3) = 8388600", FUNC(lrint) (8388600.3), 8388600);
5366 check_long ("lrint(-8388600.3) = -8388600", FUNC(lrint) (-8388600.3),
5367 -8388600);
5371 static void
5372 llrint_test (void)
5374 /* XXX this test is incomplete. We need to have a way to specifiy
5375 the rounding method and test the critical cases. So far, only
5376 unproblematic numbers are tested. */
5378 check_longlong ("llrint(0) = 0", FUNC(llrint) (0.0), 0);
5379 check_longlong ("llrint(-0) = 0", FUNC(llrint) (minus_zero), 0);
5380 check_longlong ("llrint(0.2) = 0", FUNC(llrint) (0.2), 0);
5381 check_longlong ("llrint(-0.2) = 0", FUNC(llrint) (-0.2), 0);
5383 check_longlong ("llrint(1.4) = 1", FUNC(llrint) (1.4), 1);
5384 check_longlong ("llrint(-1.4) = -1", FUNC(llrint) (-1.4), -1);
5386 check_longlong ("llrint(8388600.3) = 8388600", FUNC(llrint) (8388600.3),
5387 8388600);
5388 check_longlong ("llrint(-8388600.3) = -8388600", FUNC(llrint) (-8388600.3),
5389 -8388600);
5391 /* Test boundary conditions. */
5392 /* 0x1FFFFF */
5393 check_longlong ("llrint(2097151.0) = 2097151", FUNC(llrint) (2097151.0),
5394 2097151LL);
5395 /* 0x800000 */
5396 check_longlong ("llrint(8388608.0) = 8388608", FUNC(llrint) (8388608.0),
5397 8388608LL);
5398 /* 0x1000000 */
5399 check_longlong ("llrint(16777216.0) = 16777216",
5400 FUNC(llrint) (16777216.0), 16777216LL);
5401 /* 0x20000000000 */
5402 check_longlong ("llrint(2199023255552.0) = 2199023255552",
5403 FUNC(llrint) (2199023255552.0), 2199023255552LL);
5404 /* 0x40000000000 */
5405 check_longlong ("llrint(4398046511104.0) = 4398046511104",
5406 FUNC(llrint) (4398046511104.0), 4398046511104LL);
5407 /* 0x10000000000000 */
5408 check_longlong ("llrint(4503599627370496.0) = 4503599627370496",
5409 FUNC(llrint) (4503599627370496.0), 4503599627370496LL);
5410 /* 0x10000080000000 */
5411 check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5412 FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5413 /* 0x20000000000000 */
5414 check_longlong ("llrint(9007199254740992.0) = 9007199254740992",
5415 FUNC(llrint) (9007199254740992.0), 9007199254740992LL);
5416 /* 0x80000000000000 */
5417 check_longlong ("llrint(36028797018963968.0) = 36028797018963968",
5418 FUNC(llrint) (36028797018963968.0), 36028797018963968LL);
5419 /* 0x100000000000000 */
5420 check_longlong ("llrint(72057594037927936.0) = 72057594037927936",
5421 FUNC(llrint) (72057594037927936.0), 72057594037927936LL);
5425 static void
5426 round_test (void)
5428 check ("round(0) = 0", FUNC(round) (0), 0);
5429 check ("round(-0) = -0", FUNC(round) (minus_zero), minus_zero);
5430 check ("round(0.2) = 0", FUNC(round) (0.2), 0.0);
5431 check ("round(-0.2) = -0", FUNC(round) (-0.2), minus_zero);
5432 check ("round(0.5) = 1", FUNC(round) (0.5), 1.0);
5433 check ("round(-0.5) = -1", FUNC(round) (-0.5), -1.0);
5434 check ("round(0.8) = 1", FUNC(round) (0.8), 1.0);
5435 check ("round(-0.8) = -1", FUNC(round) (-0.8), -1.0);
5436 check ("round(1.5) = 2", FUNC(round) (1.5), 2.0);
5437 check ("round(-1.5) = -2", FUNC(round) (-1.5), -2.0);
5438 check ("round(2097152.5) = 2097153", FUNC(round) (2097152.5), 2097153);
5439 check ("round(-2097152.5) = -2097153", FUNC(round) (-2097152.5), -2097153);
5443 static void
5444 lround_test (void)
5446 check_long ("lround(0) = 0", FUNC(lround) (0), 0);
5447 check_long ("lround(-0) = 0", FUNC(lround) (minus_zero), 0);
5448 check_long ("lround(0.2) = 0", FUNC(lround) (0.2), 0.0);
5449 check_long ("lround(-0.2) = 0", FUNC(lround) (-0.2), 0);
5450 check_long ("lround(0.5) = 1", FUNC(lround) (0.5), 1);
5451 check_long ("lround(-0.5) = -1", FUNC(lround) (-0.5), -1);
5452 check_long ("lround(0.8) = 1", FUNC(lround) (0.8), 1);
5453 check_long ("lround(-0.8) = -1", FUNC(lround) (-0.8), -1);
5454 check_long ("lround(1.5) = 2", FUNC(lround) (1.5), 2);
5455 check_long ("lround(-1.5) = -2", FUNC(lround) (-1.5), -2);
5456 check_long ("lround(22514.5) = 22515", FUNC(lround) (22514.5), 22515);
5457 check_long ("lround(-22514.5) = -22515", FUNC(lround) (-22514.5), -22515);
5458 #ifndef TEST_FLOAT
5459 check_long ("lround(2097152.5) = 2097153", FUNC(lround) (2097152.5),
5460 2097153);
5461 check_long ("lround(-2097152.5) = -2097153", FUNC(lround) (-2097152.5),
5462 -2097153);
5463 #endif
5467 static void
5468 llround_test (void)
5470 check_longlong ("llround(0) = 0", FUNC(llround) (0), 0);
5471 check_longlong ("llround(-0) = 0", FUNC(llround) (minus_zero), 0);
5472 check_longlong ("llround(0.2) = 0", FUNC(llround) (0.2), 0.0);
5473 check_longlong ("llround(-0.2) = 0", FUNC(llround) (-0.2), 0);
5474 check_longlong ("llround(0.5) = 1", FUNC(llround) (0.5), 1);
5475 check_longlong ("llround(-0.5) = -1", FUNC(llround) (-0.5), -1);
5476 check_longlong ("llround(0.8) = 1", FUNC(llround) (0.8), 1);
5477 check_longlong ("llround(-0.8) = -1", FUNC(llround) (-0.8), -1);
5478 check_longlong ("llround(1.5) = 2", FUNC(llround) (1.5), 2);
5479 check_longlong ("llround(-1.5) = -2", FUNC(llround) (-1.5), -2);
5480 check_longlong ("llround(22514.5) = 22515", FUNC(llround) (22514.5), 22515);
5481 check_longlong ("llround(-22514.5) = -22515", FUNC(llround) (-22514.5),
5482 -22515);
5483 #ifndef TEST_FLOAT
5484 check_longlong ("llround(2097152.5) = 2097153",
5485 FUNC(llround) (2097152.5), 2097153);
5486 check_longlong ("llround(-2097152.5) = -2097153",
5487 FUNC(llround) (-2097152.5), -2097153);
5488 check_longlong ("llround(34359738368.5) = 34359738369",
5489 FUNC(llround) (34359738368.5), 34359738369ll);
5490 check_longlong ("llround(-34359738368.5) = -34359738369",
5491 FUNC(llround) (-34359738368.5), -34359738369ll);
5492 #endif
5494 /* Test boundary conditions. */
5495 /* 0x1FFFFF */
5496 check_longlong ("llround(2097151.0) = 2097151", FUNC(llround) (2097151.0),
5497 2097151LL);
5498 /* 0x800000 */
5499 check_longlong ("llround(8388608.0) = 8388608", FUNC(llround) (8388608.0),
5500 8388608LL);
5501 /* 0x1000000 */
5502 check_longlong ("llround(16777216.0) = 16777216",
5503 FUNC(llround) (16777216.0), 16777216LL);
5504 /* 0x20000000000 */
5505 check_longlong ("llround(2199023255552.0) = 2199023255552",
5506 FUNC(llround) (2199023255552.0), 2199023255552LL);
5507 /* 0x40000000000 */
5508 check_longlong ("llround(4398046511104.0) = 4398046511104",
5509 FUNC(llround) (4398046511104.0), 4398046511104LL);
5510 /* 0x10000000000000 */
5511 check_longlong ("llround(4503599627370496.0) = 4503599627370496",
5512 FUNC(llround) (4503599627370496.0), 4503599627370496LL);
5513 /* 0x10000080000000 */
5514 check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5515 FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5516 /* 0x20000000000000 */
5517 check_longlong ("llround(9007199254740992.0) = 9007199254740992",
5518 FUNC(llround) (9007199254740992.0), 9007199254740992LL);
5519 /* 0x80000000000000 */
5520 check_longlong ("llround(36028797018963968.0) = 36028797018963968",
5521 FUNC(llround) (36028797018963968.0), 36028797018963968LL);
5522 /* 0x100000000000000 */
5523 check_longlong ("llround(72057594037927936.0) = 72057594037927936",
5524 FUNC(llround) (72057594037927936.0), 72057594037927936LL);
5528 static void
5529 fma_test (void)
5531 check ("fma(1.0, 2.0, 3.0) = 5.0", FUNC(fma) (1.0, 2.0, 3.0), 5.0);
5532 check_isnan ("fma(NaN, 2.0, 3.0) = NaN", FUNC(fma) (nan_value, 2.0, 3.0));
5533 check_isnan ("fma(1.0, NaN, 3.0) = NaN", FUNC(fma) (1.0, nan_value, 3.0));
5534 check_isnan_maybe_exc ("fma(1.0, 2.0, NaN) = NaN",
5535 FUNC(fma) (1.0, 2.0, nan_value), INVALID_EXCEPTION);
5536 check_isnan_maybe_exc ("fma(+Inf, 0.0, NaN) = NaN",
5537 FUNC(fma) (plus_infty, 0.0, nan_value),
5538 INVALID_EXCEPTION);
5539 check_isnan_maybe_exc ("fma(-Inf, 0.0, NaN) = NaN",
5540 FUNC(fma) (minus_infty, 0.0, nan_value),
5541 INVALID_EXCEPTION);
5542 check_isnan_maybe_exc ("fma(0.0, +Inf, NaN) = NaN",
5543 FUNC(fma) (0.0, plus_infty, nan_value),
5544 INVALID_EXCEPTION);
5545 check_isnan_maybe_exc ("fma(0.0, -Inf, NaN) = NaN",
5546 FUNC(fma) (0.0, minus_infty, nan_value),
5547 INVALID_EXCEPTION);
5548 check_isnan_exc ("fma(+Inf, 0.0, 1.0) = NaN",
5549 FUNC(fma) (plus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5550 check_isnan_exc ("fma(-Inf, 0.0, 1.0) = NaN",
5551 FUNC(fma) (minus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5552 check_isnan_exc ("fma(0.0, +Inf, 1.0) = NaN",
5553 FUNC(fma) (0.0, plus_infty, 1.0), INVALID_EXCEPTION);
5554 check_isnan_exc ("fma(0.0, -Inf, 1.0) = NaN",
5555 FUNC(fma) (0.0, minus_infty, 1.0), INVALID_EXCEPTION);
5557 check_isnan_exc ("fma(+Inf, +Inf, -Inf) = NaN",
5558 FUNC(fma) (plus_infty, plus_infty, minus_infty),
5559 INVALID_EXCEPTION);
5560 check_isnan_exc ("fma(-Inf, +Inf, +Inf) = NaN",
5561 FUNC(fma) (minus_infty, plus_infty, plus_infty),
5562 INVALID_EXCEPTION);
5563 check_isnan_exc ("fma(+Inf, -Inf, +Inf) = NaN",
5564 FUNC(fma) (plus_infty, minus_infty, plus_infty),
5565 INVALID_EXCEPTION);
5566 check_isnan_exc ("fma(-Inf, -Inf, -Inf) = NaN",
5567 FUNC(fma) (minus_infty, minus_infty, minus_infty),
5568 INVALID_EXCEPTION);
5573 Tests for the comparison macros
5575 typedef enum {is_less, is_equal, is_greater, is_unordered} comp_result;
5578 static void
5579 comparison2_test (MATHTYPE x, MATHTYPE y, comp_result comp)
5581 char buf[255];
5582 int result;
5583 int expected;
5585 expected = (comp == is_greater);
5586 sprintf (buf, "isgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5587 expected);
5588 result = (isgreater (x, y) == expected);
5589 check_bool (buf, result);
5591 expected = (comp == is_greater || comp == is_equal);
5592 sprintf (buf, "isgreaterequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5593 expected);
5594 result = (isgreaterequal (x, y) == expected);
5595 check_bool (buf, result);
5597 expected = (comp == is_less);
5598 sprintf (buf, "isless (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5599 expected);
5600 result = (isless (x, y) == expected);
5601 check_bool (buf, result);
5603 expected = (comp == is_less || comp == is_equal);
5604 sprintf (buf, "islessequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5605 expected);
5606 result = (islessequal (x, y) == expected);
5607 check_bool (buf, result);
5609 expected = (comp == is_greater || comp == is_less);
5610 sprintf (buf, "islessgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5611 expected);
5612 result = (islessgreater (x, y) == expected);
5613 check_bool (buf, result);
5615 expected = (comp == is_unordered);
5616 sprintf (buf, "isunordered (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5617 expected);
5618 result = (isunordered (x, y) == expected);
5619 check_bool (buf, result);
5624 static void
5625 comparison1_test (MATHTYPE x, MATHTYPE y, comp_result comp)
5627 comp_result comp_swap;
5628 switch (comp)
5630 case is_less:
5631 comp_swap = is_greater;
5632 break;
5633 case is_greater:
5634 comp_swap = is_less;
5635 break;
5636 default:
5637 comp_swap = comp;
5638 break;
5640 comparison2_test (x, y, comp);
5641 comparison2_test (y, x, comp_swap);
5645 static void
5646 comparisons_test (void)
5648 comparison1_test (1, 2, is_less);
5649 comparison1_test (-30, 30, is_less);
5650 comparison1_test (42, 42, is_equal);
5651 comparison1_test (1, plus_infty, is_less);
5652 comparison1_test (35, minus_infty, is_greater);
5653 comparison1_test (1, nan_value, is_unordered);
5654 comparison1_test (nan_value, nan_value, is_unordered);
5655 comparison1_test (plus_infty, nan_value, is_unordered);
5656 comparison1_test (minus_infty, nan_value, is_unordered);
5657 comparison1_test (plus_infty, minus_infty, is_greater);
5661 static void
5662 inverse_func_pair_test (const char *test_name,
5663 mathfunc f1, mathfunc inverse,
5664 MATHTYPE x, MATHTYPE epsilon)
5666 MATHTYPE a, b, difference;
5667 int result;
5669 a = f1 (x);
5670 (void) &a;
5671 b = inverse (a);
5672 (void) &b;
5674 output_new_test (test_name);
5675 result = check_equal (b, x, epsilon, &difference);
5676 output_result (test_name, result,
5677 b, x, difference, PRINT, PRINT);
5681 static void
5682 inverse_functions (void)
5684 inverse_func_pair_test ("asin(sin(x)) == x",
5685 FUNC(sin), FUNC(asin), 1.0,
5686 CHOOSE (2e-18L, 0, 3e-7L));
5687 inverse_func_pair_test ("sin(asin(x)) == x",
5688 FUNC(asin), FUNC(sin), 1.0, 0.0);
5690 inverse_func_pair_test ("acos(cos(x)) == x",
5691 FUNC(cos), FUNC(acos), 1.0,
5692 CHOOSE (4e-18L, 1e-15L, 0));
5693 inverse_func_pair_test ("cos(acos(x)) == x",
5694 FUNC(acos), FUNC(cos), 1.0, 0.0);
5695 inverse_func_pair_test ("atan(tan(x)) == x",
5696 FUNC(tan), FUNC(atan), 1.0, CHOOSE (2e-18L, 0, 0));
5697 inverse_func_pair_test ("tan(atan(x)) == x",
5698 FUNC(atan), FUNC(tan), 1.0,
5699 CHOOSE (2e-18L, 1e-15L, 2e-7));
5701 inverse_func_pair_test ("asinh(sinh(x)) == x",
5702 FUNC(sinh), FUNC(asinh), 1.0, CHOOSE (1e-18L, 0, 1e-7));
5703 inverse_func_pair_test ("sinh(asinh(x)) == x",
5704 FUNC(asinh), FUNC(sinh), 1.0,
5705 CHOOSE (2e-18L, 2e-16L, 2e-7));
5707 inverse_func_pair_test ("acosh(cosh(x)) == x",
5708 FUNC(cosh), FUNC(acosh), 1.0,
5709 CHOOSE (1e-18L, 1e-15L, 6e-8));
5710 inverse_func_pair_test ("cosh(acosh(x)) == x",
5711 FUNC(acosh), FUNC(cosh), 1.0, 0.0);
5713 inverse_func_pair_test ("atanh(tanh(x)) == x",
5714 FUNC(tanh), FUNC(atanh), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
5715 inverse_func_pair_test ("tanh(atanh(x)) == x",
5716 FUNC(atanh), FUNC(tanh), 1.0, 0.0);
5720 /* Test sin and cos with the identity: sin(x)^2 + cos(x)^2 = 1. */
5721 static void
5722 identities1_test (MATHTYPE x, MATHTYPE epsilon)
5724 MATHTYPE res1, res2, res3, diff;
5725 int result;
5727 res1 = FUNC(sin) (x);
5728 (void) &res1;
5729 res2 = FUNC(cos) (x);
5730 (void) &res2;
5731 res3 = res1 * res1 + res2 * res2;
5732 (void) &res3;
5734 output_new_test ("sin^2 + cos^2 == 1");
5735 result = check_equal (res3, 1.0, epsilon, &diff);
5736 output_result_ext ("sin^2 + cos^2 == 1", result,
5737 res3, 1.0, diff, x, PRINT, PRINT);
5741 /* Test sin, cos, tan with the following relation: tan = sin/cos. */
5742 static void
5743 identities2_test (MATHTYPE x, MATHTYPE epsilon)
5745 #ifndef TEST_INLINE
5746 MATHTYPE res1, res2, res3, res4, diff;
5747 int result;
5749 res1 = FUNC(sin) (x);
5750 (void) &res1;
5751 res2 = FUNC(cos) (x);
5752 (void) &res2;
5753 res3 = FUNC(tan) (x);
5754 (void) &res3;
5755 res4 = res1 / res2;
5756 (void) &res4;
5758 output_new_test ("sin/cos == tan");
5759 result = check_equal (res4, res3, epsilon, &diff);
5760 output_result_ext ("sin/cos == tan", result,
5761 res4, res3, diff, x, PRINT, PRINT);
5762 #endif
5766 /* Test cosh and sinh with the identity cosh^2 - sinh^2 = 1. */
5767 static void
5768 identities3_test (MATHTYPE x, MATHTYPE epsilon)
5770 MATHTYPE res1, res2, res3, diff;
5771 int result;
5773 res1 = FUNC(sinh) (x);
5774 (void) &res1;
5775 res2 = FUNC(cosh) (x);
5776 (void) &res2;
5777 res3 = res2 * res2 - res1 * res1;
5778 (void) &res3;
5780 output_new_test ("cosh^2 - sinh^2 == 1");
5781 result = check_equal (res3, 1.0, epsilon, &diff);
5782 output_result_ext ("cosh^2 - sinh^2 == 1", result,
5783 res3, 1.0, diff, x, PRINT, PRINT);
5787 static void
5788 identities (void)
5790 identities1_test (0.2L, CHOOSE (1e-18L, 0, 2e-7));
5791 identities1_test (0.9L, CHOOSE (1e-18L, 0, 2e-7));
5792 identities1_test (0, 0);
5793 identities1_test (-1, CHOOSE (1e-18L, 0, 1e-7));
5795 identities2_test (0.2L, CHOOSE (1e-19L, 1e-16, 0));
5796 identities2_test (0.9L, CHOOSE (3e-19L, 1e-15, 2e-7));
5797 identities2_test (0, 0);
5798 identities2_test (-1, CHOOSE (1e-18L, 1e-15, 2e-7));
5800 identities3_test (0.2L, CHOOSE (1e-18L, 0, 1e-7));
5801 identities3_test (0.9L, CHOOSE (1e-18L, 1e-15, 1e-6));
5802 identities3_test (0, CHOOSE (0, 0, 1e-6));
5803 identities3_test (-1, CHOOSE (1e-18L, 7e-16, 1e-6));
5808 Let's test that basic arithmetic is working
5809 tests: Infinity and NaN
5811 static void
5812 basic_tests (void)
5814 /* variables are declared volatile to forbid some compiler
5815 optimizations */
5816 volatile MATHTYPE Inf_var, NaN_var, zero_var, one_var;
5817 MATHTYPE x1, x2;
5819 zero_var = 0.0;
5820 one_var = 1.0;
5821 NaN_var = nan_value;
5822 Inf_var = one_var / zero_var;
5824 (void) &zero_var;
5825 (void) &one_var;
5826 (void) &NaN_var;
5827 (void) &Inf_var;
5829 /* Clear all exceptions. The previous computations raised exceptions. */
5830 feclearexcept (FE_ALL_EXCEPT);
5832 check_isinfp ("isinf (inf) == +1", Inf_var);
5833 check_isinfn ("isinf (-inf) == -1", -Inf_var);
5834 check_bool ("!isinf (1)", !(FUNC(isinf) (one_var)));
5835 check_bool ("!isinf (NaN)", !(FUNC(isinf) (NaN_var)));
5837 check_isnan ("isnan (NaN)", NaN_var);
5838 check_isnan ("isnan (-NaN)", -NaN_var);
5839 check_bool ("!isnan (1)", !(FUNC(isnan) (one_var)));
5840 check_bool ("!isnan (inf)", !(FUNC(isnan) (Inf_var)));
5842 check_bool ("inf == inf", Inf_var == Inf_var);
5843 check_bool ("-inf == -inf", -Inf_var == -Inf_var);
5844 check_bool ("inf != -inf", Inf_var != -Inf_var);
5845 check_bool ("NaN != NaN", NaN_var != NaN_var);
5848 the same tests but this time with NAN from <bits/nan.h>
5849 NAN is a double const
5851 check_bool ("isnan (NAN)", isnan (NAN));
5852 check_bool ("isnan (-NAN)", isnan (-NAN));
5853 check_bool ("!isinf (NAN)", !(isinf (NAN)));
5854 check_bool ("!isinf (-NAN)", !(isinf (-NAN)));
5855 check_bool ("NAN != NAN", NAN != NAN);
5858 And again with the value returned by the `nan' function.
5860 check_bool ("isnan (NAN)", FUNC(isnan) (FUNC(nan) ("")));
5861 check_bool ("isnan (-NAN)", FUNC(isnan) (-FUNC(nan) ("")));
5862 check_bool ("!isinf (NAN)", !(FUNC(isinf) (FUNC(nan) (""))));
5863 check_bool ("!isinf (-NAN)", !(FUNC(isinf) (-FUNC(nan) (""))));
5864 check_bool ("NAN != NAN", FUNC(nan) ("") != FUNC(nan) (""));
5866 /* test if EPSILON is ok */
5867 x1 = MATHCONST (1.0);
5868 x2 = x1 + CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
5869 check_bool ("1 != 1+EPSILON", x1 != x2);
5871 x1 = MATHCONST (1.0);
5872 x2 = x1 - CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
5873 check_bool ("1 != 1-EPSILON", x1 != x2);
5875 /* test if HUGE_VALx is ok */
5876 x1 = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5877 check_bool ("isinf (HUGE_VALx) == +1", ISINF (x1) == +1);
5878 x1 = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5879 check_bool ("isinf (-HUGE_VALx) == -1", ISINF (x1) == -1);
5884 static void
5885 initialize (void)
5887 fpstack_test ("start *init*");
5888 plus_zero = 0.0;
5889 nan_value = plus_zero / plus_zero; /* Suppress GCC warning */
5891 minus_zero = FUNC (copysign) (0.0, -1.0);
5892 plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5893 minus_infty = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5895 (void) &plus_zero;
5896 (void) &nan_value;
5897 (void) &minus_zero;
5898 (void) &plus_infty;
5899 (void) &minus_infty;
5901 /* Clear all exceptions. From now on we must not get random exceptions. */
5902 feclearexcept (FE_ALL_EXCEPT);
5904 /* Test to make sure we start correctly. */
5905 fpstack_test ("end *init*");
5909 static struct option long_options[] =
5911 {"verbose", optional_argument, NULL, 'v'},
5912 {"silent", no_argument, NULL, 's'},
5913 {0, 0, 0, 0}
5917 static void
5918 parse_options (int argc, char *argv[])
5920 int c;
5921 int option_index;
5923 verbose = 1;
5925 while (1)
5927 c = getopt_long (argc, argv, "v::s",
5928 long_options, &option_index);
5930 /* Detect the end of the options. */
5931 if (c == -1)
5932 break;
5934 switch (c)
5936 case 'v':
5937 if (optarg)
5938 verbose = (unsigned int) strtoul (optarg, NULL, 0);
5939 else
5940 verbose = 4;
5941 break;
5942 case 's':
5943 verbose = 0;
5944 default:
5945 break;
5952 main (int argc, char *argv[])
5955 parse_options (argc, argv);
5957 initialize ();
5958 printf (TEST_MSG);
5960 basic_tests ();
5962 /* keep the tests a wee bit ordered (according to ISO 9X) */
5963 /* classification functions */
5964 fpclassify_test ();
5965 isfinite_test ();
5966 isnormal_test ();
5967 signbit_test ();
5969 comparisons_test ();
5971 /* trigonometric functions */
5972 acos_test ();
5973 asin_test ();
5974 atan_test ();
5975 atan2_test ();
5976 cos_test ();
5977 sin_test ();
5978 sincos_test ();
5979 tan_test ();
5981 /* hyperbolic functions */
5982 acosh_test ();
5983 asinh_test ();
5984 atanh_test ();
5985 cosh_test ();
5986 sinh_test ();
5987 tanh_test ();
5989 /* exponential and logarithmic functions */
5990 exp_test ();
5991 exp10_test ();
5992 exp2_test ();
5993 expm1_test ();
5994 frexp_test ();
5995 ldexp_test ();
5996 log_test ();
5997 log10_test ();
5998 log1p_test ();
5999 log2_test ();
6000 logb_test ();
6001 modf_test ();
6002 ilogb_test ();
6003 scalb_test ();
6004 scalbn_test ();
6006 /* power and absolute value functions */
6007 cbrt_test ();
6008 fabs_test ();
6009 hypot_test ();
6010 pow_test ();
6011 sqrt_test ();
6013 /* error and gamma functions */
6014 erf_test ();
6015 erfc_test ();
6016 gamma_test ();
6017 tgamma_test ();
6018 lgamma_test ();
6020 /* nearest integer functions */
6021 ceil_test ();
6022 floor_test ();
6023 nearbyint_test ();
6024 rint_test ();
6025 lrint_test ();
6026 llrint_test ();
6027 round_test ();
6028 lround_test ();
6029 llround_test ();
6030 trunc_test ();
6032 /* remainder functions */
6033 fmod_test ();
6034 remainder_test ();
6035 remquo_test ();
6037 /* manipulation functions */
6038 copysign_test ();
6039 nextafter_test ();
6041 /* maximum, minimum and positive difference functions */
6042 fdim_test ();
6043 fmin_test ();
6044 fmax_test ();
6046 /* complex functions */
6047 cabs_test ();
6048 carg_test ();
6049 cexp_test ();
6050 csin_test ();
6051 csinh_test ();
6052 ccos_test ();
6053 ccosh_test ();
6054 clog_test ();
6055 clog10_test ();
6056 cacos_test ();
6057 cacosh_test ();
6058 casin_test ();
6059 casinh_test ();
6060 catan_test ();
6061 catanh_test ();
6062 ctan_test ();
6063 ctanh_test ();
6064 csqrt_test ();
6065 cpow_test ();
6067 /* multiply and add */
6068 fma_test ();
6070 /* special tests */
6071 identities ();
6072 inverse_functions ();
6074 printf ("\nTest suite completed:\n");
6075 printf (" %d test cases plus %d tests for exception flags executed.\n",
6076 noTests, noExcTests);
6077 if (noErrors)
6079 printf (" %d errors occured.\n", noErrors);
6080 exit (1);
6082 printf (" All tests passed successfully.\n");
6083 exit (0);