Update.
[glibc.git] / math / libm-test.c
bloba4e8492bf4d88728e704e6f6964db7fe35afa18c
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, 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 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, 0, 0));
1210 check_eps ("exp10 (-1) == 0.1", FUNC(exp10) (-1), 0.1,
1211 CHOOSE(6e-18, 0, 0));
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, 0));
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);
1417 gamma has different semantics depending on _LIB_VERSION:
1418 if _LIB_VERSION is _SVID, gamma is just an alias for lgamma,
1419 otherwise gamma is the real gamma function as definied in ISO C 9X.
1421 static void
1422 gamma_test (void)
1424 int save_lib_version = _LIB_VERSION;
1425 errno = 0;
1426 FUNC(gamma) (1);
1427 if (errno == ENOSYS)
1428 /* Function not implemented. */
1429 return;
1430 feclearexcept (FE_ALL_EXCEPT);
1433 _LIB_VERSION = _SVID_;
1435 check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
1436 check_isinfp_exc ("gamma (0) == +inf plus divide by zero exception",
1437 FUNC(gamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1439 check_isinfp_exc ("gamma (x) == +inf plus divide by zero exception for integer x <= 0",
1440 FUNC(gamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1441 check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
1442 FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
1444 signgam = 0;
1445 check ("gamma (1) == 0", FUNC(gamma) (1), 0);
1446 check_int ("gamma (0) sets signgam to 1", signgam, 1);
1448 signgam = 0;
1449 check ("gamma (3) == M_LN2", FUNC(gamma) (3), M_LN2l);
1450 check_int ("gamma (3) sets signgam to 1", signgam, 1);
1452 signgam = 0;
1453 check_eps ("gamma (0.5) == log(sqrt(pi))", FUNC(gamma) (0.5),
1454 FUNC(log) (FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 1e-7));
1455 check_int ("gamma (0.5) sets signgam to 1", signgam, 1);
1457 signgam = 0;
1458 check_eps ("gamma (-0.5) == log(2*sqrt(pi))", FUNC(gamma) (-0.5),
1459 FUNC(log) (2*FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 0));
1461 check_int ("gamma (-0.5) sets signgam to -1", signgam, -1);
1464 _LIB_VERSION = _IEEE_;
1466 check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
1467 check_isnan_exc ("gamma (0) == NaN plus invalid exception",
1468 FUNC(gamma) (0), INVALID_EXCEPTION);
1470 check_isnan_exc_ext ("gamma (x) == NaN plus invalid exception for integer x <= 0",
1471 FUNC(gamma) (-2), INVALID_EXCEPTION, -2);
1472 check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
1473 FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
1475 #ifdef TODO
1476 check_eps ("gamma (0.5) == sqrt(pi)", FUNC(gamma) (0.5), FUNC(sqrt) (M_PIl),
1477 CHOOSE (0, 5e-16, 2e-7));
1478 #endif
1479 check_eps ("gamma (-0.5) == -2*sqrt(pi)", FUNC(gamma) (-0.5),
1480 -2*FUNC(sqrt) (M_PIl), CHOOSE (0, 5e-16, 3e-7));
1482 check ("gamma (1) == 1", FUNC(gamma) (1), 1);
1483 check ("gamma (4) == 6", FUNC(gamma) (4), 6);
1485 check_eps ("gamma (0.7) == 1.29805...", FUNC(gamma) (0.7),
1486 1.29805533264755778568L, CHOOSE(0, 3e-16, 2e-7));
1487 check ("gamma (1.2) == 0.91816...", FUNC(gamma) (1.2), 0.91816874239976061064L);
1489 _LIB_VERSION = save_lib_version;
1493 static void
1494 lgamma_test (void)
1496 errno = 0;
1497 FUNC(lgamma) (0);
1498 if (errno == ENOSYS)
1499 /* Function not implemented. */
1500 return;
1501 feclearexcept (FE_ALL_EXCEPT);
1503 check_isinfp ("lgamma (+inf) == +inf", FUNC(lgamma) (plus_infty));
1504 check_isinfp_exc ("lgamma (0) == +inf plus divide by zero exception",
1505 FUNC(lgamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1507 check_isinfp_exc ("lgamma (x) == +inf plus divide by zero exception for integer x <= 0",
1508 FUNC(lgamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1509 check_isnan_exc ("lgamma (-inf) == NaN plus invalid exception",
1510 FUNC(lgamma) (minus_infty), INVALID_EXCEPTION);
1512 signgam = 0;
1513 check ("lgamma (1) == 0", FUNC(lgamma) (1), 0);
1514 check_int ("lgamma (0) sets signgam to 1", signgam, 1);
1516 signgam = 0;
1517 check ("lgamma (3) == M_LN2", FUNC(lgamma) (3), M_LN2l);
1518 check_int ("lgamma (3) sets signgam to 1", signgam, 1);
1520 signgam = 0;
1521 check_eps ("lgamma (0.5) == log(sqrt(pi))", FUNC(lgamma) (0.5),
1522 FUNC(log) (FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 1e-7));
1523 check_int ("lgamma (0.5) sets signgam to 1", signgam, 1);
1525 signgam = 0;
1526 check_eps ("lgamma (-0.5) == log(2*sqrt(pi))", FUNC(lgamma) (-0.5),
1527 FUNC(log) (2*FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 0));
1529 check_int ("lgamma (-0.5) sets signgam to -1", signgam, -1);
1531 signgam = 0;
1532 check_eps ("lgamma (0.7) == 0.26086...", FUNC(lgamma) (0.7),
1533 0.26086724653166651439L, CHOOSE(0, 6e-17, 3e-8));
1534 check_int ("lgamma (0.7) sets signgam to 1", signgam, 1);
1536 signgam = 0;
1537 check_eps ("lgamma (1.2) == -0.08537...", FUNC(lgamma) (1.2),
1538 -0.853740900033158497197e-1L, CHOOSE(0, 2e-17, 2e-8));
1539 check_int ("lgamma (1.2) sets signgam to 1", signgam, 1);
1544 static void
1545 ilogb_test (void)
1547 int i;
1549 check_int ("ilogb (1) == 0", FUNC(ilogb) (1), 0);
1550 check_int ("ilogb (e) == 1", FUNC(ilogb) (M_El), 1);
1551 check_int ("ilogb (1024) == 10", FUNC(ilogb) (1024), 10);
1552 check_int ("ilogb (-2000) == 10", FUNC(ilogb) (-2000), 10);
1554 /* XXX We have a problem here: the standard does not tell us whether
1555 exceptions are allowed/required. ignore them for now. */
1556 i = FUNC (ilogb) (0.0);
1557 feclearexcept (FE_ALL_EXCEPT);
1558 check_int ("ilogb (0) == FP_ILOGB0", i, FP_ILOGB0);
1559 i = FUNC(ilogb) (nan_value);
1560 feclearexcept (FE_ALL_EXCEPT);
1561 check_int ("ilogb (NaN) == FP_ILOGBNAN", i, FP_ILOGBNAN);
1566 static void
1567 ldexp_test (void)
1569 MATHTYPE x;
1571 check ("ldexp (0, 0) == 0", FUNC(ldexp) (0, 0), 0);
1573 check_isinfp ("ldexp (+inf, 1) == +inf", FUNC(ldexp) (plus_infty, 1));
1574 check_isinfn ("ldexp (-inf, 1) == -inf", FUNC(ldexp) (minus_infty, 1));
1575 check_isnan ("ldexp (NaN, 1) == NaN", FUNC(ldexp) (nan_value, 1));
1577 check ("ldexp (0.8, 4) == 12.8", FUNC(ldexp) (0.8L, 4), 12.8L);
1578 check ("ldexp (-0.854375, 5) == -27.34", FUNC(ldexp) (-0.854375L, 5), -27.34L);
1580 x = random_greater (0.0);
1581 check_ext ("ldexp (x, 0) == x", FUNC(ldexp) (x, 0L), x, x);
1586 static void
1587 log_test (void)
1589 check_isinfn_exc ("log (+0) == -inf plus divide-by-zero exception",
1590 FUNC(log) (0), DIVIDE_BY_ZERO_EXCEPTION);
1591 check_isinfn_exc ("log (-0) == -inf plus divide-by-zero exception",
1592 FUNC(log) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1594 check ("log (1) == 0", FUNC(log) (1), 0);
1596 check_isnan_exc ("log (x) == NaN plus invalid exception if x < 0",
1597 FUNC(log) (-1), INVALID_EXCEPTION);
1598 check_isinfp ("log (+inf) == +inf", FUNC(log) (plus_infty));
1600 check_eps ("log (e) == 1", FUNC(log) (M_El), 1, CHOOSE (1e-18L, 0, 9e-8L));
1601 check_eps ("log (1/e) == -1", FUNC(log) (1.0 / M_El), -1,
1602 CHOOSE (2e-18L, 0, 0));
1603 check ("log (2) == M_LN2", FUNC(log) (2), M_LN2l);
1604 check_eps ("log (10) == M_LN10", FUNC(log) (10), M_LN10l,
1605 CHOOSE (1e-18L, 0, 0));
1606 check_eps ("log (0.7) == -0.3566749439...", FUNC(log) (0.7),
1607 -0.35667494393873237891L, CHOOSE(7e-17L, 6e-17, 3e-8));
1611 static void
1612 log10_test (void)
1614 check_isinfn_exc ("log10 (+0) == -inf plus divide-by-zero exception",
1615 FUNC(log10) (0), DIVIDE_BY_ZERO_EXCEPTION);
1616 check_isinfn_exc ("log10 (-0) == -inf plus divide-by-zero exception",
1617 FUNC(log10) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1619 check ("log10 (1) == +0", FUNC(log10) (1), 0);
1621 check_isnan_exc ("log10 (x) == NaN plus invalid exception if x < 0",
1622 FUNC(log10) (-1), INVALID_EXCEPTION);
1624 check_isinfp ("log10 (+inf) == +inf", FUNC(log10) (plus_infty));
1626 check_eps ("log10 (0.1) == -1", FUNC(log10) (0.1L), -1,
1627 CHOOSE (1e-18L, 0, 0));
1628 check_eps ("log10 (10) == 1", FUNC(log10) (10.0), 1,
1629 CHOOSE (1e-18L, 0, 0));
1630 check_eps ("log10 (100) == 2", FUNC(log10) (100.0), 2,
1631 CHOOSE (1e-18L, 0, 0));
1632 check ("log10 (10000) == 4", FUNC(log10) (10000.0), 4);
1633 check_eps ("log10 (e) == M_LOG10E", FUNC(log10) (M_El), M_LOG10El,
1634 CHOOSE (1e-18, 0, 9e-8));
1635 check_eps ("log10 (0.7) == -0.1549019599...", FUNC(log10) (0.7),
1636 -0.15490195998574316929L, CHOOSE(3e-17L, 3e-17, 2e-8));
1640 static void
1641 log1p_test (void)
1643 check ("log1p (+0) == +0", FUNC(log1p) (0), 0);
1644 check ("log1p (-0) == -0", FUNC(log1p) (minus_zero), minus_zero);
1646 check_isinfn_exc ("log1p (-1) == -inf plus divide-by-zero exception",
1647 FUNC(log1p) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1648 check_isnan_exc ("log1p (x) == NaN plus invalid exception if x < -1",
1649 FUNC(log1p) (-2), INVALID_EXCEPTION);
1651 check_isinfp ("log1p (+inf) == +inf", FUNC(log1p) (plus_infty));
1653 check_eps ("log1p (e-1) == 1", FUNC(log1p) (M_El - 1.0), 1,
1654 CHOOSE (1e-18L, 0, 6e-8));
1656 check_eps ("log1p (-0.3) == -0.35667...", FUNC(log1p) (-0.3),
1657 -0.35667494393873237891L, CHOOSE(2e-17L, 6e-17, 3e-8));
1661 static void
1662 log2_test (void)
1664 check_isinfn_exc ("log2 (+0) == -inf plus divide-by-zero exception",
1665 FUNC(log2) (0), DIVIDE_BY_ZERO_EXCEPTION);
1666 check_isinfn_exc ("log2 (-0) == -inf plus divide-by-zero exception",
1667 FUNC(log2) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1669 check ("log2 (1) == +0", FUNC(log2) (1), 0);
1671 check_isnan_exc ("log2 (x) == NaN plus invalid exception if x < 0",
1672 FUNC(log2) (-1), INVALID_EXCEPTION);
1674 check_isinfp ("log2 (+inf) == +inf", FUNC(log2) (plus_infty));
1676 check_eps ("log2 (e) == M_LOG2E", FUNC(log2) (M_El), M_LOG2El,
1677 CHOOSE (1e-18L, 0, 0));
1678 check ("log2 (2) == 1", FUNC(log2) (2.0), 1);
1679 check_eps ("log2 (16) == 4", FUNC(log2) (16.0), 4, CHOOSE (1e-18L, 0, 0));
1680 check ("log2 (256) == 8", FUNC(log2) (256.0), 8);
1681 check_eps ("log2 (0.7) == -0.5145731728...", FUNC(log2) (0.7),
1682 -0.51457317282975824043L, CHOOSE(1e-16L, 2e-16, 6e-8));
1687 static void
1688 logb_test (void)
1690 check_isinfp ("logb (+inf) == +inf", FUNC(logb) (plus_infty));
1691 check_isinfp ("logb (-inf) == +inf", FUNC(logb) (minus_infty));
1693 check_isinfn_exc ("logb (+0) == -inf plus divide-by-zero exception",
1694 FUNC(logb) (0), DIVIDE_BY_ZERO_EXCEPTION);
1696 check_isinfn_exc ("logb (-0) == -inf plus divide-by-zero exception",
1697 FUNC(logb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1699 check ("logb (1) == 0", FUNC(logb) (1), 0);
1700 check ("logb (e) == 1", FUNC(logb) (M_El), 1);
1701 check ("logb (1024) == 10", FUNC(logb) (1024), 10);
1702 check ("logb (-2000) == 10", FUNC(logb) (-2000), 10);
1707 static void
1708 modf_test (void)
1710 MATHTYPE result, intpart;
1712 result = FUNC(modf) (plus_infty, &intpart);
1713 check ("modf (+inf, &x) returns +0", result, 0);
1714 check_isinfp ("modf (+inf, &x) set x to +inf", intpart);
1716 result = FUNC(modf) (minus_infty, &intpart);
1717 check ("modf (-inf, &x) returns -0", result, minus_zero);
1718 check_isinfn ("modf (-inf, &x) sets x to -inf", intpart);
1720 result = FUNC(modf) (nan_value, &intpart);
1721 check_isnan ("modf (NaN, &x) returns NaN", result);
1722 check_isnan ("modf (NaN, &x) sets x to NaN", intpart);
1724 result = FUNC(modf) (0, &intpart);
1725 check ("modf (0, &x) returns 0", result, 0);
1726 check ("modf (0, &x) sets x to 0", intpart, 0);
1728 result = FUNC(modf) (minus_zero, &intpart);
1729 check ("modf (-0, &x) returns -0", result, minus_zero);
1730 check ("modf (-0, &x) sets x to -0", intpart, minus_zero);
1732 result = FUNC(modf) (1.5, &intpart);
1733 check ("modf (1.5, &x) returns 0.5", result, 0.5);
1734 check ("modf (1.5, &x) sets x to 1", intpart, 1);
1736 result = FUNC(modf) (2.5, &intpart);
1737 check ("modf (2.5, &x) returns 0.5", result, 0.5);
1738 check ("modf (2.5, &x) sets x to 2", intpart, 2);
1740 result = FUNC(modf) (-2.5, &intpart);
1741 check ("modf (-2.5, &x) returns -0.5", result, -0.5);
1742 check ("modf (-2.5, &x) sets x to -2", intpart, -2);
1744 result = FUNC(modf) (20, &intpart);
1745 check ("modf (20, &x) returns 0", result, 0);
1746 check ("modf (20, &x) sets x to 20", intpart, 20);
1748 result = FUNC(modf) (21, &intpart);
1749 check ("modf (21, &x) returns 0", result, 0);
1750 check ("modf (21, &x) sets x to 21", intpart, 21);
1752 result = FUNC(modf) (89.6, &intpart);
1753 check_eps ("modf (89.6, &x) returns 0.6", result, 0.6,
1754 CHOOSE(6e-15L, 6e-15, 2e-6));
1755 check ("modf (89.6, &x) sets x to 89", intpart, 89);
1759 static void
1760 scalb_test (void)
1762 MATHTYPE x;
1764 check_isnan ("scalb (2, 0.5) == NaN", FUNC(scalb) (2, 0.5));
1765 check_isnan ("scalb (3, -2.5) == NaN", FUNC(scalb) (3, -2.5));
1767 check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1768 check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1770 x = random_greater (0.0);
1771 check ("scalb (x, 0) == 0", FUNC(scalb) (x, 0), x);
1772 x = random_greater (0.0);
1773 check ("scalb (-x, 0) == 0", FUNC(scalb) (-x, 0), -x);
1775 check_isnan_exc ("scalb (+0, +inf) == NaN plus invalid exception",
1776 FUNC(scalb) (0, plus_infty), INVALID_EXCEPTION);
1777 check_isnan_exc ("scalb (-0, +inf) == NaN plus invalid exception",
1778 FUNC(scalb) (minus_zero, plus_infty), INVALID_EXCEPTION);
1780 check ("scalb (+0, 2) == +0", FUNC(scalb) (0, 2), 0);
1781 check ("scalb (-0, 4) == -0", FUNC(scalb) (minus_zero, -4), minus_zero);
1782 check ("scalb (+0, 0) == +0", FUNC(scalb) (0, 0), 0);
1783 check ("scalb (-0, 0) == -0", FUNC(scalb) (minus_zero, 0), minus_zero);
1784 check ("scalb (+0, -1) == +0", FUNC(scalb) (0, -1), 0);
1785 check ("scalb (-0, -10) == -0", FUNC(scalb) (minus_zero, -10), minus_zero);
1786 check ("scalb (+0, -inf) == +0", FUNC(scalb) (0, minus_infty), 0);
1787 check ("scalb (-0, -inf) == -0", FUNC(scalb) (minus_zero, minus_infty),
1788 minus_zero);
1790 check_isinfp ("scalb (+inf, -1) == +inf", FUNC(scalb) (plus_infty, -1));
1791 check_isinfn ("scalb (-inf, -10) == -inf", FUNC(scalb) (minus_infty, -10));
1792 check_isinfp ("scalb (+inf, 0) == +inf", FUNC(scalb) (plus_infty, 0));
1793 check_isinfn ("scalb (-inf, 0) == -inf", FUNC(scalb) (minus_infty, 0));
1794 check_isinfp ("scalb (+inf, 2) == +inf", FUNC(scalb) (plus_infty, 2));
1795 check_isinfn ("scalb (-inf, 100) == -inf", FUNC(scalb) (minus_infty, 100));
1797 x = random_greater (0.0);
1798 check ("scalb (x, -inf) == 0", FUNC(scalb) (x, minus_infty), 0.0);
1799 check ("scalb (-x, -inf) == -0", FUNC(scalb) (-x, minus_infty), minus_zero);
1801 x = random_greater (0.0);
1802 check_isinfp ("scalb (x, +inf) == +inf", FUNC(scalb) (x, plus_infty));
1803 x = random_greater (0.0);
1804 check_isinfn ("scalb (-x, +inf) == -inf", FUNC(scalb) (-x, plus_infty));
1805 check_isinfp ("scalb (+inf, +inf) == +inf",
1806 FUNC(scalb) (plus_infty, plus_infty));
1807 check_isinfn ("scalb (-inf, +inf) == -inf",
1808 FUNC(scalb) (minus_infty, plus_infty));
1810 check_isnan ("scalb (+inf, -inf) == NaN",
1811 FUNC(scalb) (plus_infty, minus_infty));
1812 check_isnan ("scalb (-inf, -inf) == NaN",
1813 FUNC(scalb) (minus_infty, minus_infty));
1815 check_isnan ("scalb (NaN, 1) == NaN", FUNC(scalb) (nan_value, 1));
1816 check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1817 check_isnan ("scalb (NaN, 0) == NaN", FUNC(scalb) (nan_value, 0));
1818 check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1819 check_isnan ("scalb (NaN, +inf) == NaN",
1820 FUNC(scalb) (nan_value, plus_infty));
1821 check_isnan ("scalb (+inf, NaN) == NaN",
1822 FUNC(scalb) (plus_infty, nan_value));
1823 check_isnan ("scalb (NaN, NaN) == NaN", FUNC(scalb) (nan_value, nan_value));
1825 check ("scalb (0.8, 4) == 12.8", FUNC(scalb) (0.8L, 4), 12.8L);
1826 check ("scalb (-0.854375, 5) == -27.34", FUNC(scalb) (-0.854375L, 5), -27.34L);
1830 static void
1831 scalbn_test (void)
1833 MATHTYPE x;
1835 check ("scalbn (0, 0) == 0", FUNC(scalbn) (0, 0), 0);
1837 check_isinfp ("scalbn (+inf, 1) == +inf", FUNC(scalbn) (plus_infty, 1));
1838 check_isinfn ("scalbn (-inf, 1) == -inf", FUNC(scalbn) (minus_infty, 1));
1839 check_isnan ("scalbn (NaN, 1) == NaN", FUNC(scalbn) (nan_value, 1));
1841 check ("scalbn (0.8, 4) == 12.8", FUNC(scalbn) (0.8L, 4), 12.8L);
1842 check ("scalbn (-0.854375, 5) == -27.34", FUNC(scalbn) (-0.854375L, 5), -27.34L);
1844 x = random_greater (0.0);
1845 check_ext ("scalbn (x, 0) == x", FUNC(scalbn) (x, 0L), x, x);
1849 static void
1850 sin_test (void)
1852 check ("sin (+0) == +0", FUNC(sin) (0), 0);
1853 check ("sin (-0) == -0", FUNC(sin) (minus_zero), minus_zero);
1854 check_isnan_exc ("sin (+inf) == NaN plus invalid exception",
1855 FUNC(sin) (plus_infty),
1856 INVALID_EXCEPTION);
1857 check_isnan_exc ("sin (-inf) == NaN plus invalid exception",
1858 FUNC(sin) (minus_infty),
1859 INVALID_EXCEPTION);
1861 check_eps ("sin (pi/6) == 0.5", FUNC(sin) (M_PI_6l),
1862 0.5, CHOOSE (4e-18L, 0, 0));
1863 check_eps ("sin (-pi/6) == -0.5", FUNC(sin) (-M_PI_6l),
1864 -0.5, CHOOSE (4e-18L, 0, 0));
1865 check ("sin (pi/2) == 1", FUNC(sin) (M_PI_2l), 1);
1866 check ("sin (-pi/2) == -1", FUNC(sin) (-M_PI_2l), -1);
1867 check_eps ("sin (0.7) == 0.6442176872...", FUNC(sin) (0.7),
1868 0.64421768723769105367L, CHOOSE(4e-17L, 0, 0));
1872 static void
1873 sinh_test (void)
1875 check ("sinh (+0) == +0", FUNC(sinh) (0), 0);
1877 #ifndef TEST_INLINE
1878 check ("sinh (-0) == -0", FUNC(sinh) (minus_zero), minus_zero);
1880 check_isinfp ("sinh (+inf) == +inf", FUNC(sinh) (plus_infty));
1881 check_isinfn ("sinh (-inf) == -inf", FUNC(sinh) (minus_infty));
1882 #endif
1884 check_eps ("sinh (0.7) == 0.7585837018...", FUNC(sinh) (0.7),
1885 0.75858370183953350346L, CHOOSE(6e-17L, 2e-16, 6e-8));
1889 static void
1890 sincos_test (void)
1892 MATHTYPE sin_res, cos_res;
1893 fenv_t fenv;
1895 FUNC(sincos) (0, &sin_res, &cos_res);
1896 fegetenv (&fenv);
1897 check ("sincos (+0, &sin, &cos) puts +0 in sin", sin_res, 0);
1898 fesetenv (&fenv);
1899 check ("sincos (+0, &sin, &cos) puts 1 in cos", cos_res, 1);
1901 FUNC(sincos) (minus_zero, &sin_res, &cos_res);
1902 fegetenv (&fenv);
1903 check ("sincos (-0, &sin, &cos) puts -0 in sin", sin_res, minus_zero);
1904 fesetenv (&fenv);
1905 check ("sincos (-0, &sin, &cos) puts 1 in cos", cos_res, 1);
1907 FUNC(sincos) (plus_infty, &sin_res, &cos_res);
1908 fegetenv (&fenv);
1909 check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in sin plus invalid exception",
1910 sin_res, INVALID_EXCEPTION);
1911 fesetenv (&fenv);
1912 check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in cos plus invalid exception",
1913 cos_res, INVALID_EXCEPTION);
1915 FUNC(sincos) (minus_infty, &sin_res, &cos_res);
1916 fegetenv (&fenv);
1917 check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in sin plus invalid exception",
1918 sin_res, INVALID_EXCEPTION);
1919 fesetenv (&fenv);
1920 check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in cos plus invalid exception",
1921 cos_res, INVALID_EXCEPTION);
1923 FUNC(sincos) (M_PI_2l, &sin_res, &cos_res);
1924 fegetenv (&fenv);
1925 check ("sincos (pi/2, &sin, &cos) puts 1 in sin", sin_res, 1);
1926 fesetenv (&fenv);
1927 check_eps ("sincos (pi/2, &sin, &cos) puts 0 in cos", cos_res, 0,
1928 CHOOSE (1e-18L, 1e-16, 1e-7));
1930 FUNC(sincos) (M_PI_6l, &sin_res, &cos_res);
1931 check_eps ("sincos (pi/6, &sin, &cos) puts 0.5 in sin", sin_res, 0.5,
1932 CHOOSE (5e-18L, 0, 0));
1934 FUNC(sincos) (M_PI_6l*2.0, &sin_res, &cos_res);
1935 check_eps ("sincos (pi/3, &sin, &cos) puts 0.5 in cos", cos_res, 0.5,
1936 CHOOSE (5e-18L, 1e-15, 1e-7));
1938 FUNC(sincos) (0.7, &sin_res, &cos_res);
1939 check_eps ("sincos (0.7, &sin, &cos) puts 0.6442176872... in sin", sin_res,
1940 0.64421768723769105367L, CHOOSE(4e-17L, 0, 0));
1941 check_eps ("sincos (0.7, &sin, &cos) puts 0.7648421872... in cos", cos_res,
1942 0.76484218728448842626L, CHOOSE(3e-17L, 2e-16, 6e-8));
1946 static void
1947 tan_test (void)
1949 check ("tan (+0) == +0", FUNC(tan) (0), 0);
1950 check ("tan (-0) == -0", FUNC(tan) (minus_zero), minus_zero);
1951 check_isnan_exc ("tan (+inf) == NaN plus invalid exception",
1952 FUNC(tan) (plus_infty), INVALID_EXCEPTION);
1953 check_isnan_exc ("tan (-inf) == NaN plus invalid exception",
1954 FUNC(tan) (minus_infty), INVALID_EXCEPTION);
1956 check_eps ("tan (pi/4) == 1", FUNC(tan) (M_PI_4l), 1,
1957 CHOOSE (2e-18L, 1e-15L, 2e-7));
1958 check_eps ("tan (0.7) == 0.8422883804...", FUNC(tan) (0.7),
1959 0.84228838046307944813L, CHOOSE(8e-17L, 0, 0));
1963 static void
1964 tanh_test (void)
1966 check ("tanh (+0) == +0", FUNC(tanh) (0), 0);
1967 #ifndef TEST_INLINE
1968 check ("tanh (-0) == -0", FUNC(tanh) (minus_zero), minus_zero);
1970 check ("tanh (+inf) == +1", FUNC(tanh) (plus_infty), 1);
1971 check ("tanh (-inf) == -1", FUNC(tanh) (minus_infty), -1);
1972 #endif
1973 check_eps ("tanh (0.7) == 0.6043677771...", FUNC(tanh) (0.7),
1974 0.60436777711716349631L, CHOOSE(3e-17L, 2e-16, 6e-8));
1978 static void
1979 fabs_test (void)
1981 check ("fabs (+0) == +0", FUNC(fabs) (0), 0);
1982 check ("fabs (-0) == +0", FUNC(fabs) (minus_zero), 0);
1984 check_isinfp ("fabs (+inf) == +inf", FUNC(fabs) (plus_infty));
1985 check_isinfp ("fabs (-inf) == +inf", FUNC(fabs) (minus_infty));
1987 check ("fabs (+38) == 38", FUNC(fabs) (38.0), 38.0);
1988 check ("fabs (-e) == e", FUNC(fabs) (-M_El), M_El);
1992 static void
1993 floor_test (void)
1995 check ("floor (+0) == +0", FUNC(floor) (0.0), 0.0);
1996 check ("floor (-0) == -0", FUNC(floor) (minus_zero), minus_zero);
1997 check_isinfp ("floor (+inf) == +inf", FUNC(floor) (plus_infty));
1998 check_isinfn ("floor (-inf) == -inf", FUNC(floor) (minus_infty));
2000 check ("floor (pi) == 3", FUNC(floor) (M_PIl), 3.0);
2001 check ("floor (-pi) == -4", FUNC(floor) (-M_PIl), -4.0);
2005 static void
2006 hypot_test (void)
2008 MATHTYPE a;
2010 a = random_greater (0);
2011 check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot) (plus_infty, a), a);
2012 check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot) (minus_infty, a), a);
2014 #ifndef TEST_INLINE
2015 check_isinfp ("hypot (+inf, NaN) == +inf", FUNC(hypot) (plus_infty, nan_value));
2016 check_isinfp ("hypot (-inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
2017 #endif
2019 check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot) (nan_value, nan_value));
2021 a = FUNC(hypot) (12.4L, 0.7L);
2022 check ("hypot (x,y) == hypot (y,x)", FUNC(hypot) (0.7L, 12.4L), a);
2023 check ("hypot (x,y) == hypot (-x,y)", FUNC(hypot) (-12.4L, 0.7L), a);
2024 check ("hypot (x,y) == hypot (-y,x)", FUNC(hypot) (-0.7L, 12.4L), a);
2025 check ("hypot (x,y) == hypot (-x,-y)", FUNC(hypot) (-12.4L, -0.7L), a);
2026 check ("hypot (x,y) == hypot (-y,-x)", FUNC(hypot) (-0.7L, -12.4L), a);
2027 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-0.7L, 0), 0.7L);
2028 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (0.7L, 0), 0.7L);
2029 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-1.0L, 0), 1.0L);
2030 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (1.0L, 0), 1.0L);
2031 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-5.7e7L, 0), 5.7e7L);
2032 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (5.7e7L, 0), 5.7e7L);
2034 check_eps ("hypot (0.7,1.2) == 1.38924...", FUNC(hypot) (0.7, 1.2),
2035 1.3892443989449804508L, CHOOSE(7e-17L, 3e-16, 0));
2039 static void
2040 pow_test (void)
2042 MATHTYPE x;
2044 check ("pow (+0, +0) == 1", FUNC(pow) (0, 0), 1);
2045 check ("pow (+0, -0) == 1", FUNC(pow) (0, minus_zero), 1);
2046 check ("pow (-0, +0) == 1", FUNC(pow) (minus_zero, 0), 1);
2047 check ("pow (-0, -0) == 1", FUNC(pow) (minus_zero, minus_zero), 1);
2049 check ("pow (+10, +0) == 1", FUNC(pow) (10, 0), 1);
2050 check ("pow (+10, -0) == 1", FUNC(pow) (10, minus_zero), 1);
2051 check ("pow (-10, +0) == 1", FUNC(pow) (-10, 0), 1);
2052 check ("pow (-10, -0) == 1", FUNC(pow) (-10, minus_zero), 1);
2054 check ("pow (NaN, +0) == 1", FUNC(pow) (nan_value, 0), 1);
2055 check ("pow (NaN, -0) == 1", FUNC(pow) (nan_value, minus_zero), 1);
2057 #ifndef TEST_INLINE
2058 check_isinfp ("pow (+1.1, +inf) == +inf", FUNC(pow) (1.1, plus_infty));
2059 check_isinfp ("pow (+inf, +inf) == +inf", FUNC(pow) (plus_infty, plus_infty));
2060 check_isinfp ("pow (-1.1, +inf) == +inf", FUNC(pow) (-1.1, plus_infty));
2061 check_isinfp ("pow (-inf, +inf) == +inf", FUNC(pow) (minus_infty, plus_infty));
2063 check ("pow (0.9, +inf) == +0", FUNC(pow) (0.9L, plus_infty), 0);
2064 check ("pow (1e-7, +inf) == +0", FUNC(pow) (1e-7L, plus_infty), 0);
2065 check ("pow (-0.9, +inf) == +0", FUNC(pow) (-0.9L, plus_infty), 0);
2066 check ("pow (-1e-7, +inf) == +0", FUNC(pow) (-1e-7L, plus_infty), 0);
2068 check ("pow (+1.1, -inf) == 0", FUNC(pow) (1.1, minus_infty), 0);
2069 check ("pow (+inf, -inf) == 0", FUNC(pow) (plus_infty, minus_infty), 0);
2070 check ("pow (-1.1, -inf) == 0", FUNC(pow) (-1.1, minus_infty), 0);
2071 check ("pow (-inf, -inf) == 0", FUNC(pow) (minus_infty, minus_infty), 0);
2073 check_isinfp ("pow (0.9, -inf) == +inf", FUNC(pow) (0.9L, minus_infty));
2074 check_isinfp ("pow (1e-7, -inf) == +inf", FUNC(pow) (1e-7L, minus_infty));
2075 check_isinfp ("pow (-0.9, -inf) == +inf", FUNC(pow) (-0.9L, minus_infty));
2076 check_isinfp ("pow (-1e-7, -inf) == +inf", FUNC(pow) (-1e-7L, minus_infty));
2078 check_isinfp ("pow (+inf, 1e-7) == +inf", FUNC(pow) (plus_infty, 1e-7L));
2079 check_isinfp ("pow (+inf, 1) == +inf", FUNC(pow) (plus_infty, 1));
2080 check_isinfp ("pow (+inf, 1e7) == +inf", FUNC(pow) (plus_infty, 1e7L));
2082 check ("pow (+inf, -1e-7) == 0", FUNC(pow) (plus_infty, -1e-7L), 0);
2083 check ("pow (+inf, -1) == 0", FUNC(pow) (plus_infty, -1), 0);
2084 check ("pow (+inf, -1e7) == 0", FUNC(pow) (plus_infty, -1e7L), 0);
2086 check_isinfn ("pow (-inf, 1) == -inf", FUNC(pow) (minus_infty, 1));
2087 check_isinfn ("pow (-inf, 11) == -inf", FUNC(pow) (minus_infty, 11));
2088 check_isinfn ("pow (-inf, 1001) == -inf", FUNC(pow) (minus_infty, 1001));
2090 check_isinfp ("pow (-inf, 2) == +inf", FUNC(pow) (minus_infty, 2));
2091 check_isinfp ("pow (-inf, 12) == +inf", FUNC(pow) (minus_infty, 12));
2092 check_isinfp ("pow (-inf, 1002) == +inf", FUNC(pow) (minus_infty, 1002));
2093 check_isinfp ("pow (-inf, 0.1) == +inf", FUNC(pow) (minus_infty, 0.1));
2094 check_isinfp ("pow (-inf, 1.1) == +inf", FUNC(pow) (minus_infty, 1.1));
2095 check_isinfp ("pow (-inf, 11.1) == +inf", FUNC(pow) (minus_infty, 11.1));
2096 check_isinfp ("pow (-inf, 1001.1) == +inf", FUNC(pow) (minus_infty, 1001.1));
2098 check ("pow (-inf, -1) == -0", FUNC(pow) (minus_infty, -1), minus_zero);
2099 check ("pow (-inf, -11) == -0", FUNC(pow) (minus_infty, -11), minus_zero);
2100 check ("pow (-inf, -1001) == -0", FUNC(pow) (minus_infty, -1001), minus_zero);
2102 check ("pow (-inf, -2) == +0", FUNC(pow) (minus_infty, -2), 0);
2103 check ("pow (-inf, -12) == +0", FUNC(pow) (minus_infty, -12), 0);
2104 check ("pow (-inf, -1002) == +0", FUNC(pow) (minus_infty, -1002), 0);
2105 check ("pow (-inf, -0.1) == +0", FUNC(pow) (minus_infty, -0.1), 0);
2106 check ("pow (-inf, -1.1) == +0", FUNC(pow) (minus_infty, -1.1), 0);
2107 check ("pow (-inf, -11.1) == +0", FUNC(pow) (minus_infty, -11.1), 0);
2108 check ("pow (-inf, -1001.1) == +0", FUNC(pow) (minus_infty, -1001.1), 0);
2110 check_isnan ("pow (NaN, NaN) == NaN", FUNC(pow) (nan_value, nan_value));
2111 check_isnan ("pow (0, NaN) == NaN", FUNC(pow) (0, nan_value));
2112 check_isnan ("pow (1, NaN) == NaN", FUNC(pow) (1, nan_value));
2113 check_isnan ("pow (-1, NaN) == NaN", FUNC(pow) (-1, nan_value));
2114 check_isnan ("pow (NaN, 1) == NaN", FUNC(pow) (nan_value, 1));
2115 check_isnan ("pow (NaN, -1) == NaN", FUNC(pow) (nan_value, -1));
2117 x = random_greater (0.0);
2118 check_isnan_ext ("pow (x, NaN) == NaN", FUNC(pow) (x, nan_value), x);
2120 check_isnan_exc ("pow (+1, +inf) == NaN plus invalid exception",
2121 FUNC(pow) (1, plus_infty), INVALID_EXCEPTION);
2122 check_isnan_exc ("pow (-1, +inf) == NaN plus invalid exception",
2123 FUNC(pow) (-1, plus_infty), INVALID_EXCEPTION);
2124 check_isnan_exc ("pow (+1, -inf) == NaN plus invalid exception",
2125 FUNC(pow) (1, minus_infty), INVALID_EXCEPTION);
2126 check_isnan_exc ("pow (-1, -inf) == NaN plus invalid exception",
2127 FUNC(pow) (-1, minus_infty), INVALID_EXCEPTION);
2129 check_isnan_exc ("pow (-0.1, 1.1) == NaN plus invalid exception",
2130 FUNC(pow) (-0.1, 1.1), INVALID_EXCEPTION);
2131 check_isnan_exc ("pow (-0.1, -1.1) == NaN plus invalid exception",
2132 FUNC(pow) (-0.1, -1.1), INVALID_EXCEPTION);
2133 check_isnan_exc ("pow (-10.1, 1.1) == NaN plus invalid exception",
2134 FUNC(pow) (-10.1, 1.1), INVALID_EXCEPTION);
2135 check_isnan_exc ("pow (-10.1, -1.1) == NaN plus invalid exception",
2136 FUNC(pow) (-10.1, -1.1), INVALID_EXCEPTION);
2138 check_isinfp_exc ("pow (+0, -1) == +inf plus divide-by-zero exception",
2139 FUNC(pow) (0, -1), DIVIDE_BY_ZERO_EXCEPTION);
2140 check_isinfp_exc ("pow (+0, -11) == +inf plus divide-by-zero exception",
2141 FUNC(pow) (0, -11), DIVIDE_BY_ZERO_EXCEPTION);
2142 check_isinfn_exc ("pow (-0, -1) == -inf plus divide-by-zero exception",
2143 FUNC(pow) (minus_zero, -1), DIVIDE_BY_ZERO_EXCEPTION);
2144 check_isinfn_exc ("pow (-0, -11) == -inf plus divide-by-zero exception",
2145 FUNC(pow) (minus_zero, -11), DIVIDE_BY_ZERO_EXCEPTION);
2147 check_isinfp_exc ("pow (+0, -2) == +inf plus divide-by-zero exception",
2148 FUNC(pow) (0, -2), DIVIDE_BY_ZERO_EXCEPTION);
2149 check_isinfp_exc ("pow (+0, -11.1) == +inf plus divide-by-zero exception",
2150 FUNC(pow) (0, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2151 check_isinfp_exc ("pow (-0, -2) == +inf plus divide-by-zero exception",
2152 FUNC(pow) (minus_zero, -2), DIVIDE_BY_ZERO_EXCEPTION);
2153 check_isinfp_exc ("pow (-0, -11.1) == +inf plus divide-by-zero exception",
2154 FUNC(pow) (minus_zero, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2155 #endif
2157 check ("pow (+0, 1) == +0", FUNC(pow) (0, 1), 0);
2158 check ("pow (+0, 11) == +0", FUNC(pow) (0, 11), 0);
2159 #ifndef TEST_INLINE
2160 check ("pow (-0, 1) == -0", FUNC(pow) (minus_zero, 1), minus_zero);
2161 check ("pow (-0, 11) == -0", FUNC(pow) (minus_zero, 11), minus_zero);
2162 #endif
2164 check ("pow (+0, 2) == +0", FUNC(pow) (0, 2), 0);
2165 check ("pow (+0, 11.1) == +0", FUNC(pow) (0, 11.1), 0);
2167 #ifndef TEST_INLINE
2168 check ("pow (-0, 2) == +0", FUNC(pow) (minus_zero, 2), 0);
2169 check ("pow (-0, 11.1) == +0", FUNC(pow) (minus_zero, 11.1), 0);
2171 x = random_greater (1.0);
2172 check_isinfp_ext ("pow (x, +inf) == +inf for |x| > 1",
2173 FUNC(pow) (x, plus_infty), x);
2175 x = random_value (-1.0, 1.0);
2176 check_ext ("pow (x, +inf) == +0 for |x| < 1",
2177 FUNC(pow) (x, plus_infty), 0.0, x);
2179 x = random_greater (1.0);
2180 check_ext ("pow (x, -inf) == +0 for |x| > 1",
2181 FUNC(pow) (x, minus_infty), 0.0, x);
2183 x = random_value (-1.0, 1.0);
2184 check_isinfp_ext ("pow (x, -inf) == +inf for |x| < 1",
2185 FUNC(pow) (x, minus_infty), x);
2187 x = random_greater (0.0);
2188 check_isinfp_ext ("pow (+inf, y) == +inf for y > 0",
2189 FUNC(pow) (plus_infty, x), x);
2191 x = random_less (0.0);
2192 check_ext ("pow (+inf, y) == +0 for y < 0",
2193 FUNC(pow) (plus_infty, x), 0.0, x);
2195 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2196 check_isinfn_ext ("pow (-inf, y) == -inf for y an odd integer > 0",
2197 FUNC(pow) (minus_infty, x), x);
2199 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2200 check_isinfp_ext ("pow (-inf, y) == +inf for y > 0 and not an odd integer",
2201 FUNC(pow) (minus_infty, x), x);
2203 x = -((rand () % 1000000) * 2.0 + 1); /* Get random odd integer < 0 */
2204 check_ext ("pow (-inf, y) == -0 for y an odd integer < 0",
2205 FUNC(pow) (minus_infty, x), minus_zero, x);
2207 x = ((rand () % 1000000) + 1) * -2.0; /* Get random even integer < 0 */
2208 check_ext ("pow (-inf, y) == +0 for y < 0 and not an odd integer",
2209 FUNC(pow) (minus_infty, x), 0.0, x);
2210 #endif
2212 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2213 check_ext ("pow (+0, y) == +0 for y an odd integer > 0",
2214 FUNC(pow) (0.0, x), 0.0, x);
2215 #ifndef TEST_INLINE
2216 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2217 check_ext ("pow (-0, y) == -0 for y an odd integer > 0",
2218 FUNC(pow) (minus_zero, x), minus_zero, x);
2219 #endif
2221 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2222 check_ext ("pow (+0, y) == +0 for y > 0 and not an odd integer",
2223 FUNC(pow) (0.0, x), 0.0, x);
2225 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2226 check_ext ("pow (-0, y) == +0 for y > 0 and not an odd integer",
2227 FUNC(pow) (minus_zero, x), 0.0, x);
2229 check_eps ("pow (0.7, 1.2) == 0.65180...", FUNC(pow) (0.7, 1.2),
2230 0.65180494056638638188L, CHOOSE(4e-17L, 0, 0));
2232 #ifdef TEST_DOUBLE
2233 check ("pow (-7.49321e+133, -9.80818e+16) == 0",
2234 FUNC(pow) (-7.49321e+133, -9.80818e+16), 0);
2235 #endif
2239 static void
2240 fdim_test (void)
2242 check ("fdim (+0, +0) = +0", FUNC(fdim) (0, 0), 0);
2243 check ("fdim (9, 0) = 9", FUNC(fdim) (9, 0), 9);
2244 check ("fdim (0, 9) = 0", FUNC(fdim) (0, 9), 0);
2245 check ("fdim (-9, 0) = 9", FUNC(fdim) (-9, 0), 0);
2246 check ("fdim (0, -9) = 9", FUNC(fdim) (0, -9), 9);
2248 check_isinfp ("fdim (+inf, 9) = +inf", FUNC(fdim) (plus_infty, 9));
2249 check_isinfp ("fdim (+inf, -9) = +inf", FUNC(fdim) (plus_infty, -9));
2250 check ("fdim (-inf, 9) = 0", FUNC(fdim) (minus_infty, 9), 0);
2251 check ("fdim (-inf, -9) = 0", FUNC(fdim) (minus_infty, -9), 0);
2252 check_isinfp ("fdim (+9, -inf) = +inf", FUNC(fdim) (9, minus_infty));
2253 check_isinfp ("fdim (-9, -inf) = +inf", FUNC(fdim) (-9, minus_infty));
2254 check ("fdim (9, inf) = 0", FUNC(fdim) (9, plus_infty), 0);
2255 check ("fdim (-9, inf) = 0", FUNC(fdim) (-9, plus_infty), 0);
2257 check_isnan ("fdim (0, NaN) = NaN", FUNC(fdim) (0, nan_value));
2258 check_isnan ("fdim (9, NaN) = NaN", FUNC(fdim) (9, nan_value));
2259 check_isnan ("fdim (-9, NaN) = NaN", FUNC(fdim) (-9, nan_value));
2260 check_isnan ("fdim (NaN, 9) = NaN", FUNC(fdim) (nan_value, 9));
2261 check_isnan ("fdim (NaN, -9) = NaN", FUNC(fdim) (nan_value, -9));
2262 check_isnan ("fdim (+inf, NaN) = NaN", FUNC(fdim) (plus_infty, nan_value));
2263 check_isnan ("fdim (-inf, NaN) = NaN", FUNC(fdim) (minus_infty, nan_value));
2264 check_isnan ("fdim (NaN, +inf) = NaN", FUNC(fdim) (nan_value, plus_infty));
2265 check_isnan ("fdim (NaN, -inf) = NaN", FUNC(fdim) (nan_value, minus_infty));
2266 check_isnan ("fdim (NaN, NaN) = NaN", FUNC(fdim) (nan_value, nan_value));
2270 static void
2271 fmin_test (void)
2273 check ("fmin (+0, +0) = +0", FUNC(fmin) (0, 0), 0);
2274 check ("fmin (9, 0) = 0", FUNC(fmin) (9, 0), 0);
2275 check ("fmin (0, 9) = 0", FUNC(fmin) (0, 9), 0);
2276 check ("fmin (-9, 0) = -9", FUNC(fmin) (-9, 0), -9);
2277 check ("fmin (0, -9) = -9", FUNC(fmin) (0, -9), -9);
2279 check ("fmin (+inf, 9) = 9", FUNC(fmin) (plus_infty, 9), 9);
2280 check ("fmin (9, +inf) = 9", FUNC(fmin) (9, plus_infty), 9);
2281 check ("fmin (+inf, -9) = -9", FUNC(fmin) (plus_infty, -9), -9);
2282 check ("fmin (-9, +inf) = -9", FUNC(fmin) (-9, plus_infty), -9);
2283 check_isinfn ("fmin (-inf, 9) = -inf", FUNC(fmin) (minus_infty, 9));
2284 check_isinfn ("fmin (-inf, -9) = -inf", FUNC(fmin) (minus_infty, -9));
2285 check_isinfn ("fmin (+9, -inf) = -inf", FUNC(fmin) (9, minus_infty));
2286 check_isinfn ("fmin (-9, -inf) = -inf", FUNC(fmin) (-9, minus_infty));
2288 check ("fmin (0, NaN) = 0", FUNC(fmin) (0, nan_value), 0);
2289 check ("fmin (9, NaN) = 9", FUNC(fmin) (9, nan_value), 9);
2290 check ("fmin (-9, NaN) = 9", FUNC(fmin) (-9, nan_value), -9);
2291 check ("fmin (NaN, 0) = 0", FUNC(fmin) (nan_value, 0), 0);
2292 check ("fmin (NaN, 9) = NaN", FUNC(fmin) (nan_value, 9), 9);
2293 check ("fmin (NaN, -9) = NaN", FUNC(fmin) (nan_value, -9), -9);
2294 check_isinfp ("fmin (+inf, NaN) = +inf", FUNC(fmin) (plus_infty, nan_value));
2295 check_isinfn ("fmin (-inf, NaN) = -inf", FUNC(fmin) (minus_infty, nan_value));
2296 check_isinfp ("fmin (NaN, +inf) = +inf", FUNC(fmin) (nan_value, plus_infty));
2297 check_isinfn ("fmin (NaN, -inf) = -inf", FUNC(fmin) (nan_value, minus_infty));
2298 check_isnan ("fmin (NaN, NaN) = NaN", FUNC(fmin) (nan_value, nan_value));
2302 static void
2303 fmax_test (void)
2305 check ("fmax (+0, +0) = +0", FUNC(fmax) (0, 0), 0);
2306 check ("fmax (9, 0) = 9", FUNC(fmax) (9, 0), 9);
2307 check ("fmax (0, 9) = 9", FUNC(fmax) (0, 9), 9);
2308 check ("fmax (-9, 0) = 0", FUNC(fmax) (-9, 0), 0);
2309 check ("fmax (0, -9) = 0", FUNC(fmax) (0, -9), 0);
2311 check_isinfp ("fmax (+inf, 9) = +inf", FUNC(fmax) (plus_infty, 9));
2312 check_isinfp ("fmax (9, +inf) = +inf", FUNC(fmax) (0, plus_infty));
2313 check_isinfp ("fmax (-9, +inf) = +inf", FUNC(fmax) (-9, plus_infty));
2314 check_isinfp ("fmax (+inf, -9) = +inf", FUNC(fmax) (plus_infty, -9));
2315 check ("fmax (-inf, 9) = 9", FUNC(fmax) (minus_infty, 9), 9);
2316 check ("fmax (-inf, -9) = -9", FUNC(fmax) (minus_infty, -9), -9);
2317 check ("fmax (+9, -inf) = 9", FUNC(fmax) (9, minus_infty), 9);
2318 check ("fmax (-9, -inf) = -9", FUNC(fmax) (-9, minus_infty), -9);
2320 check ("fmax (0, NaN) = 0", FUNC(fmax) (0, nan_value), 0);
2321 check ("fmax (9, NaN) = 9", FUNC(fmax) (9, nan_value), 9);
2322 check ("fmax (-9, NaN) = 9", FUNC(fmax) (-9, nan_value), -9);
2323 check ("fmax (NaN, 0) = 0", FUNC(fmax) (nan_value, 0), 0);
2324 check ("fmax (NaN, 9) = NaN", FUNC(fmax) (nan_value, 9), 9);
2325 check ("fmax (NaN, -9) = NaN", FUNC(fmax) (nan_value, -9), -9);
2326 check_isinfp ("fmax (+inf, NaN) = +inf", FUNC(fmax) (plus_infty, nan_value));
2327 check_isinfn ("fmax (-inf, NaN) = -inf", FUNC(fmax) (minus_infty, nan_value));
2328 check_isinfp ("fmax (NaN, +inf) = +inf", FUNC(fmax) (nan_value, plus_infty));
2329 check_isinfn ("fmax (NaN, -inf) = -inf", FUNC(fmax) (nan_value, minus_infty));
2330 check_isnan ("fmax (NaN, NaN) = NaN", FUNC(fmax) (nan_value, nan_value));
2334 static void
2335 fmod_test (void)
2337 MATHTYPE x;
2339 x = random_greater (0);
2340 check_ext ("fmod (+0, y) == +0 for y != 0", FUNC(fmod) (0, x), 0, x);
2342 x = random_greater (0);
2343 check_ext ("fmod (-0, y) == -0 for y != 0", FUNC(fmod) (minus_zero, x),
2344 minus_zero, x);
2346 check_isnan_exc_ext ("fmod (+inf, y) == NaN plus invalid exception",
2347 FUNC(fmod) (plus_infty, x), INVALID_EXCEPTION, x);
2348 check_isnan_exc_ext ("fmod (-inf, y) == NaN plus invalid exception",
2349 FUNC(fmod) (minus_infty, x), INVALID_EXCEPTION, x);
2350 check_isnan_exc_ext ("fmod (x, +0) == NaN plus invalid exception",
2351 FUNC(fmod) (x, 0), INVALID_EXCEPTION, x);
2352 check_isnan_exc_ext ("fmod (x, -0) == NaN plus invalid exception",
2353 FUNC(fmod) (x, minus_zero), INVALID_EXCEPTION, x);
2355 x = random_greater (0);
2356 check_ext ("fmod (x, +inf) == x for x not infinite",
2357 FUNC(fmod) (x, plus_infty), x, x);
2358 x = random_greater (0);
2359 check_ext ("fmod (x, -inf) == x for x not infinite",
2360 FUNC(fmod) (x, minus_infty), x, x);
2362 check_eps ("fmod (6.5, 2.3) == 1.9", FUNC(fmod) (6.5, 2.3), 1.9,
2363 CHOOSE(5e-16, 1e-15, 2e-7));
2364 check_eps ("fmod (-6.5, 2.3) == -1.9", FUNC(fmod) (-6.5, 2.3), -1.9,
2365 CHOOSE(5e-16, 1e-15, 2e-7));
2366 check_eps ("fmod (6.5, -2.3) == 1.9", FUNC(fmod) (6.5, -2.3), 1.9,
2367 CHOOSE(5e-16, 1e-15, 2e-7));
2368 check_eps ("fmod (-6.5, -2.3) == -1.9", FUNC(fmod) (-6.5, -2.3), -1.9,
2369 CHOOSE(5e-16, 1e-15, 2e-7));
2375 static void
2376 nextafter_test (void)
2378 MATHTYPE x;
2380 check ("nextafter (+0, +0) = +0", FUNC(nextafter) (0, 0), 0);
2381 check ("nextafter (-0, +0) = +0", FUNC(nextafter) (minus_zero, 0), 0);
2382 check ("nextafter (+0, -0) = -0", FUNC(nextafter) (0, minus_zero),
2383 minus_zero);
2384 check ("nextafter (-0, -0) = -0", FUNC(nextafter) (minus_zero, minus_zero),
2385 minus_zero);
2387 check ("nextafter (9, 9) = 9", FUNC(nextafter) (9, 9), 9);
2388 check ("nextafter (-9, -9) = -9", FUNC(nextafter) (-9, -9), -9);
2389 check_isinfp ("nextafter (+inf, +inf) = +inf",
2390 FUNC(nextafter) (plus_infty, plus_infty));
2391 check_isinfn ("nextafter (-inf, -inf) = -inf",
2392 FUNC(nextafter) (minus_infty, minus_infty));
2394 x = rand () * 1.1;
2395 check_isnan ("nextafter (NaN, x) = NaN", FUNC(nextafter) (nan_value, x));
2396 check_isnan ("nextafter (x, NaN) = NaN", FUNC(nextafter) (x, nan_value));
2397 check_isnan ("nextafter (NaN, NaN) = NaN", FUNC(nextafter) (nan_value,
2398 nan_value));
2400 /* XXX We need the hexadecimal FP number representation here for further
2401 tests. */
2405 static void
2406 copysign_test (void)
2408 check ("copysign (0, 4) = 0", FUNC(copysign) (0, 4), 0);
2409 check ("copysign (0, -4) = -0", FUNC(copysign) (0, -4), minus_zero);
2410 check ("copysign (-0, 4) = 0", FUNC(copysign) (minus_zero, 4), 0);
2411 check ("copysign (-0, -4) = -0", FUNC(copysign) (minus_zero, -4),
2412 minus_zero);
2414 check_isinfp ("copysign (+inf, 0) = +inf", FUNC(copysign) (plus_infty, 0));
2415 check_isinfn ("copysign (+inf, -0) = -inf", FUNC(copysign) (plus_infty,
2416 minus_zero));
2417 check_isinfp ("copysign (-inf, 0) = +inf", FUNC(copysign) (minus_infty, 0));
2418 check_isinfn ("copysign (-inf, -0) = -inf", FUNC(copysign) (minus_infty,
2419 minus_zero));
2421 check ("copysign (0, +inf) = 0", FUNC(copysign) (0, plus_infty), 0);
2422 check ("copysign (0, -inf) = -0", FUNC(copysign) (0, minus_zero),
2423 minus_zero);
2424 check ("copysign (-0, +inf) = 0", FUNC(copysign) (minus_zero, plus_infty),
2426 check ("copysign (-0, -inf) = -0", FUNC(copysign) (minus_zero, minus_zero),
2427 minus_zero);
2429 /* XXX More correctly we would have to check the sign of the NaN. */
2430 check_isnan ("copysign (+NaN, 0) = +NaN", FUNC(copysign) (nan_value, 0));
2431 check_isnan ("copysign (+NaN, -0) = -NaN", FUNC(copysign) (nan_value,
2432 minus_zero));
2433 check_isnan ("copysign (-NaN, 0) = +NaN", FUNC(copysign) (-nan_value, 0));
2434 check_isnan ("copysign (-NaN, -0) = -NaN", FUNC(copysign) (-nan_value,
2435 minus_zero));
2439 static void
2440 trunc_test (void)
2442 check ("trunc(0) = 0", FUNC(trunc) (0), 0);
2443 check ("trunc(-0) = -0", FUNC(trunc) (minus_zero), minus_zero);
2444 check ("trunc(0.625) = 0", FUNC(trunc) (0.625), 0);
2445 check ("trunc(-0.625) = -0", FUNC(trunc) (-0.625), minus_zero);
2446 check ("trunc(1) = 1", FUNC(trunc) (1), 1);
2447 check ("trunc(-1) = -1", FUNC(trunc) (-1), -1);
2448 check ("trunc(1.625) = 1", FUNC(trunc) (1.625), 1);
2449 check ("trunc(-1.625) = -1", FUNC(trunc) (-1.625), -1);
2451 check ("trunc(1048580.625) = 1048580", FUNC(trunc) (1048580.625L),
2452 1048580L);
2453 check ("trunc(-1048580.625) = -1048580", FUNC(trunc) (-1048580.625L),
2454 -1048580L);
2456 check ("trunc(8388610.125) = 8388610", FUNC(trunc) (8388610.125L),
2457 8388610.0L);
2458 check ("trunc(-8388610.125) = -8388610", FUNC(trunc) (-8388610.125L),
2459 -8388610.0L);
2461 check ("trunc(4294967296.625) = 4294967296", FUNC(trunc) (4294967296.625L),
2462 4294967296.0L);
2463 check ("trunc(-4294967296.625) = -4294967296",
2464 FUNC(trunc) (-4294967296.625L), -4294967296.0L);
2466 check_isinfp ("trunc(+inf) = +inf", FUNC(trunc) (plus_infty));
2467 check_isinfn ("trunc(-inf) = -inf", FUNC(trunc) (minus_infty));
2468 check_isnan ("trunc(NaN) = NaN", FUNC(trunc) (nan_value));
2472 static void
2473 sqrt_test (void)
2475 MATHTYPE x;
2478 /* XXX Tests fuer negative x are missing */
2479 check ("sqrt (0) == 0", FUNC(sqrt) (0), 0);
2480 check_isnan ("sqrt (NaN) == NaN", FUNC(sqrt) (nan_value));
2481 check_isinfp ("sqrt (+inf) == +inf", FUNC(sqrt) (plus_infty));
2483 check ("sqrt (-0) == -0", FUNC(sqrt) (0), 0);
2485 x = random_less (0.0);
2486 check_isnan_exc_ext ("sqrt (x) == NaN plus invalid exception for x < 0",
2487 FUNC(sqrt) (x), INVALID_EXCEPTION, x);
2489 x = random_value (0, 10000);
2490 check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x);
2491 check ("sqrt (4) == 2", FUNC(sqrt) (4), 2);
2492 check ("sqrt (2) == 1.14142...", FUNC(sqrt) (2), M_SQRT2l);
2493 check ("sqrt (0.25) == 0.5", FUNC(sqrt) (0.25), 0.5);
2494 check ("sqrt (6642.25) == 81.5", FUNC(sqrt) (6642.25), 81.5);
2495 check_eps ("sqrt (15239.903) == 123.45", FUNC(sqrt) (15239.903), 123.45,
2496 CHOOSE (3e-6L, 3e-6, 8e-6));
2497 check_eps ("sqrt (0.7) == 0.8366600265", FUNC(sqrt) (0.7),
2498 0.83666002653407554798L, CHOOSE(3e-17L, 0, 0));
2501 static void
2502 remainder_test (void)
2504 MATHTYPE result;
2506 result = FUNC(remainder) (1, 0);
2507 check_isnan_exc ("remainder(1, +0) == NaN plus invalid exception",
2508 result, INVALID_EXCEPTION);
2510 result = FUNC(remainder) (1, minus_zero);
2511 check_isnan_exc ("remainder(1, -0) == NaN plus invalid exception",
2512 result, INVALID_EXCEPTION);
2514 result = FUNC(remainder) (plus_infty, 1);
2515 check_isnan_exc ("remainder(+inf, 1) == NaN plus invalid exception",
2516 result, INVALID_EXCEPTION);
2518 result = FUNC(remainder) (minus_infty, 1);
2519 check_isnan_exc ("remainder(-inf, 1) == NaN plus invalid exception",
2520 result, INVALID_EXCEPTION);
2522 result = FUNC(remainder) (1.625, 1.0);
2523 check ("remainder(1.625, 1.0) == -0.375", result, -0.375);
2525 result = FUNC(remainder) (-1.625, 1.0);
2526 check ("remainder(-1.625, 1.0) == 0.375", result, 0.375);
2528 result = FUNC(remainder) (1.625, -1.0);
2529 check ("remainder(1.625, -1.0) == -0.375", result, -0.375);
2531 result = FUNC(remainder) (-1.625, -1.0);
2532 check ("remainder(-1.625, -1.0) == 0.375", result, 0.375);
2534 result = FUNC(remainder) (5.0, 2.0);
2535 check ("remainder(5.0, 2.0) == 1.0", result, 1.0);
2537 result = FUNC(remainder) (3.0, 2.0);
2538 check ("remainder(3.0, 2.0) == -1.0", result, -1.0);
2542 static void
2543 remquo_test (void)
2545 int quo;
2546 MATHTYPE result;
2548 result = FUNC(remquo) (1, 0, &quo);
2549 check_isnan_exc ("remquo(1, +0, &x) == NaN plus invalid exception",
2550 result, INVALID_EXCEPTION);
2552 result = FUNC(remquo) (1, minus_zero, &quo);
2553 check_isnan_exc ("remquo(1, -0, &x) == NaN plus invalid exception",
2554 result, INVALID_EXCEPTION);
2556 result = FUNC(remquo) (plus_infty, 1, &quo);
2557 check_isnan_exc ("remquo(+inf, 1, &x) == NaN plus invalid exception",
2558 result, INVALID_EXCEPTION);
2560 result = FUNC(remquo) (minus_infty, 1, &quo);
2561 check_isnan_exc ("remquo(-inf, 1, &x) == NaN plus invalid exception",
2562 result, INVALID_EXCEPTION);
2564 result = FUNC(remquo) (1.625, 1.0, &quo);
2565 check ("remquo(1.625, 1.0, &x) == -0.375", result, -0.375);
2566 check_long ("remquo(1.625, 1.0, &x) puts 2 in x", quo, 2);
2568 result = FUNC(remquo) (-1.625, 1.0, &quo);
2569 check ("remquo(-1.625, 1.0, &x) == 0.375", result, 0.375);
2570 check_long ("remquo(-1.625, 1.0, &x) puts -2 in x", quo, -2);
2572 result = FUNC(remquo) (1.625, -1.0, &quo);
2573 check ("remquo(1.625, -1.0, &x) == -0.375", result, -0.375);
2574 check_long ("remquo(1.625, -1.0, &x) puts -2 in x", quo, -2);
2576 result = FUNC(remquo) (-1.625, -1.0, &quo);
2577 check ("remquo(-1.625, -1.0, &x) == 0.375", result, 0.375);
2578 check_long ("remquo(-1.625, -1.0, &x) puts 2 in x", quo, 2);
2580 result = FUNC(remquo) (5.0, 2.0, &quo);
2581 check ("remquo(5.0, 2.0, &x) == 1.0", result, 1.0);
2582 check_long ("remquo (5.0, 2.0, &x) puts 2 in x", quo, 2);
2584 result = FUNC(remquo) (3.0, 2.0, &quo);
2585 check ("remquo(3.0, 2.0, &x) == -1.0", result, -1.0);
2586 check_long ("remquo (3.0, 2.0, &x) puts 2 in x", quo, 2);
2590 static void
2591 cexp_test (void)
2593 __complex__ MATHTYPE result;
2595 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, plus_zero));
2596 check ("real(cexp(0 + 0i)) = 1", __real__ result, 1);
2597 check ("imag(cexp(0 + 0i)) = 0", __imag__ result, 0);
2598 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_zero));
2599 check ("real(cexp(-0 + 0i)) = 1", __real__ result, 1);
2600 check ("imag(cexp(-0 + 0i)) = 0", __imag__ result, 0);
2601 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, minus_zero));
2602 check ("real(cexp(0 - 0i)) = 1", __real__ result, 1);
2603 check ("imag(cexp(0 - 0i)) = -0", __imag__ result, minus_zero);
2604 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_zero));
2605 check ("real(cexp(-0 - 0i)) = 1", __real__ result, 1);
2606 check ("imag(cexp(-0 - 0i)) = -0", __imag__ result, minus_zero);
2608 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_zero));
2609 check_isinfp ("real(cexp(+inf + 0i)) = +inf", __real__ result);
2610 check ("imag(cexp(+inf + 0i)) = 0", __imag__ result, 0);
2611 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_zero));
2612 check_isinfp ("real(cexp(+inf - 0i)) = +inf", __real__ result);
2613 check ("imag(cexp(+inf - 0i)) = -0", __imag__ result, minus_zero);
2615 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_zero));
2616 check ("real(cexp(-inf + 0i)) = 0", __real__ result, 0);
2617 check ("imag(cexp(-inf + 0i)) = 0", __imag__ result, 0);
2618 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_zero));
2619 check ("real(cexp(-inf - 0i)) = 0", __real__ result, 0);
2620 check ("imag(cexp(-inf - 0i)) = -0", __imag__ result, minus_zero);
2623 result = FUNC(cexp) (BUILD_COMPLEX (0.0, plus_infty));
2624 check_isnan_exc ("real(cexp(0 + i inf)) = NaN plus invalid exception",
2625 __real__ result, INVALID_EXCEPTION);
2626 check_isnan ("imag(cexp(0 + i inf)) = NaN plus invalid exception",
2627 __imag__ result);
2629 #if defined __GNUC__ && __GNUC__ <= 2 && __GNUC_MINOR__ <= 7
2630 if (verbose)
2631 printf ("The following test for cexp might fail due to a gcc compiler error!\n");
2632 #endif
2634 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_infty));
2635 check_isnan_exc ("real(cexp(-0 + i inf)) = NaN plus invalid exception",
2636 __real__ result, INVALID_EXCEPTION);
2637 check_isnan ("imag(cexp(-0 + i inf)) = NaN plus invalid exception",
2638 __imag__ result);
2639 result = FUNC(cexp) (BUILD_COMPLEX (0.0, minus_infty));
2640 check_isnan_exc ("real(cexp(0 - i inf)) = NaN plus invalid exception",
2641 __real__ result, INVALID_EXCEPTION);
2642 check_isnan ("imag(cexp(0 - i inf)) = NaN plus invalid exception",
2643 __imag__ result);
2644 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_infty));
2645 check_isnan_exc ("real(cexp(-0 - i inf)) = NaN plus invalid exception",
2646 __real__ result, INVALID_EXCEPTION);
2647 check_isnan ("imag(cexp(-0 - i inf)) = NaN plus invalid exception",
2648 __imag__ result);
2650 result = FUNC(cexp) (BUILD_COMPLEX (100.0, plus_infty));
2651 check_isnan_exc ("real(cexp(100.0 + i inf)) = NaN plus invalid exception",
2652 __real__ result, INVALID_EXCEPTION);
2653 check_isnan ("imag(cexp(100.0 + i inf)) = NaN plus invalid exception",
2654 __imag__ result);
2655 result = FUNC(cexp) (BUILD_COMPLEX (-100.0, plus_infty));
2656 check_isnan_exc ("real(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2657 __real__ result, INVALID_EXCEPTION);
2658 check_isnan ("imag(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2659 __imag__ result);
2660 result = FUNC(cexp) (BUILD_COMPLEX (100.0, minus_infty));
2661 check_isnan_exc ("real(cexp(100.0 - i inf)) = NaN plus invalid exception",
2662 __real__ result, INVALID_EXCEPTION);
2663 check_isnan ("imag(cexp(100.0 - i inf)) = NaN plus invalid exception",
2664 __imag__ result);
2665 result = FUNC(cexp) (BUILD_COMPLEX (-100.0, minus_infty));
2666 check_isnan_exc ("real(cexp(-100.0 - i inf)) = NaN plus invalid exception",
2667 __real__ result, INVALID_EXCEPTION);
2668 check_isnan ("imag(cexp(-100.0 - i inf)) = NaN", __imag__ result);
2670 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 2.0));
2671 check ("real(cexp(-inf + 2.0i)) = -0", __real__ result, minus_zero);
2672 check ("imag(cexp(-inf + 2.0i)) = 0", __imag__ result, 0);
2673 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 4.0));
2674 check ("real(cexp(-inf + 4.0i)) = -0", __real__ result, minus_zero);
2675 check ("imag(cexp(-inf + 4.0i)) = -0", __imag__ result, minus_zero);
2677 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 2.0));
2678 check_isinfn ("real(cexp(+inf + 2.0i)) = -inf", __real__ result);
2679 check_isinfp ("imag(cexp(+inf + 2.0i)) = +inf", __imag__ result);
2680 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 4.0));
2681 check_isinfn ("real(cexp(+inf + 4.0i)) = -inf", __real__ result);
2682 check_isinfn ("imag(cexp(+inf + 4.0i)) = -inf", __imag__ result);
2684 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_infty));
2685 check_isinfp_exc ("real(cexp(+inf + i inf)) = +inf plus invalid exception",
2686 __real__ result, INVALID_EXCEPTION);
2687 check_isnan ("imag(cexp(+inf + i inf)) = NaN plus invalid exception",
2688 __imag__ result);
2689 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_infty));
2690 check_isinfp_exc ("real(cexp(+inf - i inf)) = +inf plus invalid exception",
2691 __real__ result, INVALID_EXCEPTION);
2692 check_isnan ("imag(cexp(+inf - i inf)) = NaN plus invalid exception",
2693 __imag__ result);
2695 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_infty));
2696 check ("real(cexp(-inf + i inf)) = 0", __real__ result, 0);
2697 check ("imag(cexp(-inf + i inf)) = 0", __imag__ result, 0);
2698 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_infty));
2699 check ("real(cexp(-inf - i inf)) = 0", __real__ result, 0);
2700 check ("imag(cexp(-inf - i inf)) = -0", __imag__ result, minus_zero);
2702 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, nan_value));
2703 check ("real(cexp(-inf + i NaN)) = 0", __real__ result, 0);
2704 check ("imag(cexp(-inf + i NaN)) = 0", fabs (__imag__ result), 0);
2706 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, nan_value));
2707 check_isinfp ("real(cexp(+inf + i NaN)) = +inf", __real__ result);
2708 check_isnan ("imag(cexp(+inf + i NaN)) = NaN", __imag__ result);
2710 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 0.0));
2711 check_isnan_maybe_exc ("real(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2712 __real__ result, INVALID_EXCEPTION);
2713 check_isnan ("imag(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2714 __imag__ result);
2715 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
2716 check_isnan_maybe_exc ("real(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2717 __real__ result, INVALID_EXCEPTION);
2718 check_isnan ("imag(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2719 __imag__ result);
2720 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, plus_infty));
2721 check_isnan_maybe_exc ("real(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2722 __real__ result, INVALID_EXCEPTION);
2723 check_isnan ("imag(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2724 __imag__ result);
2726 result = FUNC(cexp) (BUILD_COMPLEX (0, nan_value));
2727 check_isnan_maybe_exc ("real(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2728 __real__ result, INVALID_EXCEPTION);
2729 check_isnan ("imag(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2730 __imag__ result);
2731 result = FUNC(cexp) (BUILD_COMPLEX (1, nan_value));
2732 check_isnan_maybe_exc ("real(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2733 __real__ result, INVALID_EXCEPTION);
2734 check_isnan ("imag(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2735 __imag__ result);
2737 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, nan_value));
2738 check_isnan ("real(cexp(NaN + i NaN)) = NaN", __real__ result);
2739 check_isnan ("imag(cexp(NaN + i NaN)) = NaN", __imag__ result);
2741 result = FUNC(cexp) (BUILD_COMPLEX (0.7, 1.2));
2742 check_eps ("real(cexp(0.7 + i 1.2)) == 0.72969...", __real__ result,
2743 0.7296989091503236012L, CHOOSE(6e-17L, 2e-16, 2e-7));
2744 check_eps ("imag(cexp(0.7 + i 1.2)) == 1.87689...", __imag__ result,
2745 1.8768962328348102821L, CHOOSE(2e-16L, 0, 3e-7));
2747 result = FUNC(cexp) (BUILD_COMPLEX (-2, -3));
2748 check_eps ("real(cexp(-2 - i 3)) == -0.13398...", __real__ result,
2749 -0.1339809149295426134L, CHOOSE(6e-20L, 0, 2e-8));
2750 check_eps ("imag(cexp(-2 - i 3)) == -0.01909...", __imag__ result,
2751 -0.0190985162611351964L, CHOOSE(4e-20L, 0, 2e-9));
2755 static void
2756 csin_test (void)
2758 __complex__ MATHTYPE result;
2760 result = FUNC(csin) (BUILD_COMPLEX (0.0, 0.0));
2761 check ("real(csin(0 + 0i)) = 0", __real__ result, 0);
2762 check ("imag(csin(0 + 0i)) = 0", __imag__ result, 0);
2763 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, 0.0));
2764 check ("real(csin(-0 + 0i)) = -0", __real__ result, minus_zero);
2765 check ("imag(csin(-0 + 0i)) = 0", __imag__ result, 0);
2766 result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_zero));
2767 check ("real(csin(0 - 0i)) = 0", __real__ result, 0);
2768 check ("imag(csin(0 - 0i)) = -0", __imag__ result, minus_zero);
2769 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_zero));
2770 check ("real(csin(-0 - 0i)) = -0", __real__ result, minus_zero);
2771 check ("imag(csin(-0 - 0i)) = -0", __imag__ result, minus_zero);
2773 result = FUNC(csin) (BUILD_COMPLEX (0.0, plus_infty));
2774 check ("real(csin(0 + i Inf)) = 0", __real__ result, 0);
2775 check_isinfp ("imag(csin(0 + i Inf)) = +Inf", __imag__ result);
2776 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, plus_infty));
2777 check ("real(csin(-0 + i Inf)) = -0", __real__ result, minus_zero);
2778 check_isinfp ("imag(csin(-0 + i Inf)) = +Inf", __imag__ result);
2779 result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_infty));
2780 check ("real(csin(0 - i Inf)) = 0", __real__ result, 0);
2781 check_isinfn ("imag(csin(0 - i Inf)) = -Inf", __imag__ result);
2782 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_infty));
2783 check ("real(csin(-0 - i Inf)) = -0", __real__ result, minus_zero);
2784 check_isinfn("imag(csin(-0 - i Inf)) = -Inf", __imag__ result);
2786 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 0.0));
2787 check_isnan_exc ("real(csin(+Inf + 0i)) = NaN plus invalid exception",
2788 __real__ result, INVALID_EXCEPTION);
2789 check ("imag(csin(+Inf + 0i)) = +-0 plus invalid exception",
2790 FUNC(fabs) (__imag__ result), 0);
2791 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 0.0));
2792 check_isnan_exc ("real(csin(-Inf + 0i)) = NaN plus invalid exception",
2793 __real__ result, INVALID_EXCEPTION);
2794 check ("imag(csin(-Inf + 0i)) = +-0 plus invalid exception",
2795 FUNC(fabs) (__imag__ result), 0);
2796 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_zero));
2797 check_isnan_exc ("real(csin(+Inf - 0i)) = NaN plus invalid exception",
2798 __real__ result, INVALID_EXCEPTION);
2799 check ("imag(csin(+Inf - 0i)) = +-0 plus invalid exception",
2800 FUNC(fabs) (__imag__ result), 0.0);
2801 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_zero));
2802 check_isnan_exc ("real(csin(-Inf - 0i)) = NaN plus invalid exception",
2803 __real__ result, INVALID_EXCEPTION);
2804 check ("imag(csin(-Inf - 0i)) = +-0 plus invalid exception",
2805 FUNC(fabs) (__imag__ result), 0.0);
2807 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, plus_infty));
2808 check_isnan_exc ("real(csin(+Inf + i Inf)) = NaN plus invalid exception",
2809 __real__ result, INVALID_EXCEPTION);
2810 check_isinfp ("imag(csin(+Inf + i Inf)) = +-Inf plus invalid exception",
2811 FUNC(fabs) (__imag__ result));
2812 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, plus_infty));
2813 check_isnan_exc ("real(csin(-Inf + i Inf)) = NaN plus invalid exception",
2814 __real__ result, INVALID_EXCEPTION);
2815 check_isinfp ("imag(csin(-Inf + i Inf)) = +-Inf plus invalid exception",
2816 FUNC(fabs) (__imag__ result));
2817 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_infty));
2818 check_isnan_exc ("real(csin(Inf - i Inf)) = NaN plus invalid exception",
2819 __real__ result, INVALID_EXCEPTION);
2820 check_isinfp ("imag(csin(Inf - i Inf)) = +-Inf plus invalid exception",
2821 FUNC(fabs) (__imag__ result));
2822 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_infty));
2823 check_isnan_exc ("real(csin(-Inf - i Inf)) = NaN plus invalid exception",
2824 __real__ result, INVALID_EXCEPTION);
2825 check_isinfp ("imag(csin(-Inf - i Inf)) = +-Inf plus invalid exception",
2826 FUNC(fabs) (__imag__ result));
2828 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 6.75));
2829 check_isnan_exc ("real(csin(+Inf + i 6.75)) = NaN plus invalid exception",
2830 __real__ result, INVALID_EXCEPTION);
2831 check_isnan ("imag(csin(+Inf + i6.75)) = NaN plus invalid exception",
2832 __imag__ result);
2833 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, -6.75));
2834 check_isnan_exc ("real(csin(+Inf - i 6.75)) = NaN plus invalid exception",
2835 __real__ result, INVALID_EXCEPTION);
2836 check_isnan ("imag(csin(+Inf - i6.75)) = NaN plus invalid exception",
2837 __imag__ result);
2838 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 6.75));
2839 check_isnan_exc ("real(csin(-Inf + i6.75)) = NaN plus invalid exception",
2840 __real__ result, INVALID_EXCEPTION);
2841 check_isnan ("imag(csin(-Inf + i6.75)) = NaN plus invalid exception",
2842 __imag__ result);
2843 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, -6.75));
2844 check_isnan_exc ("real(csin(-Inf - i6.75)) = NaN plus invalid exception",
2845 __real__ result, INVALID_EXCEPTION);
2846 check_isnan ("imag(csin(-Inf - i6.75)) = NaN plus invalid exception",
2847 __imag__ result);
2849 result = FUNC(csin) (BUILD_COMPLEX (4.625, plus_infty));
2850 check_isinfn ("real(csin(4.625 + i Inf)) = -Inf", __real__ result);
2851 check_isinfn ("imag(csin(4.625 + i Inf)) = -Inf", __imag__ result);
2852 result = FUNC(csin) (BUILD_COMPLEX (4.625, minus_infty));
2853 check_isinfn ("real(csin(4.625 - i Inf)) = -Inf", __real__ result);
2854 check_isinfp ("imag(csin(4.625 - i Inf)) = +Inf", __imag__ result);
2855 result = FUNC(csin) (BUILD_COMPLEX (-4.625, plus_infty));
2856 check_isinfp ("real(csin(-4.625 + i Inf)) = +Inf", __real__ result);
2857 check_isinfn ("imag(csin(-4.625 + i Inf)) = -Inf", __imag__ result);
2858 result = FUNC(csin) (BUILD_COMPLEX (-4.625, minus_infty));
2859 check_isinfp ("real(csin(-4.625 - i Inf)) = +Inf", __real__ result);
2860 check_isinfp ("imag(csin(-4.625 - i Inf)) = +Inf", __imag__ result);
2862 result = FUNC(csin) (BUILD_COMPLEX (nan_value, 0.0));
2863 check_isnan ("real(csin(NaN + i0)) = NaN", __real__ result);
2864 check ("imag(csin(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2865 result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_zero));
2866 check_isnan ("real(csin(NaN - i0)) = NaN", __real__ result);
2867 check ("imag(csin(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2869 result = FUNC(csin) (BUILD_COMPLEX (nan_value, plus_infty));
2870 check_isnan ("real(csin(NaN + i Inf)) = NaN", __real__ result);
2871 check_isinfp ("imag(csin(NaN + i Inf)) = +-Inf",
2872 FUNC(fabs) (__imag__ result));
2873 result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_infty));
2874 check_isnan ("real(csin(NaN - i Inf)) = NaN", __real__ result);
2875 check_isinfp ("real(csin(NaN - i Inf)) = +-Inf",
2876 FUNC(fabs) (__imag__ result));
2878 result = FUNC(csin) (BUILD_COMPLEX (nan_value, 9.0));
2879 check_isnan_maybe_exc ("real(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2880 __real__ result, INVALID_EXCEPTION);
2881 check_isnan ("imag(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2882 __imag__ result);
2883 result = FUNC(csin) (BUILD_COMPLEX (nan_value, -9.0));
2884 check_isnan_maybe_exc ("real(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2885 __real__ result, INVALID_EXCEPTION);
2886 check_isnan ("imag(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2887 __imag__ result);
2889 result = FUNC(csin) (BUILD_COMPLEX (0.0, nan_value));
2890 check ("real(csin(0 + i NaN))", __real__ result, 0.0);
2891 check_isnan ("imag(csin(0 + i NaN)) = NaN", __imag__ result);
2892 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, nan_value));
2893 check ("real(csin(-0 + i NaN)) = -0", __real__ result, minus_zero);
2894 check_isnan ("imag(csin(-0 + NaN)) = NaN", __imag__ result);
2896 result = FUNC(csin) (BUILD_COMPLEX (10.0, nan_value));
2897 check_isnan_maybe_exc ("real(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2898 __real__ result, INVALID_EXCEPTION);
2899 check_isnan ("imag(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2900 __imag__ result);
2901 result = FUNC(csin) (BUILD_COMPLEX (nan_value, -10.0));
2902 check_isnan_maybe_exc ("real(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2903 __real__ result, INVALID_EXCEPTION);
2904 check_isnan ("imag(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2905 __imag__ result);
2907 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, nan_value));
2908 check_isnan_maybe_exc ("real(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2909 __real__ result, INVALID_EXCEPTION);
2910 check_isnan ("imag(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2911 __imag__ result);
2912 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, nan_value));
2913 check_isnan_maybe_exc ("real(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2914 __real__ result, INVALID_EXCEPTION);
2915 check_isnan ("imag(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2916 __imag__ result);
2918 result = FUNC(csin) (BUILD_COMPLEX (nan_value, nan_value));
2919 check_isnan ("real(csin(NaN + i NaN)) = NaN", __real__ result);
2920 check_isnan ("imag(csin(NaN + i NaN)) = NaN", __imag__ result);
2922 result = FUNC(csin) (BUILD_COMPLEX (0.7, 1.2));
2923 check_eps ("real(csin(0.7 + i 1.2)) = 1.166456341...", __real__ result,
2924 1.1664563419657581376L, CHOOSE(2e-16L, 0, 0));
2925 check_eps ("imag(csin(0.7 + i 1.2)) = 1.154499724...", __imag__ result,
2926 1.1544997246948547371L, CHOOSE(2e-17L, 0, 2e-7));
2928 result = FUNC(csin) (BUILD_COMPLEX (-2, -3));
2929 check_eps ("real(csin(-2 - i 3)) == -9.15449...", __real__ result,
2930 -9.1544991469114295734L, CHOOSE(4e-18L, 0, 1e-6));
2931 check_eps ("imag(csin(-2 - i 3)) == -4.16890...", __imag__ result,
2932 4.1689069599665643507L, CHOOSE(2e-17L, 0, 5e-7));
2936 static void
2937 csinh_test (void)
2939 __complex__ MATHTYPE result;
2941 result = FUNC(csinh) (BUILD_COMPLEX (0.0, 0.0));
2942 check ("real(csinh(0 + 0i)) = 0", __real__ result, 0);
2943 check ("imag(csinh(0 + 0i)) = 0", __imag__ result, 0);
2944 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, 0.0));
2945 check ("real(csinh(-0 + 0i)) = -0", __real__ result, minus_zero);
2946 check ("imag(csinh(-0 + 0i)) = 0", __imag__ result, 0);
2947 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_zero));
2948 check ("real(csinh(0 - 0i)) = 0", __real__ result, 0);
2949 check ("imag(csinh(0 - 0i)) = -0", __imag__ result, minus_zero);
2950 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_zero));
2951 check ("real(csinh(-0 - 0i)) = -0", __real__ result, minus_zero);
2952 check ("imag(csinh(-0 - 0i)) = -0", __imag__ result, minus_zero);
2954 result = FUNC(csinh) (BUILD_COMPLEX (0.0, plus_infty));
2955 check_exc ("real(csinh(0 + i Inf)) = +-0 plus invalid exception",
2956 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2957 check_isnan ("imag(csinh(0 + i Inf)) = NaN plus invalid exception",
2958 __imag__ result);
2959 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, plus_infty));
2960 check_exc ("real(csinh(-0 + i Inf)) = +-0 plus invalid exception",
2961 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2962 check_isnan ("imag(csinh(-0 + i Inf)) = NaN plus invalid exception",
2963 __imag__ result);
2964 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_infty));
2965 check_exc ("real(csinh(0 - i Inf)) = +-0 plus invalid exception",
2966 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2967 check_isnan ("imag(csinh(0 - i Inf)) = NaN plus invalid exception",
2968 __imag__ result);
2969 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_infty));
2970 check_exc ("real(csinh(-0 - i Inf)) = +-0 plus invalid exception",
2971 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2972 check_isnan ("imag(csinh(-0 - i Inf)) = NaN plus invalid exception",
2973 __imag__ result);
2975 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 0.0));
2976 check_isinfp ("real(csinh(+Inf + 0i)) = +Inf", __real__ result);
2977 check ("imag(csinh(+Inf + 0i)) = 0", __imag__ result, 0);
2978 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 0.0));
2979 check_isinfn ("real(csinh(-Inf + 0i)) = -Inf", __real__ result);
2980 check ("imag(csinh(-Inf + 0i)) = 0", __imag__ result, 0);
2981 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_zero));
2982 check_isinfp ("real(csinh(+Inf - 0i)) = +Inf", __real__ result);
2983 check ("imag(csinh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
2984 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_zero));
2985 check_isinfn ("real(csinh(-Inf - 0i)) = -Inf", __real__ result);
2986 check ("imag(csinh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
2988 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, plus_infty));
2989 check_isinfp_exc ("real(csinh(+Inf + i Inf)) = +-Inf plus invalid exception",
2990 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2991 check_isnan ("imag(csinh(+Inf + i Inf)) = NaN plus invalid exception",
2992 __imag__ result);
2993 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, plus_infty));
2994 check_isinfp_exc ("real(csinh(-Inf + i Inf)) = +-Inf plus invalid exception",
2995 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2996 check_isnan ("imag(csinh(-Inf + i Inf)) = NaN plus invalid exception",
2997 __imag__ result);
2998 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_infty));
2999 check_isinfp_exc ("real(csinh(Inf - i Inf)) = +-Inf plus invalid exception",
3000 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
3001 check_isnan ("imag(csinh(Inf - i Inf)) = NaN plus invalid exception",
3002 __imag__ result);
3003 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_infty));
3004 check_isinfp_exc ("real(csinh(-Inf - i Inf)) = +-Inf plus invalid exception",
3005 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
3006 check_isnan ("imag(csinh(-Inf - i Inf)) = NaN plus invalid exception",
3007 __imag__ result);
3009 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 4.625));
3010 check_isinfn ("real(csinh(+Inf + i4.625)) = -Inf", __real__ result);
3011 check_isinfn ("imag(csinh(+Inf + i4.625)) = -Inf", __imag__ result);
3012 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 4.625));
3013 check_isinfp ("real(csinh(-Inf + i4.625)) = +Inf", __real__ result);
3014 check_isinfn ("imag(csinh(-Inf + i4.625)) = -Inf", __imag__ result);
3015 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, -4.625));
3016 check_isinfn ("real(csinh(+Inf - i4.625)) = -Inf", __real__ result);
3017 check_isinfp ("imag(csinh(+Inf - i4.625)) = +Inf", __imag__ result);
3018 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, -4.625));
3019 check_isinfp ("real(csinh(-Inf - i4.625)) = +Inf", __real__ result);
3020 check_isinfp ("imag(csinh(-Inf - i4.625)) = +Inf", __imag__ result);
3022 result = FUNC(csinh) (BUILD_COMPLEX (6.75, plus_infty));
3023 check_isnan_exc ("real(csinh(6.75 + i Inf)) = NaN plus invalid exception",
3024 __real__ result, INVALID_EXCEPTION);
3025 check_isnan ("imag(csinh(6.75 + i Inf)) = NaN plus invalid exception",
3026 __imag__ result);
3027 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, plus_infty));
3028 check_isnan_exc ("real(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
3029 __real__ result, INVALID_EXCEPTION);
3030 check_isnan ("imag(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
3031 __imag__ result);
3032 result = FUNC(csinh) (BUILD_COMPLEX (6.75, minus_infty));
3033 check_isnan_exc ("real(csinh(6.75 - i Inf)) = NaN plus invalid exception",
3034 __real__ result, INVALID_EXCEPTION);
3035 check_isnan ("imag(csinh(6.75 - i Inf)) = NaN plus invalid exception",
3036 __imag__ result);
3037 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, minus_infty));
3038 check_isnan_exc ("real(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
3039 __real__ result, INVALID_EXCEPTION);
3040 check_isnan ("imag(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
3041 __imag__ result);
3043 result = FUNC(csinh) (BUILD_COMPLEX (0.0, nan_value));
3044 check ("real(csinh(0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
3045 check_isnan ("imag(csinh(0 + i NaN)) = NaN", __imag__ result);
3046 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, nan_value));
3047 check ("real(csinh(-0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
3048 check_isnan ("imag(csinh(-0 + i NaN)) = NaN", __imag__ result);
3050 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, nan_value));
3051 check_isinfp ("real(csinh(+Inf + i NaN)) = +-Inf",
3052 FUNC(fabs) (__real__ result));
3053 check_isnan ("imag(csinh(+Inf + i NaN)) = NaN", __imag__ result);
3054 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, nan_value));
3055 check_isinfp ("real(csinh(-Inf + i NaN)) = +-Inf",
3056 FUNC(fabs) (__real__ result));
3057 check_isnan ("imag(csinh(-Inf + i NaN)) = NaN", __imag__ result);
3059 result = FUNC(csinh) (BUILD_COMPLEX (9.0, nan_value));
3060 check_isnan_maybe_exc ("real(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3061 __real__ result, INVALID_EXCEPTION);
3062 check_isnan ("imag(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3063 __imag__ result);
3064 result = FUNC(csinh) (BUILD_COMPLEX (-9.0, nan_value));
3065 check_isnan_maybe_exc ("real(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3066 __real__ result, INVALID_EXCEPTION);
3067 check_isnan ("imag(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3068 __imag__ result);
3070 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 0.0));
3071 check_isnan ("real(csinh(NaN + i0)) = NaN", __real__ result);
3072 check ("imag(csinh(NaN + i0)) = 0", __imag__ result, 0.0);
3073 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_zero));
3074 check_isnan ("real(csinh(NaN - i0)) = NaN", __real__ result);
3075 check ("imag(csinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3077 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 10.0));
3078 check_isnan_maybe_exc ("real(csinh(NaN + i10)) = NaN plus maybe invalid exception",
3079 __real__ result, INVALID_EXCEPTION);
3080 check_isnan ("imag(csinh(NaN + i10)) = NaN plus maybe invalid exception",
3081 __imag__ result);
3082 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, -10.0));
3083 check_isnan_maybe_exc ("real(csinh(NaN - i10)) = NaN plus maybe invalid exception",
3084 __real__ result, INVALID_EXCEPTION);
3085 check_isnan ("imag(csinh(NaN - i10)) = NaN plus maybe invalid exception",
3086 __imag__ result);
3088 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, plus_infty));
3089 check_isnan_maybe_exc ("real(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
3090 __real__ result, INVALID_EXCEPTION);
3091 check_isnan ("imag(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
3092 __imag__ result);
3093 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_infty));
3094 check_isnan_maybe_exc ("real(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
3095 __real__ result, INVALID_EXCEPTION);
3096 check_isnan ("imag(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
3097 __imag__ result);
3099 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, nan_value));
3100 check_isnan ("real(csinh(NaN + i NaN)) = NaN", __real__ result);
3101 check_isnan ("imag(csinh(NaN + i NaN)) = NaN", __imag__ result);
3103 result = FUNC(csinh) (BUILD_COMPLEX (0.7, 1.2));
3104 check_eps ("real(csinh(0.7 + i 1.2)) = 0.274878686...", __real__ result,
3105 0.27487868678117583582L, CHOOSE(2e-17L, 6e-17, 3e-8));
3106 check_eps ("imag(csinh(0.7 + i 1.2)) = 1.169866572...", __imag__ result,
3107 1.1698665727426565139L, CHOOSE(6e-17L, 0, 2e-7));
3109 result = FUNC(csinh) (BUILD_COMPLEX (-2, -3));
3110 check_eps ("real(csinh(-2 - i 3)) == -3.59056...", __real__ result,
3111 3.5905645899857799520L, CHOOSE(7e-19L, 5e-16, 3e-7));
3112 check_eps ("imag(csinh(-2 - i 3)) == -0.53092...", __imag__ result,
3113 -0.5309210862485198052L, CHOOSE(3e-19L, 2e-16, 6e-8));
3117 static void
3118 ccos_test (void)
3120 __complex__ MATHTYPE result;
3122 result = FUNC(ccos) (BUILD_COMPLEX (0.0, 0.0));
3123 check ("real(ccos(0 + 0i)) = 1.0", __real__ result, 1.0);
3124 check ("imag(ccos(0 + 0i)) = -0", __imag__ result, minus_zero);
3125 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, 0.0));
3126 check ("real(ccos(-0 + 0i)) = 1.0", __real__ result, 1.0);
3127 check ("imag(ccos(-0 + 0i)) = 0", __imag__ result, 0.0);
3128 result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_zero));
3129 check ("real(ccos(0 - 0i)) = 1.0", __real__ result, 1.0);
3130 check ("imag(ccos(0 - 0i)) = 0", __imag__ result, 0.0);
3131 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_zero));
3132 check ("real(ccos(-0 - 0i)) = 1.0", __real__ result, 1.0);
3133 check ("imag(ccos(-0 - 0i)) = -0", __imag__ result, minus_zero);
3135 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 0.0));
3136 check_isnan_exc ("real(ccos(+Inf + i0)) = NaN plus invalid exception",
3137 __real__ result, INVALID_EXCEPTION);
3138 check ("imag(ccos(Inf + i0)) = +-0 plus invalid exception",
3139 FUNC(fabs) (__imag__ result), 0);
3140 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_zero));
3141 check_isnan_exc ("real(ccos(Inf - i0)) = NaN plus invalid exception",
3142 __real__ result, INVALID_EXCEPTION);
3143 check ("imag(ccos(Inf - i0)) = +-0 plus invalid exception",
3144 FUNC(fabs) (__imag__ result), 0);
3145 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 0.0));
3146 check_isnan_exc ("real(ccos(-Inf + i0)) = NaN plus invalid exception",
3147 __real__ result, INVALID_EXCEPTION);
3148 check ("imag(ccos(-Inf + i0)) = +-0 plus invalid exception",
3149 FUNC(fabs) (__imag__ result), 0);
3150 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_zero));
3151 check_isnan_exc ("real(ccos(-Inf - i0)) = NaN plus invalid exception",
3152 __real__ result, INVALID_EXCEPTION);
3153 check ("imag(ccos(-Inf - i0)) = +-0 plus invalid exception",
3154 FUNC(fabs) (__imag__ result), 0);
3156 result = FUNC(ccos) (BUILD_COMPLEX (0.0, plus_infty));
3157 check_isinfp ("real(ccos(0 + i Inf)) = +Inf", __real__ result);
3158 check ("imag(ccos(0 + i Inf)) = -0", __imag__ result, minus_zero);
3159 result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_infty));
3160 check_isinfp ("real(ccos(0 - i Inf)) = +Inf", __real__ result);
3161 check ("imag(ccos(0 - i Inf)) = 0", __imag__ result, 0);
3162 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, plus_infty));
3163 check_isinfp ("real(ccos(-0 + i Inf)) = +Inf", __real__ result);
3164 check ("imag(ccos(-0 + i Inf)) = 0", __imag__ result, 0.0);
3165 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_infty));
3166 check_isinfp ("real(ccos(-0 - i Inf)) = +Inf", __real__ result);
3167 check ("imag(ccos(-0 - i Inf)) = -0", __imag__ result, minus_zero);
3169 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, plus_infty));
3170 check_isinfp_exc ("real(ccos(+Inf + i Inf)) = +Inf plus invalid exception",
3171 __real__ result, INVALID_EXCEPTION);
3172 check_isnan ("imag(ccos(+Inf + i Inf)) = NaN plus invalid exception",
3173 __imag__ result);
3174 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, plus_infty));
3175 check_isinfp_exc ("real(ccos(-Inf + i Inf)) = +Inf plus invalid exception",
3176 __real__ result, INVALID_EXCEPTION);
3177 check_isnan ("imag(ccos(-Inf + i Inf)) = NaN plus invalid exception",
3178 __imag__ result);
3179 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_infty));
3180 check_isinfp_exc ("real(ccos(Inf - i Inf)) = +Inf plus invalid exception",
3181 __real__ result, INVALID_EXCEPTION);
3182 check_isnan ("imag(ccos(Inf - i Inf)) = NaN plus invalid exception",
3183 __imag__ result);
3184 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_infty));
3185 check_isinfp_exc ("real(ccos(-Inf - i Inf)) = +Inf plus invalid exception",
3186 __real__ result, INVALID_EXCEPTION);
3187 check_isnan ("imag(ccos(-Inf - i Inf)) = NaN plus invalid exception",
3188 __imag__ result);
3190 result = FUNC(ccos) (BUILD_COMPLEX (4.625, plus_infty));
3191 check_isinfn ("real(ccos(4.625 + i Inf)) = -Inf", __real__ result);
3192 check_isinfp ("imag(ccos(4.625 + i Inf)) = +Inf", __imag__ result);
3193 result = FUNC(ccos) (BUILD_COMPLEX (4.625, minus_infty));
3194 check_isinfn ("real(ccos(4.625 - i Inf)) = -Inf", __real__ result);
3195 check_isinfn ("imag(ccos(4.625 - i Inf)) = -Inf", __imag__ result);
3196 result = FUNC(ccos) (BUILD_COMPLEX (-4.625, plus_infty));
3197 check_isinfn ("real(ccos(-4.625 + i Inf)) = -Inf", __real__ result);
3198 check_isinfn ("imag(ccos(-4.625 + i Inf)) = -Inf", __imag__ result);
3199 result = FUNC(ccos) (BUILD_COMPLEX (-4.625, minus_infty));
3200 check_isinfn ("real(ccos(-4.625 - i Inf)) = -Inf", __real__ result);
3201 check_isinfp ("imag(ccos(-4.625 - i Inf)) = +Inf", __imag__ result);
3203 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 6.75));
3204 check_isnan_exc ("real(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3205 __real__ result, INVALID_EXCEPTION);
3206 check_isnan ("imag(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3207 __imag__ result);
3208 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, -6.75));
3209 check_isnan_exc ("real(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3210 __real__ result, INVALID_EXCEPTION);
3211 check_isnan ("imag(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3212 __imag__ result);
3213 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 6.75));
3214 check_isnan_exc ("real(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3215 __real__ result, INVALID_EXCEPTION);
3216 check_isnan ("imag(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3217 __imag__ result);
3218 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, -6.75));
3219 check_isnan_exc ("real(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3220 __real__ result, INVALID_EXCEPTION);
3221 check_isnan ("imag(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3222 __imag__ result);
3224 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 0.0));
3225 check_isnan ("real(ccos(NaN + i0)) = NaN", __real__ result);
3226 check ("imag(ccos(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3227 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_zero));
3228 check_isnan ("real(ccos(NaN - i0)) = NaN", __real__ result);
3229 check ("imag(ccos(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3231 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, plus_infty));
3232 check_isinfp ("real(ccos(NaN + i Inf)) = +Inf", __real__ result);
3233 check_isnan ("imag(ccos(NaN + i Inf)) = NaN", __imag__ result);
3234 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_infty));
3235 check_isinfp ("real(ccos(NaN - i Inf)) = +Inf", __real__ result);
3236 check_isnan ("imag(ccos(NaN - i Inf)) = NaN", __imag__ result);
3238 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 9.0));
3239 check_isnan_maybe_exc ("real(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3240 __real__ result, INVALID_EXCEPTION);
3241 check_isnan ("imag(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3242 __imag__ result);
3243 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, -9.0));
3244 check_isnan_maybe_exc ("real(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3245 __real__ result, INVALID_EXCEPTION);
3246 check_isnan ("imag(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3247 __imag__ result);
3249 result = FUNC(ccos) (BUILD_COMPLEX (0.0, nan_value));
3250 check_isnan ("real(ccos(0 + i NaN)) = NaN", __real__ result);
3251 check ("imag(ccos(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3252 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, nan_value));
3253 check_isnan ("real(ccos(-0 + i NaN)) = NaN", __real__ result);
3254 check ("imag(ccos(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3256 result = FUNC(ccos) (BUILD_COMPLEX (10.0, nan_value));
3257 check_isnan_maybe_exc ("real(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3258 __real__ result, INVALID_EXCEPTION);
3259 check_isnan ("imag(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3260 __imag__ result);
3261 result = FUNC(ccos) (BUILD_COMPLEX (-10.0, nan_value));
3262 check_isnan_maybe_exc ("real(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3263 __real__ result, INVALID_EXCEPTION);
3264 check_isnan ("imag(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3265 __imag__ result);
3267 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, nan_value));
3268 check_isnan_maybe_exc ("real(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3269 __real__ result, INVALID_EXCEPTION);
3270 check_isnan ("imag(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3271 __imag__ result);
3272 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, nan_value));
3273 check_isnan_maybe_exc ("real(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3274 __real__ result, INVALID_EXCEPTION);
3275 check_isnan ("imag(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3276 __imag__ result);
3278 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, nan_value));
3279 check_isnan ("real(ccos(NaN + i NaN)) = NaN", __real__ result);
3280 check_isnan ("imag(ccos(NaN + i NaN)) = NaN", __imag__ result);
3282 result = FUNC(ccos) (BUILD_COMPLEX (0.7, 1.2));
3283 check_eps ("real(ccos(0.7 + i 1.2)) = 1.384865764...", __real__ result,
3284 1.3848657645312111080L, CHOOSE(4e-18L, 3e-16, 2e-7));
3285 check_eps ("imag(ccos(0.7 + i 1.2)) = -0.972421703...", __imag__ result,
3286 -0.97242170335830028619L, CHOOSE(2e-16L, 2e-16, 0));
3288 result = FUNC(ccos) (BUILD_COMPLEX (-2, -3));
3289 check_eps ("real(ccos(-2 - i 3)) == -4.18962...", __real__ result,
3290 -4.1896256909688072301L, CHOOSE(2e-17L, 0, 5e-7));
3291 check_eps ("imag(ccos(-2 - i 3)) == -9.10922...", __imag__ result,
3292 -9.1092278937553365979L, CHOOSE(3e-18L, 0, 1e-6));
3296 static void
3297 ccosh_test (void)
3299 __complex__ MATHTYPE result;
3301 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, 0.0));
3302 check ("real(ccosh(0 + 0i)) = 1.0", __real__ result, 1.0);
3303 check ("imag(ccosh(0 + 0i)) = 0", __imag__ result, 0);
3304 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, 0.0));
3305 check ("real(ccosh(-0 + 0i)) = 1.0", __real__ result, 1.0);
3306 check ("imag(ccosh(-0 + 0i)) = -0", __imag__ result, minus_zero);
3307 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_zero));
3308 check ("real(ccosh(0 - 0i)) = 1.0", __real__ result, 1.0);
3309 check ("imag(ccosh(0 - 0i)) = -0", __imag__ result, minus_zero);
3310 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3311 check ("real(ccosh(-0 - 0i)) = 1.0", __real__ result, 1.0);
3312 check ("imag(ccosh(-0 - 0i)) = 0", __imag__ result, 0.0);
3314 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, plus_infty));
3315 check_isnan_exc ("real(ccosh(0 + i Inf)) = NaN plus invalid exception",
3316 __real__ result, INVALID_EXCEPTION);
3317 check ("imag(ccosh(0 + i Inf)) = +-0 plus invalid exception",
3318 FUNC(fabs) (__imag__ result), 0);
3319 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, plus_infty));
3320 check_isnan_exc ("real(ccosh(-0 + i Inf)) = NaN plus invalid exception",
3321 __real__ result, INVALID_EXCEPTION);
3322 check ("imag(ccosh(-0 + i Inf)) = +-0 plus invalid exception",
3323 FUNC(fabs) (__imag__ result), 0);
3324 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_infty));
3325 check_isnan_exc ("real(ccosh(0 - i Inf)) = NaN plus invalid exception",
3326 __real__ result, INVALID_EXCEPTION);
3327 check ("imag(ccosh(0 - i Inf)) = +-0 plus invalid exception",
3328 FUNC(fabs) (__imag__ result), 0);
3329 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_infty));
3330 check_isnan_exc ("real(ccosh(-0 - i Inf)) = NaN plus invalid exception",
3331 __real__ result, INVALID_EXCEPTION);
3332 check ("imag(ccosh(-0 - i Inf)) = +-0 plus invalid exception",
3333 FUNC(fabs) (__imag__ result), 0);
3335 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 0.0));
3336 check_isinfp ("real(ccosh(+Inf + 0i)) = +Inf", __real__ result);
3337 check ("imag(ccosh(+Inf + 0i)) = 0", __imag__ result, 0);
3338 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 0.0));
3339 check_isinfp ("real(ccosh(-Inf + 0i)) = +Inf", __real__ result);
3340 check ("imag(ccosh(-Inf + 0i)) = -0", __imag__ result, minus_zero);
3341 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3342 check_isinfp ("real(ccosh(+Inf - 0i)) = +Inf", __real__ result);
3343 check ("imag(ccosh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
3344 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3345 check_isinfp ("real(ccosh(-Inf - 0i)) = +Inf", __real__ result);
3346 check ("imag(ccosh(-Inf - 0i)) = 0", __imag__ result, 0.0);
3348 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3349 check_isinfp_exc ("real(ccosh(+Inf + i Inf)) = +Inf plus invalid exception",
3350 __real__ result, INVALID_EXCEPTION);
3351 check_isnan ("imag(ccosh(+Inf + i Inf)) = NaN plus invalid exception",
3352 __imag__ result);
3353 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3354 check_isinfp_exc ("real(ccosh(-Inf + i Inf)) = +Inf plus invalid exception",
3355 __real__ result, INVALID_EXCEPTION);
3356 check_isnan ("imag(ccosh(-Inf + i Inf)) = NaN plus invalid exception",
3357 __imag__ result);
3358 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3359 check_isinfp_exc ("real(ccosh(Inf - i Inf)) = +Inf plus invalid exception",
3360 __real__ result, INVALID_EXCEPTION);
3361 check_isnan ("imag(ccosh(Inf - i Inf)) = NaN plus invalid exception",
3362 __imag__ result);
3363 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3364 check_isinfp_exc ("real(ccosh(-Inf - i Inf)) = +Inf plus invalid exception",
3365 __real__ result, INVALID_EXCEPTION);
3366 check_isnan ("imag(ccosh(-Inf - i Inf)) = NaN plus invalid exception",
3367 __imag__ result);
3369 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 4.625));
3370 check_isinfn ("real(ccosh(+Inf + i4.625)) = -Inf", __real__ result);
3371 check_isinfn ("imag(ccosh(+Inf + i4.625)) = -Inf", __imag__ result);
3372 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 4.625));
3373 check_isinfn ("real(ccosh(-Inf + i4.625)) = -Inf", __real__ result);
3374 check_isinfp ("imag(ccosh(-Inf + i4.625)) = Inf", __imag__ result);
3375 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, -4.625));
3376 check_isinfn ("real(ccosh(+Inf - i4.625)) = -Inf", __real__ result);
3377 check_isinfp ("imag(ccosh(+Inf - i4.625)) = +Inf", __imag__ result);
3378 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, -4.625));
3379 check_isinfn ("real(ccosh(-Inf - i4.625)) = -Inf", __real__ result);
3380 check_isinfn ("imag(ccosh(-Inf - i4.625)) = -Inf", __imag__ result);
3382 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, plus_infty));
3383 check_isnan_exc ("real(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3384 __real__ result, INVALID_EXCEPTION);
3385 check_isnan ("imag(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3386 __imag__ result);
3387 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, plus_infty));
3388 check_isnan_exc ("real(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3389 __real__ result, INVALID_EXCEPTION);
3390 check_isnan ("imag(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3391 __imag__ result);
3392 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, minus_infty));
3393 check_isnan_exc ("real(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3394 __real__ result, INVALID_EXCEPTION);
3395 check_isnan ("imag(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3396 __imag__ result);
3397 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, minus_infty));
3398 check_isnan_exc ("real(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3399 __real__ result, INVALID_EXCEPTION);
3400 check_isnan ("imag(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3401 __imag__ result);
3403 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, nan_value));
3404 check_isnan ("real(ccosh(0 + i NaN)) = NaN", __real__ result);
3405 check ("imag(ccosh(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3406 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, nan_value));
3407 check_isnan ("real(ccosh(-0 + i NaN)) = NaN", __real__ result);
3408 check ("imag(ccosh(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3410 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, nan_value));
3411 check_isinfp ("real(ccosh(+Inf + i NaN)) = +Inf", __real__ result);
3412 check_isnan ("imag(ccosh(+Inf + i NaN)) = NaN", __imag__ result);
3413 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, nan_value));
3414 check_isinfp ("real(ccosh(-Inf + i NaN)) = +Inf", __real__ result);
3415 check_isnan ("imag(ccosh(-Inf + i NaN)) = NaN", __imag__ result);
3417 result = FUNC(ccosh) (BUILD_COMPLEX (9.0, nan_value));
3418 check_isnan_maybe_exc ("real(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3419 __real__ result, INVALID_EXCEPTION);
3420 check_isnan ("imag(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3421 __imag__ result);
3422 result = FUNC(ccosh) (BUILD_COMPLEX (-9.0, nan_value));
3423 check_isnan_maybe_exc ("real(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3424 __real__ result, INVALID_EXCEPTION);
3425 check_isnan ("imag(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3426 __imag__ result);
3428 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 0.0));
3429 check_isnan ("real(ccosh(NaN + i0)) = NaN", __real__ result);
3430 check ("imag(ccosh(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3431 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_zero));
3432 check_isnan ("real(ccosh(NaN - i0)) = NaN", __real__ result);
3433 check ("imag(ccosh(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3435 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 10.0));
3436 check_isnan_maybe_exc ("real(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3437 __real__ result, INVALID_EXCEPTION);
3438 check_isnan ("imag(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3439 __imag__ result);
3440 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, -10.0));
3441 check_isnan_maybe_exc ("real(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3442 __real__ result, INVALID_EXCEPTION);
3443 check_isnan ("imag(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3444 __imag__ result);
3446 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, plus_infty));
3447 check_isnan_maybe_exc ("real(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3448 __real__ result, INVALID_EXCEPTION);
3449 check_isnan ("imag(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3450 __imag__ result);
3451 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_infty));
3452 check_isnan_maybe_exc ("real(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3453 __real__ result, INVALID_EXCEPTION);
3454 check_isnan ("imag(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3455 __imag__ result);
3457 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, nan_value));
3458 check_isnan ("real(ccosh(NaN + i NaN)) = NaN", __real__ result);
3459 check_isnan ("imag(ccosh(NaN + i NaN)) = NaN", __imag__ result);
3461 result = FUNC(ccosh) (BUILD_COMPLEX (0.7, 1.2));
3462 check_eps ("real(ccosh(0.7 + i 1.2)) == 0.45482...", __real__ result,
3463 0.4548202223691477654L, CHOOSE(5e-17L, 6e-17, 9e-8));
3464 check_eps ("imag(ccosh(0.7 + i 1.2)) == 0.70702...", __imag__ result,
3465 0.7070296600921537682L, CHOOSE(7e-17L, 2e-16, 0));
3467 result = FUNC(ccosh) (BUILD_COMPLEX (-2, -3));
3468 check_eps ("real(ccosh(-2 - i 3)) == -3.72454...", __real__ result,
3469 -3.7245455049153225654L, CHOOSE(7e-19L, 0, 3e-7));
3470 check_eps ("imag(ccosh(-2 - i 3)) == -0.51182...", __imag__ result,
3471 0.5118225699873846088L, CHOOSE(3e-19L, 2e-16, 6e-8));
3475 static void
3476 cacos_test (void)
3478 __complex__ MATHTYPE result;
3480 result = FUNC(cacos) (BUILD_COMPLEX (0, 0));
3481 check ("real(cacos(0 + i0)) = pi/2", __real__ result, M_PI_2l);
3482 check ("imag(cacos(0 + i0)) = -0", __imag__ result, minus_zero);
3483 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, 0));
3484 check ("real(cacos(-0 + i0)) = pi/2", __real__ result, M_PI_2l);
3485 check ("imag(cacos(-0 + i0)) = -0", __imag__ result, minus_zero);
3486 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_zero));
3487 check ("real(cacos(0 - i0)) = pi/2", __real__ result, M_PI_2l);
3488 check ("imag(cacos(0 - i0)) = 0", __imag__ result, 0);
3489 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, minus_zero));
3490 check ("real(cacos(-0 - i0)) = pi/2", __real__ result, M_PI_2l);
3491 check ("imag(cacos(-0 - i0)) = 0", __imag__ result, 0);
3493 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, plus_infty));
3494 check ("real(cacos(-Inf + i Inf)) = 3*pi/4", __real__ result,
3495 M_PIl - M_PI_4l);
3496 check_isinfn ("imag(cacos(-Inf + i Inf)) = -Inf", __imag__ result);
3497 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_infty));
3498 check ("real(cacos(-Inf - i Inf)) = 3*pi/4", __real__ result,
3499 M_PIl - M_PI_4l);
3500 check_isinfp ("imag(cacos(-Inf - i Inf)) = +Inf", __imag__ result);
3502 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, plus_infty));
3503 check ("real(cacos(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4l);
3504 check_isinfn ("imag(cacos(+Inf + i Inf)) = -Inf", __imag__ result);
3505 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_infty));
3506 check ("real(cacos(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4l);
3507 check_isinfp ("imag(cacos(+Inf - i Inf)) = +Inf", __imag__ result);
3509 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, plus_infty));
3510 check ("real(cacos(-10.0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3511 check_isinfn ("imag(cacos(-10.0 + i Inf)) = -Inf", __imag__ result);
3512 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, minus_infty));
3513 check ("real(cacos(-10.0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3514 check_isinfp ("imag(cacos(-10.0 - i Inf)) = +Inf", __imag__ result);
3515 result = FUNC(cacos) (BUILD_COMPLEX (0, plus_infty));
3516 check ("real(cacos(0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3517 check_isinfn ("imag(cacos(0 + i Inf)) = -Inf", __imag__ result);
3518 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_infty));
3519 check ("real(cacos(0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3520 check_isinfp ("imag(cacos(0 - i Inf)) = +Inf", __imag__ result);
3521 result = FUNC(cacos) (BUILD_COMPLEX (0.1, plus_infty));
3522 check ("real(cacos(0.1 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3523 check_isinfn ("imag(cacos(0.1 + i Inf)) = -Inf", __imag__ result);
3524 result = FUNC(cacos) (BUILD_COMPLEX (0.1, minus_infty));
3525 check ("real(cacos(0.1 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3526 check_isinfp ("imag(cacos(0.1 - i Inf)) = +Inf", __imag__ result);
3528 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 0));
3529 check ("real(cacos(-Inf + i0)) = pi", __real__ result, M_PIl);
3530 check_isinfn ("imag(cacos(-Inf + i0)) = -Inf", __imag__ result);
3531 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_zero));
3532 check ("real(cacos(-Inf - i0)) = pi", __real__ result, M_PIl);
3533 check_isinfp ("imag(cacos(-Inf - i0)) = +Inf", __imag__ result);
3534 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 100));
3535 check ("real(cacos(-Inf + i100)) = pi", __real__ result, M_PIl);
3536 check_isinfn ("imag(cacos(-Inf + i100)) = -Inf", __imag__ result);
3537 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, -100));
3538 check ("real(cacos(-Inf - i100)) = pi", __real__ result, M_PIl);
3539 check_isinfp ("imag(cacos(-Inf - i100)) = +Inf", __imag__ result);
3541 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0));
3542 check ("real(cacos(+Inf + i0)) = 0", __real__ result, 0);
3543 check_isinfn ("imag(cacos(+Inf + i0)) = -Inf", __imag__ result);
3544 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_zero));
3545 check ("real(cacos(+Inf - i0)) = 0", __real__ result, 0);
3546 check_isinfp ("imag(cacos(+Inf - i0)) = +Inf", __imag__ result);
3547 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0.5));
3548 check ("real(cacos(+Inf + i0.5)) = 0", __real__ result, 0);
3549 check_isinfn ("imag(cacos(+Inf + i0.5)) = -Inf", __imag__ result);
3550 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, -0.5));
3551 check ("real(cacos(+Inf - i0.5)) = 0", __real__ result, 0);
3552 check_isinfp ("imag(cacos(+Inf - i0.5)) = +Inf", __imag__ result);
3554 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, nan_value));
3555 check_isnan ("real(cacos(+Inf + i NaN)) = NaN", __real__ result);
3556 check_isinfp ("imag(cacos(+Inf + i NaN)) = +-Inf",
3557 FUNC(fabs) (__imag__ result));
3558 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, nan_value));
3559 check_isnan ("real(cacos(-Inf + i NaN)) = NaN", __real__ result);
3560 check_isinfp ("imag(cacos(-Inf + i NaN)) = +-Inf",
3561 FUNC(fabs) (__imag__ result));
3563 result = FUNC(cacos) (BUILD_COMPLEX (0, nan_value));
3564 check ("real(cacos(0 + i NaN)) = pi/2", __real__ result, M_PI_2l);
3565 check_isnan ("imag(cacos(0 + i NaN)) = NaN", __imag__ result);
3566 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, nan_value));
3567 check ("real(cacos(-0 + i NaN)) = pi/2", __real__ result, M_PI_2l);
3568 check_isnan ("imag(cacos(-0 + i NaN)) = NaN", __imag__ result);
3570 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, plus_infty));
3571 check_isnan ("real(cacos(NaN + i Inf)) = NaN", __real__ result);
3572 check_isinfn ("imag(cacos(NaN + i Inf)) = -Inf", __imag__ result);
3573 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, minus_infty));
3574 check_isnan ("real(cacos(NaN - i Inf)) = NaN", __real__ result);
3575 check_isinfp ("imag(cacos(NaN - i Inf)) = +Inf", __imag__ result);
3577 result = FUNC(cacos) (BUILD_COMPLEX (10.5, nan_value));
3578 check_isnan_maybe_exc ("real(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3579 __real__ result, INVALID_EXCEPTION);
3580 check_isnan ("imag(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3581 __imag__ result);
3582 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3583 check_isnan_maybe_exc ("real(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3584 __real__ result, INVALID_EXCEPTION);
3585 check_isnan ("imag(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3586 __imag__ result);
3588 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, 0.75));
3589 check_isnan_maybe_exc ("real(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3590 __real__ result, INVALID_EXCEPTION);
3591 check_isnan ("imag(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3592 __imag__ result);
3593 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3594 check_isnan_maybe_exc ("real(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3595 __real__ result, INVALID_EXCEPTION);
3596 check_isnan ("imag(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3597 __imag__ result);
3599 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, nan_value));
3600 check_isnan ("real(cacos(NaN + i NaN)) = NaN", __real__ result);
3601 check_isnan ("imag(cacos(NaN + i NaN)) = NaN", __imag__ result);
3603 result = FUNC(cacos) (BUILD_COMPLEX (0.7, 1.2));
3604 check_eps ("real(cacos(0.7 + i 1.2)) == 1.13518...", __real__ result,
3605 1.1351827477151551089L, CHOOSE(2e-17L, 3e-16, 2e-7));
3606 check_eps ("imag(cacos(0.7 + i 1.2)) == -1.09276...", __imag__ result,
3607 -1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 3e-7));
3609 result = FUNC(cacos) (BUILD_COMPLEX (-2, -3));
3610 check_eps ("real(cacos(-2 - i 3)) == 2.14144...", __real__ result,
3611 2.1414491111159960199L, CHOOSE(3e-19L, 0, 0));
3612 check_eps ("imag(cacos(-2 - i 3)) == -1.98338...", __imag__ result,
3613 1.9833870299165354323L, CHOOSE(3e-19L, 0, 0));
3617 static void
3618 cacosh_test (void)
3620 __complex__ MATHTYPE result;
3622 result = FUNC(cacosh) (BUILD_COMPLEX (0, 0));
3623 check ("real(cacosh(0 + i0)) = 0", __real__ result, 0);
3624 check ("imag(cacosh(0 + i0)) = pi/2", __imag__ result, M_PI_2l);
3625 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, 0));
3626 check ("real(cacosh(-0 + i0)) = 0", __real__ result, 0);
3627 check ("imag(cacosh(-0 + i0)) = pi/2", __imag__ result, M_PI_2l);
3628 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_zero));
3629 check ("real(cacosh(0 - i0)) = 0", __real__ result, 0);
3630 check ("imag(cacosh(0 - i0)) = -pi/2", __imag__ result, -M_PI_2l);
3631 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3632 check ("real(cacosh(-0 - i0)) = 0", __real__ result, 0);
3633 check ("imag(cacosh(-0 - i0)) = -pi/2", __imag__ result, -M_PI_2l);
3635 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3636 check_isinfp ("real(cacosh(-Inf + i Inf)) = +Inf", __real__ result);
3637 check ("imag(cacosh(-Inf + i Inf)) = 3*pi/4", __imag__ result,
3638 M_PIl - M_PI_4l);
3639 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3640 check_isinfp ("real(cacosh(-Inf - i Inf)) = +Inf", __real__ result);
3641 check ("imag(cacosh(-Inf - i Inf)) = -3*pi/4", __imag__ result,
3642 M_PI_4l - M_PIl);
3644 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3645 check_isinfp ("real(cacosh(+Inf + i Inf)) = +Inf", __real__ result);
3646 check ("imag(cacosh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3647 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3648 check_isinfp ("real(cacosh(+Inf - i Inf)) = +Inf", __real__ result);
3649 check ("imag(cacosh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3651 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, plus_infty));
3652 check_isinfp ("real(cacosh(-10.0 + i Inf)) = +Inf", __real__ result);
3653 check ("imag(cacosh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3654 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, minus_infty));
3655 check_isinfp ("real(cacosh(-10.0 - i Inf)) = +Inf", __real__ result);
3656 check ("imag(cacosh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3657 result = FUNC(cacosh) (BUILD_COMPLEX (0, plus_infty));
3658 check_isinfp ("real(cacosh(0 + i Inf)) = +Inf", __real__ result);
3659 check ("imag(cacosh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3660 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_infty));
3661 check_isinfp ("real(cacosh(0 - i Inf)) = +Inf", __real__ result);
3662 check ("imag(cacosh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3663 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, plus_infty));
3664 check_isinfp ("real(cacosh(0.1 + i Inf)) = +Inf", __real__ result);
3665 check ("imag(cacosh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3666 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, minus_infty));
3667 check_isinfp ("real(cacosh(0.1 - i Inf)) = +Inf", __real__ result);
3668 check ("imag(cacosh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3670 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 0));
3671 check_isinfp ("real(cacosh(-Inf + i0)) = +Inf", __real__ result);
3672 check ("imag(cacosh(-Inf + i0)) = pi", __imag__ result, M_PIl);
3673 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3674 check_isinfp ("real(cacosh(-Inf - i0)) = +Inf", __real__ result);
3675 check ("imag(cacosh(-Inf - i0)) = -pi", __imag__ result, -M_PIl);
3676 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 100));
3677 check_isinfp ("real(cacosh(-Inf + i100)) = +Inf", __real__ result);
3678 check ("imag(cacosh(-Inf + i100)) = pi", __imag__ result, M_PIl);
3679 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, -100));
3680 check_isinfp ("real(cacosh(-Inf - i100)) = +Inf", __real__ result);
3681 check ("imag(cacosh(-Inf - i100)) = -pi", __imag__ result, -M_PIl);
3683 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0));
3684 check_isinfp ("real(cacosh(+Inf + i0)) = +Inf", __real__ result);
3685 check ("imag(cacosh(+Inf + i0)) = 0", __imag__ result, 0);
3686 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3687 check_isinfp ("real(cacosh(+Inf - i0)) = +Inf", __real__ result);
3688 check ("imag(cacosh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3689 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0.5));
3690 check_isinfp ("real(cacosh(+Inf + i0.5)) = +Inf", __real__ result);
3691 check ("imag(cacosh(+Inf + i0.5)) = 0", __imag__ result, 0);
3692 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, -0.5));
3693 check_isinfp ("real(cacosh(+Inf - i0.5)) = +Inf", __real__ result);
3694 check ("imag(cacosh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3696 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, nan_value));
3697 check_isinfp ("real(cacosh(+Inf + i NaN)) = +Inf", __real__ result);
3698 check_isnan ("imag(cacosh(+Inf + i NaN)) = NaN", __imag__ result);
3699 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, nan_value));
3700 check_isinfp ("real(cacosh(-Inf + i NaN)) = +Inf", __real__ result);
3701 check_isnan ("imag(cacosh(-Inf + i NaN)) = NaN", __imag__ result);
3703 result = FUNC(cacosh) (BUILD_COMPLEX (0, nan_value));
3704 check_isnan ("real(cacosh(0 + i NaN)) = NaN", __real__ result);
3705 check_isnan ("imag(cacosh(0 + i NaN)) = NaN", __imag__ result);
3706 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, nan_value));
3707 check_isnan ("real(cacosh(-0 + i NaN)) = NaN", __real__ result);
3708 check_isnan ("imag(cacosh(-0 + i NaN)) = NaN", __imag__ result);
3710 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, plus_infty));
3711 check_isinfp ("real(cacosh(NaN + i Inf)) = +Inf", __real__ result);
3712 check_isnan ("imag(cacosh(NaN + i Inf)) = NaN", __imag__ result);
3713 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, minus_infty));
3714 check_isinfp ("real(cacosh(NaN - i Inf)) = +Inf", __real__ result);
3715 check_isnan ("imag(cacosh(NaN - i Inf)) = NaN", __imag__ result);
3717 result = FUNC(cacosh) (BUILD_COMPLEX (10.5, nan_value));
3718 check_isnan_maybe_exc ("real(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3719 __real__ result, INVALID_EXCEPTION);
3720 check_isnan ("imag(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3721 __imag__ result);
3722 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3723 check_isnan_maybe_exc ("real(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3724 __real__ result, INVALID_EXCEPTION);
3725 check_isnan ("imag(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3726 __imag__ result);
3728 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, 0.75));
3729 check_isnan_maybe_exc ("real(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3730 __real__ result, INVALID_EXCEPTION);
3731 check_isnan ("imag(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3732 __imag__ result);
3733 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3734 check_isnan_maybe_exc ("real(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3735 __real__ result, INVALID_EXCEPTION);
3736 check_isnan ("imag(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3737 __imag__ result);
3739 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, nan_value));
3740 check_isnan ("real(cacosh(NaN + i NaN)) = NaN", __real__ result);
3741 check_isnan ("imag(cacosh(NaN + i NaN)) = NaN", __imag__ result);
3743 result = FUNC(cacosh) (BUILD_COMPLEX (0.7, 1.2));
3744 check_eps ("real(cacosh(0.7 + i 1.2)) == 1.09276...", __real__ result,
3745 1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 2e-7));
3746 check_eps ("imag(cacosh(0.7 + i 1.2)) == 1.13518...", __imag__ result,
3747 1.1351827477151551089L, CHOOSE(2e-17L, 0, 0));
3749 result = FUNC(cacosh) (BUILD_COMPLEX (-2, -3));
3750 check_eps ("real(cacosh(-2 - i 3)) == -1.98338...", __real__ result,
3751 -1.9833870299165354323L, CHOOSE (2e-18L, 3e-16, 9e-7));
3752 check_eps ("imag(cacosh(-2 - i 3)) == 2.14144...", __imag__ result,
3753 2.1414491111159960199L, CHOOSE (3e-19, 5e-16, 1e-6));
3757 static void
3758 casin_test (void)
3760 __complex__ MATHTYPE result;
3762 result = FUNC(casin) (BUILD_COMPLEX (0, 0));
3763 check ("real(casin(0 + i0)) = 0", __real__ result, 0);
3764 check ("imag(casin(0 + i0)) = 0", __imag__ result, 0);
3765 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, 0));
3766 check ("real(casin(-0 + i0)) = -0", __real__ result, minus_zero);
3767 check ("imag(casin(-0 + i0)) = 0", __imag__ result, 0);
3768 result = FUNC(casin) (BUILD_COMPLEX (0, minus_zero));
3769 check ("real(casin(0 - i0)) = 0", __real__ result, 0);
3770 check ("imag(casin(0 - i0)) = -0", __imag__ result, minus_zero);
3771 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_zero));
3772 check ("real(casin(-0 - i0)) = -0", __real__ result, minus_zero);
3773 check ("imag(casin(-0 - i0)) = -0", __imag__ result, minus_zero);
3775 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, plus_infty));
3776 check ("real(casin(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4l);
3777 check_isinfp ("imag(casin(+Inf + i Inf)) = +Inf", __imag__ result);
3778 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_infty));
3779 check ("real(casin(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4l);
3780 check_isinfn ("imag(casin(+Inf - i Inf)) = -Inf", __imag__ result);
3781 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, plus_infty));
3782 check ("real(casin(-Inf + i Inf)) = -pi/4", __real__ result, -M_PI_4l);
3783 check_isinfp ("imag(casin(-Inf + i Inf)) = +Inf", __imag__ result);
3784 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_infty));
3785 check ("real(casin(-Inf - i Inf)) = -pi/4", __real__ result, -M_PI_4l);
3786 check_isinfn ("imag(casin(-Inf - i Inf)) = -Inf", __imag__ result);
3788 result = FUNC(casin) (BUILD_COMPLEX (-10.0, plus_infty));
3789 check ("real(casin(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
3790 check_isinfp ("imag(casin(-10.0 + i Inf)) = +Inf", __imag__ result);
3791 result = FUNC(casin) (BUILD_COMPLEX (-10.0, minus_infty));
3792 check ("real(casin(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
3793 check_isinfn ("imag(casin(-10.0 - i Inf)) = -Inf", __imag__ result);
3794 result = FUNC(casin) (BUILD_COMPLEX (0, plus_infty));
3795 check ("real(casin(0 + i Inf)) = 0", __real__ result, 0.0);
3796 check_isinfp ("imag(casin(0 + i Inf)) = +Inf", __imag__ result);
3797 result = FUNC(casin) (BUILD_COMPLEX (0, minus_infty));
3798 check ("real(casin(0 - i Inf)) = 0", __real__ result, 0.0);
3799 check_isinfn ("imag(casin(0 - i Inf)) = -Inf", __imag__ result);
3800 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, plus_infty));
3801 check ("real(casin(-0 + i Inf)) = -0", __real__ result, minus_zero);
3802 check_isinfp ("imag(casin(-0 + i Inf)) = +Inf", __imag__ result);
3803 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_infty));
3804 check ("real(casin(-0 - i Inf)) = -0", __real__ result, minus_zero);
3805 check_isinfn ("imag(casin(-0 - i Inf)) = -Inf", __imag__ result);
3806 result = FUNC(casin) (BUILD_COMPLEX (0.1, plus_infty));
3807 check ("real(casin(0.1 + i Inf)) = 0", __real__ result, 0);
3808 check_isinfp ("imag(casin(0.1 + i Inf)) = +Inf", __imag__ result);
3809 result = FUNC(casin) (BUILD_COMPLEX (0.1, minus_infty));
3810 check ("real(casin(0.1 - i Inf)) = 0", __real__ result, 0);
3811 check_isinfn ("imag(casin(0.1 - i Inf)) = -Inf", __imag__ result);
3813 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 0));
3814 check ("real(casin(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2l);
3815 check_isinfp ("imag(casin(-Inf + i0)) = +Inf", __imag__ result);
3816 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_zero));
3817 check ("real(casin(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2l);
3818 check_isinfn ("imag(casin(-Inf - i0)) = -Inf", __imag__ result);
3819 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 100));
3820 check ("real(casin(-Inf + i100)) = -pi/2", __real__ result, -M_PI_2l);
3821 check_isinfp ("imag(casin(-Inf + i100)) = +Inf", __imag__ result);
3822 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, -100));
3823 check ("real(casin(-Inf - i100)) = -pi/2", __real__ result, -M_PI_2l);
3824 check_isinfn ("imag(casin(-Inf - i100)) = -Inf", __imag__ result);
3826 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0));
3827 check ("real(casin(+Inf + i0)) = pi/2", __real__ result, M_PI_2l);
3828 check_isinfp ("imag(casin(+Inf + i0)) = +Inf", __imag__ result);
3829 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_zero));
3830 check ("real(casin(+Inf - i0)) = pi/2", __real__ result, M_PI_2l);
3831 check_isinfn ("imag(casin(+Inf - i0)) = -Inf", __imag__ result);
3832 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0.5));
3833 check ("real(casin(+Inf + i0.5)) = pi/2", __real__ result, M_PI_2l);
3834 check_isinfp ("imag(casin(+Inf + i0.5)) = +Inf", __imag__ result);
3835 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, -0.5));
3836 check ("real(casin(+Inf - i0.5)) = pi/2", __real__ result, M_PI_2l);
3837 check_isinfn ("imag(casin(+Inf - i0.5)) = -Inf", __imag__ result);
3839 result = FUNC(casin) (BUILD_COMPLEX (nan_value, plus_infty));
3840 check_isnan ("real(casin(NaN + i Inf)) = NaN", __real__ result);
3841 check_isinfp ("imag(casin(NaN + i Inf)) = +Inf", __imag__ result);
3842 result = FUNC(casin) (BUILD_COMPLEX (nan_value, minus_infty));
3843 check_isnan ("real(casin(NaN - i Inf)) = NaN", __real__ result);
3844 check_isinfn ("imag(casin(NaN - i Inf)) = -Inf", __imag__ result);
3846 result = FUNC(casin) (BUILD_COMPLEX (0.0, nan_value));
3847 check ("real(casin(0 + i NaN)) = 0", __real__ result, 0.0);
3848 check_isnan ("imag(casin(0 + i NaN)) = NaN", __imag__ result);
3849 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, nan_value));
3850 check ("real(casin(-0 + i NaN)) = -0", __real__ result, minus_zero);
3851 check_isnan ("imag(casin(-0 + i NaN)) = NaN", __imag__ result);
3853 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, nan_value));
3854 check_isnan ("real(casin(+Inf + i NaN)) = NaN", __real__ result);
3855 check_isinfp ("imag(casin(+Inf + i NaN)) = +-Inf",
3856 FUNC(fabs) (__imag__ result));
3857 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, nan_value));
3858 check_isnan ("real(casin(-Inf + i NaN)) = NaN", __real__ result);
3859 check_isinfp ("imag(casin(-Inf + NaN)) = +-Inf",
3860 FUNC(fabs) (__imag__ result));
3862 result = FUNC(casin) (BUILD_COMPLEX (nan_value, 10.5));
3863 check_isnan_maybe_exc ("real(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3864 __real__ result, INVALID_EXCEPTION);
3865 check_isnan ("imag(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3866 __imag__ result);
3867 result = FUNC(casin) (BUILD_COMPLEX (nan_value, -10.5));
3868 check_isnan_maybe_exc ("real(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3869 __real__ result, INVALID_EXCEPTION);
3870 check_isnan ("imag(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3871 __imag__ result);
3873 result = FUNC(casin) (BUILD_COMPLEX (0.75, nan_value));
3874 check_isnan_maybe_exc ("real(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3875 __real__ result, INVALID_EXCEPTION);
3876 check_isnan ("imag(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3877 __imag__ result);
3878 result = FUNC(casin) (BUILD_COMPLEX (-0.75, nan_value));
3879 check_isnan_maybe_exc ("real(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3880 __real__ result, INVALID_EXCEPTION);
3881 check_isnan ("imag(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3882 __imag__ result);
3884 result = FUNC(casin) (BUILD_COMPLEX (nan_value, nan_value));
3885 check_isnan ("real(casin(NaN + i NaN)) = NaN", __real__ result);
3886 check_isnan ("imag(casin(NaN + i NaN)) = NaN", __imag__ result);
3888 result = FUNC(casin) (BUILD_COMPLEX (0.7, 1.2));
3889 check_eps ("real(casin(0.7 + i 1.2)) == 0.43561...", __real__ result,
3890 0.4356135790797415103L, CHOOSE(2e-17L, 2e-16, 2e-7));
3891 check_eps ("imag(casin(0.7 + i 1.2)) == 1.09276...", __imag__ result,
3892 1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 3e-7));
3894 result = FUNC(casin) (BUILD_COMPLEX (-2, -3));
3895 check_eps ("real(casin(-2 - i 3)) == -0.57065...", __real__ result,
3896 -0.5706527843210994007L, CHOOSE(4e-19L, 0, 0));
3897 check_eps ("imag(casin(-2 - i 3)) == -1.98338...", __imag__ result,
3898 -1.9833870299165354323L, CHOOSE(3e-19L, 0, 0));
3902 static void
3903 casinh_test (void)
3905 __complex__ MATHTYPE result;
3907 result = FUNC(casinh) (BUILD_COMPLEX (0, 0));
3908 check ("real(casinh(0 + i0)) = 0", __real__ result, 0);
3909 check ("imag(casinh(0 + i0)) = 0", __imag__ result, 0);
3910 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, 0));
3911 check ("real(casinh(-0 + i0)) = -0", __real__ result, minus_zero);
3912 check ("imag(casinh(-0 + i0)) = 0", __imag__ result, 0);
3913 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_zero));
3914 check ("real(casinh(0 - i0)) = 0", __real__ result, 0);
3915 check ("imag(casinh(0 - i0)) = -0", __imag__ result, minus_zero);
3916 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_zero));
3917 check ("real(casinh(-0 - i0)) = -0", __real__ result, minus_zero);
3918 check ("imag(casinh(-0 - i0)) = -0", __imag__ result, minus_zero);
3920 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, plus_infty));
3921 check_isinfp ("real(casinh(+Inf + i Inf)) = +Inf", __real__ result);
3922 check ("imag(casinh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3923 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_infty));
3924 check_isinfp ("real(casinh(+Inf - i Inf)) = +Inf", __real__ result);
3925 check ("imag(casinh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3926 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, plus_infty));
3927 check_isinfn ("real(casinh(-Inf + i Inf)) = -Inf", __real__ result);
3928 check ("imag(casinh(-Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3929 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_infty));
3930 check_isinfn ("real(casinh(-Inf - i Inf)) = -Inf", __real__ result);
3931 check ("imag(casinh(-Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3933 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, plus_infty));
3934 check_isinfn ("real(casinh(-10.0 + i Inf)) = -Inf", __real__ result);
3935 check ("imag(casinh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3936 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, minus_infty));
3937 check_isinfn ("real(casinh(-10.0 - i Inf)) = -Inf", __real__ result);
3938 check ("imag(casinh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3939 result = FUNC(casinh) (BUILD_COMPLEX (0, plus_infty));
3940 check_isinfp ("real(casinh(0 + i Inf)) = +Inf", __real__ result);
3941 check ("imag(casinh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3942 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_infty));
3943 check_isinfp ("real(casinh(0 - i Inf)) = +Inf", __real__ result);
3944 check ("imag(casinh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3945 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, plus_infty));
3946 check_isinfn ("real(casinh(-0 + i Inf)) = -Inf", __real__ result);
3947 check ("imag(casinh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3948 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_infty));
3949 check_isinfn ("real(casinh(-0 - i Inf)) = -Inf", __real__ result);
3950 check ("imag(casinh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3951 result = FUNC(casinh) (BUILD_COMPLEX (0.1, plus_infty));
3952 check_isinfp ("real(casinh(0.1 + i Inf)) = +Inf", __real__ result);
3953 check ("imag(casinh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3954 result = FUNC(casinh) (BUILD_COMPLEX (0.1, minus_infty));
3955 check_isinfp ("real(casinh(0.1 - i Inf)) = +Inf", __real__ result);
3956 check ("imag(casinh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3958 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 0));
3959 check_isinfn ("real(casinh(-Inf + i0)) = -Inf", __real__ result);
3960 check ("imag(casinh(-Inf + i0)) = 0", __imag__ result, 0);
3961 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_zero));
3962 check_isinfn ("real(casinh(-Inf - i0)) = -Inf", __real__ result);
3963 check ("imag(casinh(-Inf - i0)) = -0", __imag__ result, minus_zero);
3964 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 100));
3965 check_isinfn ("real(casinh(-Inf + i100)) = -Inf", __real__ result);
3966 check ("imag(casinh(-Inf + i100)) = 0", __imag__ result, 0);
3967 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, -100));
3968 check_isinfn ("real(casinh(-Inf - i100)) = -Inf", __real__ result);
3969 check ("imag(casinh(-Inf - i100)) = -0", __imag__ result, minus_zero);
3971 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0));
3972 check_isinfp ("real(casinh(+Inf + i0)) = +Inf", __real__ result);
3973 check ("imag(casinh(+Inf + i0)) = 0", __imag__ result, 0);
3974 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_zero));
3975 check_isinfp ("real(casinh(+Inf - i0)) = +Inf", __real__ result);
3976 check ("imag(casinh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3977 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0.5));
3978 check_isinfp ("real(casinh(+Inf + i0.5)) = +Inf", __real__ result);
3979 check ("imag(casinh(+Inf + i0.5)) = 0", __imag__ result, 0);
3980 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, -0.5));
3981 check_isinfp ("real(casinh(+Inf - i0.5)) = +Inf", __real__ result);
3982 check ("imag(casinh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3984 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, nan_value));
3985 check_isinfp ("real(casinh(+Inf + i NaN)) = +Inf", __real__ result);
3986 check_isnan ("imag(casinh(+Inf + i NaN)) = NaN", __imag__ result);
3987 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, nan_value));
3988 check_isinfn ("real(casinh(-Inf + i NaN)) = -Inf", __real__ result);
3989 check_isnan ("imag(casinh(-Inf + i NaN)) = NaN", __imag__ result);
3991 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0));
3992 check_isnan ("real(casinh(NaN + i0)) = NaN", __real__ result);
3993 check ("imag(casinh(NaN + i0)) = 0", __imag__ result, 0);
3994 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_zero));
3995 check_isnan ("real(casinh(NaN - i0)) = NaN", __real__ result);
3996 check ("imag(casinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3998 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, plus_infty));
3999 check_isinfp ("real(casinh(NaN + i Inf)) = +-Inf",
4000 FUNC(fabs) (__real__ result));
4001 check_isnan ("imag(casinh(NaN + i Inf)) = NaN", __imag__ result);
4002 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_infty));
4003 check_isinfp ("real(casinh(NaN - i Inf)) = +-Inf",
4004 FUNC(fabs) (__real__ result));
4005 check_isnan ("imag(casinh(NaN - i Inf)) = NaN", __imag__ result);
4007 result = FUNC(casinh) (BUILD_COMPLEX (10.5, nan_value));
4008 check_isnan_maybe_exc ("real(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4009 __real__ result, INVALID_EXCEPTION);
4010 check_isnan ("imag(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4011 __imag__ result);
4012 result = FUNC(casinh) (BUILD_COMPLEX (-10.5, nan_value));
4013 check_isnan_maybe_exc ("real(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4014 __real__ result, INVALID_EXCEPTION);
4015 check_isnan ("imag(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4016 __imag__ result);
4018 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0.75));
4019 check_isnan_maybe_exc ("real(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
4020 __real__ result, INVALID_EXCEPTION);
4021 check_isnan ("imag(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
4022 __imag__ result);
4023 result = FUNC(casinh) (BUILD_COMPLEX (-0.75, nan_value));
4024 check_isnan_maybe_exc ("real(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
4025 __real__ result, INVALID_EXCEPTION);
4026 check_isnan ("imag(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
4027 __imag__ result);
4029 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, nan_value));
4030 check_isnan ("real(casinh(NaN + i NaN)) = NaN", __real__ result);
4031 check_isnan ("imag(casinh(NaN + i NaN)) = NaN", __imag__ result);
4033 result = FUNC(casinh) (BUILD_COMPLEX (0.7, 1.2));
4034 check_eps ("real(casinh(0.7 + i 1.2)) == 0.97865...", __real__ result,
4035 0.9786545955936738768L, CHOOSE(5e-17L, 2e-16, 0));
4036 check_eps ("imag(casinh(0.7 + i 1.2)) == 0.91135...", __imag__ result,
4037 0.9113541895315601156L, CHOOSE(7e-19L, 2e-16, 6e-8));
4039 result = FUNC(casinh) (BUILD_COMPLEX (-2, -3));
4040 check_eps ("real(casinh(-2 - i 3)) == -1.96863...", __real__ result,
4041 -1.9686379257930962917L, CHOOSE(7e-19L, 2e-15, 2e-7));
4042 check_eps ("imag(casinh(-2 - i 3)) == -0.96465...", __imag__ result,
4043 -0.9646585044076027920L, CHOOSE(4e-19L, 2e-15, 4e-7));
4047 static void
4048 catan_test (void)
4050 __complex__ MATHTYPE result;
4052 result = FUNC(catan) (BUILD_COMPLEX (0, 0));
4053 check ("real(catan(0 + i0)) = 0", __real__ result, 0);
4054 check ("imag(catan(0 + i0)) = 0", __imag__ result, 0);
4055 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, 0));
4056 check ("real(catan(-0 + i0)) = -0", __real__ result, minus_zero);
4057 check ("imag(catan(-0 + i0)) = 0", __imag__ result, 0);
4058 result = FUNC(catan) (BUILD_COMPLEX (0, minus_zero));
4059 check ("real(catan(0 - i0)) = 0", __real__ result, 0);
4060 check ("imag(catan(0 - i0)) = -0", __imag__ result, minus_zero);
4061 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_zero));
4062 check ("real(catan(-0 - i0)) = -0", __real__ result, minus_zero);
4063 check ("imag(catan(-0 - i0)) = -0", __imag__ result, minus_zero);
4065 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, plus_infty));
4066 check ("real(catan(+Inf + i Inf)) = pi/2", __real__ result, M_PI_2l);
4067 check ("imag(catan(+Inf + i Inf)) = 0", __imag__ result, 0);
4068 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_infty));
4069 check ("real(catan(+Inf - i Inf)) = pi/2", __real__ result, M_PI_2l);
4070 check ("imag(catan(+Inf - i Inf)) = -0", __imag__ result, minus_zero);
4071 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, plus_infty));
4072 check ("real(catan(-Inf + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4073 check ("imag(catan(-Inf + i Inf)) = 0", __imag__ result, 0.0);
4074 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_infty));
4075 check ("real(catan(-Inf - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4076 check ("imag(catan(-Inf - i Inf)) = -0", __imag__ result, minus_zero);
4078 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, -10.0));
4079 check ("real(catan(+Inf - i10.0)) = pi/2", __real__ result, M_PI_2l);
4080 check ("imag(catan(+Inf - i10.0)) = -0", __imag__ result, minus_zero);
4081 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, -10.0));
4082 check ("real(catan(-Inf - i10.0)) = -pi/2", __real__ result, -M_PI_2l);
4083 check ("imag(catan(-Inf - i10.0)) = -0", __imag__ result, minus_zero);
4084 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_zero));
4085 check ("real(catan(Inf - i0)) = pi/2", __real__ result, M_PI_2l);
4086 check ("imag(catan(Inf - i0)) = -0", __imag__ result, minus_zero);
4087 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_zero));
4088 check ("real(catan(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2l);
4089 check ("imag(catan(-Inf - i0)) = -0", __imag__ result, minus_zero);
4090 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.0));
4091 check ("real(catan(Inf + i0)) = pi/2", __real__ result, M_PI_2l);
4092 check ("imag(catan(Inf + i0)) = 0", __imag__ result, 0.0);
4093 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.0));
4094 check ("real(catan(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2l);
4095 check ("imag(catan(-Inf + i0)) = 0", __imag__ result, 0.0);
4096 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.1));
4097 check ("real(catan(+Inf + i0.1)) = pi/2", __real__ result, M_PI_2l);
4098 check ("imag(catan(+Inf + i0.1)) = 0", __imag__ result, 0);
4099 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.1));
4100 check ("real(catan(-Inf + i0.1)) = -pi/2", __real__ result, -M_PI_2l);
4101 check ("imag(catan(-Inf + i0.1)) = 0", __imag__ result, 0);
4103 result = FUNC(catan) (BUILD_COMPLEX (0.0, minus_infty));
4104 check ("real(catan(0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
4105 check ("imag(catan(0 - i Inf)) = -0", __imag__ result, minus_zero);
4106 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_infty));
4107 check ("real(catan(-0 - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4108 check ("imag(catan(-0 - i Inf)) = -0", __imag__ result, minus_zero);
4109 result = FUNC(catan) (BUILD_COMPLEX (100.0, minus_infty));
4110 check ("real(catan(100 - i Inf)) = pi/2", __real__ result, M_PI_2l);
4111 check ("imag(catan(100 - i Inf)) = -0", __imag__ result, minus_zero);
4112 result = FUNC(catan) (BUILD_COMPLEX (-100.0, minus_infty));
4113 check ("real(catan(-100 - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4114 check ("imag(catan(-100 - i Inf)) = -0", __imag__ result, minus_zero);
4116 result = FUNC(catan) (BUILD_COMPLEX (0.0, plus_infty));
4117 check ("real(catan(0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
4118 check ("imag(catan(0 + i Inf)) = 0", __imag__ result, 0);
4119 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, plus_infty));
4120 check ("real(catan(-0 + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4121 check ("imag(catan(-0 + i Inf)) = 0", __imag__ result, 0);
4122 result = FUNC(catan) (BUILD_COMPLEX (0.5, plus_infty));
4123 check ("real(catan(0.5 + i Inf)) = pi/2", __real__ result, M_PI_2l);
4124 check ("imag(catan(0.5 + i Inf)) = 0", __imag__ result, 0);
4125 result = FUNC(catan) (BUILD_COMPLEX (-0.5, plus_infty));
4126 check ("real(catan(-0.5 + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4127 check ("imag(catan(-0.5 + i Inf)) = 0", __imag__ result, 0);
4129 result = FUNC(catan) (BUILD_COMPLEX (nan_value, 0.0));
4130 check_isnan ("real(catan(NaN + i0)) = NaN", __real__ result);
4131 check ("imag(catan(NaN + i0)) = 0", __imag__ result, 0.0);
4132 result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_zero));
4133 check_isnan ("real(catan(NaN - i0)) = NaN", __real__ result);
4134 check ("imag(catan(NaN - i0)) = -0", __imag__ result, minus_zero);
4136 result = FUNC(catan) (BUILD_COMPLEX (nan_value, plus_infty));
4137 check_isnan ("real(catan(NaN + i Inf)) = NaN", __real__ result);
4138 check ("imag(catan(NaN + i Inf)) = 0", __imag__ result, 0);
4139 result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_infty));
4140 check_isnan ("real(catan(NaN - i Inf)) = NaN", __real__ result);
4141 check ("imag(catan(NaN - i Inf)) = -0", __imag__ result, minus_zero);
4143 result = FUNC(catan) (BUILD_COMPLEX (0.0, nan_value));
4144 check_isnan ("real(catan(0 + i NaN)) = NaN", __real__ result);
4145 check_isnan ("imag(catan(0 + i NaN)) = NaN", __imag__ result);
4146 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, nan_value));
4147 check_isnan ("real(catan(-0 + i NaN)) = NaN", __real__ result);
4148 check_isnan ("imag(catan(-0 + i NaN)) = NaN", __imag__ result);
4150 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, nan_value));
4151 check ("real(catan(+Inf + i NaN)) = pi/2", __real__ result, M_PI_2l);
4152 check ("imag(catan(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4153 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, nan_value));
4154 check ("real(catan(-Inf + i NaN)) = -pi/2", __real__ result, -M_PI_2l);
4155 check ("imag(catan(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4157 result = FUNC(catan) (BUILD_COMPLEX (nan_value, 10.5));
4158 check_isnan_maybe_exc ("real(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
4159 __real__ result, INVALID_EXCEPTION);
4160 check_isnan ("imag(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
4161 __imag__ result);
4162 result = FUNC(catan) (BUILD_COMPLEX (nan_value, -10.5));
4163 check_isnan_maybe_exc ("real(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
4164 __real__ result, INVALID_EXCEPTION);
4165 check_isnan ("imag(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
4166 __imag__ result);
4168 result = FUNC(catan) (BUILD_COMPLEX (0.75, nan_value));
4169 check_isnan_maybe_exc ("real(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
4170 __real__ result, INVALID_EXCEPTION);
4171 check_isnan ("imag(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
4172 __imag__ result);
4173 result = FUNC(catan) (BUILD_COMPLEX (-0.75, nan_value));
4174 check_isnan_maybe_exc ("real(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
4175 __real__ result, INVALID_EXCEPTION);
4176 check_isnan ("imag(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
4177 __imag__ result);
4179 result = FUNC(catan) (BUILD_COMPLEX (nan_value, nan_value));
4180 check_isnan ("real(catan(NaN + i NaN)) = NaN", __real__ result);
4181 check_isnan ("imag(catan(NaN + i NaN)) = NaN", __imag__ result);
4183 result = FUNC(catan) (BUILD_COMPLEX (0.7, 1.2));
4184 check_eps ("real(catan(0.7 + i 1.2)) == 1.07857...", __real__ result,
4185 1.0785743834118921877L, CHOOSE (3e-17, 0, 5e-7));
4186 check_eps ("imag(catan(0.7 + i 1.2)) == 0.57705...", __imag__ result,
4187 0.5770573776534306764L, CHOOSE(3e-17L, 2e-16, 6e-8));
4189 result = FUNC(catan) (BUILD_COMPLEX (-2, -3));
4190 check_eps ("real(catan(-2 - i 3)) == -1.40992...", __real__ result,
4191 -1.4099210495965755225L, CHOOSE(0, 0, 4e-7));
4192 check_eps ("imag(catan(-2 - i 3)) == -0.22907...", __imag__ result,
4193 -0.2290726829685387662L, CHOOSE(1.1e-19L, 3e-17, 2e-8));
4197 static void
4198 catanh_test (void)
4200 __complex__ MATHTYPE result;
4202 result = FUNC(catanh) (BUILD_COMPLEX (0, 0));
4203 check ("real(catanh(0 + i0)) = 0", __real__ result, 0);
4204 check ("imag(catanh(0 + i0)) = 0", __imag__ result, 0);
4205 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, 0));
4206 check ("real(catanh(-0 + i0)) = -0", __real__ result, minus_zero);
4207 check ("imag(catanh(-0 + i0)) = 0", __imag__ result, 0);
4208 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_zero));
4209 check ("real(catanh(0 - i0)) = 0", __real__ result, 0);
4210 check ("imag(catanh(0 - i0)) = -0", __imag__ result, minus_zero);
4211 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4212 check ("real(catanh(-0 - i0)) = -0", __real__ result, minus_zero);
4213 check ("imag(catanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4215 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, plus_infty));
4216 check ("real(catanh(+Inf + i Inf)) = 0", __real__ result, 0);
4217 check ("imag(catanh(+Inf + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4218 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_infty));
4219 check ("real(catanh(+Inf - i Inf)) = 0", __real__ result, 0);
4220 check ("imag(catanh(+Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4221 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, plus_infty));
4222 check ("real(catanh(-Inf + i Inf)) = -0", __real__ result, minus_zero);
4223 check ("imag(catanh(-Inf + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4224 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_infty));
4225 check ("real(catanh(-Inf - i Inf)) = -0", __real__ result, minus_zero);
4226 check ("imag(catanh(-Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4228 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, plus_infty));
4229 check ("real(catanh(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
4230 check ("imag(catanh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4231 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, minus_infty));
4232 check ("real(catanh(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
4233 check ("imag(catanh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4234 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4235 check ("real(catanh(-0 + i Inf)) = -0", __real__ result, minus_zero);
4236 check ("imag(catanh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4237 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4238 check ("real(catanh(-0 - i Inf)) = -0", __real__ result, minus_zero);
4239 check ("imag(catanh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4240 result = FUNC(catanh) (BUILD_COMPLEX (0, plus_infty));
4241 check ("real(catanh(0 + i Inf)) = 0", __real__ result, 0);
4242 check ("imag(catanh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4243 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_infty));
4244 check ("real(catanh(0 - i Inf)) = 0", __real__ result, 0);
4245 check ("imag(catanh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4246 result = FUNC(catanh) (BUILD_COMPLEX (0.1, plus_infty));
4247 check ("real(catanh(0.1 + i Inf)) = 0", __real__ result, 0);
4248 check ("imag(catanh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4249 result = FUNC(catanh) (BUILD_COMPLEX (0.1, minus_infty));
4250 check ("real(catanh(0.1 - i Inf)) = 0", __real__ result, 0);
4251 check ("imag(catanh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4253 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 0));
4254 check ("real(catanh(-Inf + i0)) = -0", __real__ result, minus_zero);
4255 check ("imag(catanh(-Inf + i0)) = pi/2", __imag__ result, M_PI_2l);
4256 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4257 check ("real(catanh(-Inf - i0)) = -0", __real__ result, minus_zero);
4258 check ("imag(catanh(-Inf - i0)) = -pi/2", __imag__ result, -M_PI_2l);
4259 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 100));
4260 check ("real(catanh(-Inf + i100)) = -0", __real__ result, minus_zero);
4261 check ("imag(catanh(-Inf + i100)) = pi/2", __imag__ result, M_PI_2l);
4262 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, -100));
4263 check ("real(catanh(-Inf - i100)) = -0", __real__ result, minus_zero);
4264 check ("imag(catanh(-Inf - i100)) = -pi/2", __imag__ result, -M_PI_2l);
4266 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0));
4267 check ("real(catanh(+Inf + i0)) = 0", __real__ result, 0);
4268 check ("imag(catanh(+Inf + i0)) = pi/2", __imag__ result, M_PI_2l);
4269 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4270 check ("real(catanh(+Inf - i0)) = 0", __real__ result, 0);
4271 check ("imag(catanh(+Inf - i0)) = -pi/2", __imag__ result, -M_PI_2l);
4272 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0.5));
4273 check ("real(catanh(+Inf + i0.5)) = 0", __real__ result, 0);
4274 check ("imag(catanh(+Inf + i0.5)) = pi/2", __imag__ result, M_PI_2l);
4275 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, -0.5));
4276 check ("real(catanh(+Inf - i0.5)) = 0", __real__ result, 0);
4277 check ("imag(catanh(+Inf - i0.5)) = -pi/2", __imag__ result, -M_PI_2l);
4279 result = FUNC(catanh) (BUILD_COMPLEX (0, nan_value));
4280 check ("real(catanh(0 + i NaN)) = 0", __real__ result, 0);
4281 check_isnan ("imag(catanh(0 + i NaN)) = NaN", __imag__ result);
4282 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, nan_value));
4283 check ("real(catanh(-0 + i NaN)) = -0", __real__ result, minus_zero);
4284 check_isnan ("imag(catanh(-0 + i NaN)) = NaN", __imag__ result);
4286 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, nan_value));
4287 check ("real(catanh(+Inf + i NaN)) = 0", __real__ result, 0);
4288 check_isnan ("imag(catanh(+Inf + i NaN)) = NaN", __imag__ result);
4289 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, nan_value));
4290 check ("real(catanh(-Inf + i NaN)) = -0", __real__ result, minus_zero);
4291 check_isnan ("imag(catanh(-Inf + i NaN)) = NaN", __imag__ result);
4293 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0));
4294 check_isnan ("real(catanh(NaN + i0)) = NaN", __real__ result);
4295 check_isnan ("imag(catanh(NaN + i0)) = NaN", __imag__ result);
4296 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_zero));
4297 check_isnan ("real(catanh(NaN - i0)) = NaN", __real__ result);
4298 check_isnan ("imag(catanh(NaN - i0)) = NaN", __imag__ result);
4300 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, plus_infty));
4301 check ("real(catanh(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4302 check ("imag(catanh(NaN + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4303 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_infty));
4304 check ("real(catanh(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4305 check ("imag(catanh(NaN - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4307 result = FUNC(catanh) (BUILD_COMPLEX (10.5, nan_value));
4308 check_isnan_maybe_exc ("real(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4309 __real__ result, INVALID_EXCEPTION);
4310 check_isnan ("imag(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4311 __imag__ result);
4312 result = FUNC(catanh) (BUILD_COMPLEX (-10.5, nan_value));
4313 check_isnan_maybe_exc ("real(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4314 __real__ result, INVALID_EXCEPTION);
4315 check_isnan ("imag(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4316 __imag__ result);
4318 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0.75));
4319 check_isnan_maybe_exc ("real(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4320 __real__ result, INVALID_EXCEPTION);
4321 check_isnan ("imag(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4322 __imag__ result);
4323 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, -0.75));
4324 check_isnan_maybe_exc ("real(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4325 __real__ result, INVALID_EXCEPTION);
4326 check_isnan ("imag(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4327 __imag__ result);
4329 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, nan_value));
4330 check_isnan ("real(catanh(NaN + i NaN)) = NaN", __real__ result);
4331 check_isnan ("imag(catanh(NaN + i NaN)) = NaN", __imag__ result);
4333 result = FUNC(catanh) (BUILD_COMPLEX (0.7, 1.2));
4334 check_eps ("real(catanh(0.7 + i 1.2)) == 0.26007...", __real__ result,
4335 0.2600749516525135959L, CHOOSE (2e-18, 6e-17, 0));
4336 check_eps ("imag(catanh(0.7 + i 1.2)) == 0.97024...", __imag__ result,
4337 0.9702403077950989849L, CHOOSE (3e-17, 2e-16, 4e-7));
4339 result = FUNC(catanh) (BUILD_COMPLEX (-2, -3));
4340 check_eps ("real(catanh(-2 - i 3)) == -0.14694...", __real__ result,
4341 -0.1469466662255297520L, CHOOSE (9e-20L, 2e-16, 2e-8));
4342 check_eps ("imag(catanh(-2 - i 3)) == -1.33897...", __imag__ result,
4343 -1.3389725222944935611L, CHOOSE (7e-19L, 0, 5e-7));
4347 static void
4348 ctan_test (void)
4350 __complex__ MATHTYPE result;
4352 result = FUNC(ctan) (BUILD_COMPLEX (0, 0));
4353 check ("real(ctan(0 + i0)) = 0", __real__ result, 0);
4354 check ("imag(ctan(0 + i0)) = 0", __imag__ result, 0);
4355 result = FUNC(ctan) (BUILD_COMPLEX (0, minus_zero));
4356 check ("real(ctan(0 - i0)) = 0", __real__ result, 0);
4357 check ("imag(ctan(0 - i0)) = -0", __imag__ result, minus_zero);
4358 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, 0));
4359 check ("real(ctan(-0 + i0)) = -0", __real__ result, minus_zero);
4360 check ("imag(ctan(-0 + i0)) = 0", __imag__ result, 0);
4361 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_zero));
4362 check ("real(ctan(-0 - i0)) = -0", __real__ result, minus_zero);
4363 check ("imag(ctan(-0 - i0)) = -0", __imag__ result, minus_zero);
4366 result = FUNC(ctan) (BUILD_COMPLEX (0, plus_infty));
4367 check ("real(ctan(0 + i Inf)) = 0", __real__ result, 0);
4368 check ("imag(ctan(0 + i Inf)) = 1", __imag__ result, 1);
4369 result = FUNC(ctan) (BUILD_COMPLEX (1, plus_infty));
4370 check ("real(ctan(1 + i Inf)) = 0", __real__ result, 0);
4371 check ("imag(ctan(1 + i Inf)) = 1", __imag__ result, 1);
4372 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, plus_infty));
4373 check ("real(ctan(-0 + i Inf)) = -0", __real__ result, minus_zero);
4374 check ("imag(ctan(-0 + i Inf)) = 1", __imag__ result, 1);
4375 result = FUNC(ctan) (BUILD_COMPLEX (-1, plus_infty));
4376 check ("real(ctan(-1 + i Inf)) = -0", __real__ result, minus_zero);
4377 check ("imag(ctan(-1 + i Inf)) = 1", __imag__ result, 1);
4379 result = FUNC(ctan) (BUILD_COMPLEX (0, minus_infty));
4380 check ("real(ctan(0 - i Inf)) = 0", __real__ result, 0);
4381 check ("imag(ctan(0 - i Inf)) = -1", __imag__ result, -1);
4382 result = FUNC(ctan) (BUILD_COMPLEX (1, minus_infty));
4383 check ("real(ctan(1 - i Inf)) = 0", __real__ result, 0);
4384 check ("imag(ctan(1 - i Inf)) = -1", __imag__ result, -1);
4385 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_infty));
4386 check ("real(ctan(-0 - i Inf)) = -0", __real__ result, minus_zero);
4387 check ("imag(ctan(-0 - i Inf)) = -1", __imag__ result, -1);
4388 result = FUNC(ctan) (BUILD_COMPLEX (-1, minus_infty));
4389 check ("real(ctan(-1 - i Inf)) = -0", __real__ result, minus_zero);
4390 check ("imag(ctan(-1 - i Inf)) = -1", __imag__ result, -1);
4392 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 0));
4393 check_isnan_exc ("real(ctan(Inf + i 0)) = NaN plus invalid exception",
4394 __real__ result, INVALID_EXCEPTION);
4395 check_isnan ("imag(ctan(Inf + i 0)) = NaN plus invalid exception",
4396 __imag__ result);
4397 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 2));
4398 check_isnan_exc ("real(ctan(Inf + i 2)) = NaN plus invalid exception",
4399 __real__ result, INVALID_EXCEPTION);
4400 check_isnan ("imag(ctan(Inf + i 2)) = NaN plus invalid exception",
4401 __imag__ result);
4402 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 0));
4403 check_isnan_exc ("real(ctan(-Inf + i 0)) = NaN plus invalid exception",
4404 __real__ result, INVALID_EXCEPTION);
4405 check_isnan ("imag(ctan(-Inf + i 0)) = NaN plus invalid exception",
4406 __imag__ result);
4407 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 2));
4408 check_isnan_exc ("real(ctan(- Inf + i 2)) = NaN plus invalid exception",
4409 __real__ result, INVALID_EXCEPTION);
4410 check_isnan ("imag(ctan(- Inf + i 2)) = NaN plus invalid exception",
4411 __imag__ result);
4412 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, minus_zero));
4413 check_isnan_exc ("real(ctan(Inf - i 0)) = NaN plus invalid exception",
4414 __real__ result, INVALID_EXCEPTION);
4415 check_isnan ("imag(ctan(Inf - i 0)) = NaN plus invalid exception",
4416 __imag__ result);
4417 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, -2));
4418 check_isnan_exc ("real(ctan(Inf - i 2)) = NaN plus invalid exception",
4419 __real__ result, INVALID_EXCEPTION);
4420 check_isnan ("imag(ctan(Inf - i 2)) = NaN plus invalid exception",
4421 __imag__ result);
4422 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, minus_zero));
4423 check_isnan_exc ("real(ctan(-Inf - i 0)) = NaN plus invalid exception",
4424 __real__ result, INVALID_EXCEPTION);
4425 check_isnan ("imag(ctan(-Inf - i 0)) = NaN plus invalid exception",
4426 __imag__ result);
4427 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, -2));
4428 check_isnan_exc ("real(ctan(-Inf - i 2)) = NaN plus invalid exception",
4429 __real__ result, INVALID_EXCEPTION);
4430 check_isnan ("imag(ctan(-Inf - i 2)) = NaN plus invalid exception",
4431 __imag__ result);
4433 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, plus_infty));
4434 check ("real(ctan(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4435 check ("imag(ctan(NaN + i Inf)) = 1", __imag__ result, 1);
4436 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_infty));
4437 check ("real(ctan(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4438 check ("imag(ctan(NaN - i Inf)) = -1", __imag__ result, -1);
4440 result = FUNC(ctan) (BUILD_COMPLEX (0, nan_value));
4441 check ("real(ctan(0 + i NaN)) = 0", __real__ result, 0);
4442 check_isnan ("imag(ctan(0 + i NaN)) = NaN", __imag__ result);
4443 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, nan_value));
4444 check ("real(ctan(-0 + i NaN)) = -0", __real__ result, minus_zero);
4445 check_isnan ("imag(ctan(-0 + i NaN)) = NaN", __imag__ result);
4447 result = FUNC(ctan) (BUILD_COMPLEX (0.5, nan_value));
4448 check_isnan_maybe_exc ("real(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4449 __real__ result, INVALID_EXCEPTION);
4450 check_isnan ("imag(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4451 __imag__ result);
4452 result = FUNC(ctan) (BUILD_COMPLEX (-4.5, nan_value));
4453 check_isnan_maybe_exc ("real(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4454 __real__ result, INVALID_EXCEPTION);
4455 check_isnan ("imag(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4456 __imag__ result);
4458 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 0));
4459 check_isnan_maybe_exc ("real(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4460 __real__ result, INVALID_EXCEPTION);
4461 check_isnan ("imag(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4462 __imag__ result);
4463 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 5));
4464 check_isnan_maybe_exc ("real(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4465 __real__ result, INVALID_EXCEPTION);
4466 check_isnan ("imag(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4467 __imag__ result);
4468 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_zero));
4469 check_isnan_maybe_exc ("real(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4470 __real__ result, INVALID_EXCEPTION);
4471 check_isnan ("imag(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4472 __imag__ result);
4473 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, -0.25));
4474 check_isnan_maybe_exc ("real(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4475 __real__ result, INVALID_EXCEPTION);
4476 check_isnan ("imag(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4477 __imag__ result);
4479 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, nan_value));
4480 check_isnan ("real(ctan(NaN + i NaN)) = NaN", __real__ result);
4481 check_isnan ("imag(ctan(NaN + i NaN)) = NaN", __imag__ result);
4483 result = FUNC(ctan) (BUILD_COMPLEX (0.7, 1.2));
4484 check_eps ("real(ctan(0.7 + i 1.2)) == 0.17207...", __real__ result,
4485 0.1720734197630349001L, CHOOSE(1e-17L, 3e-17, 2e-8));
4486 check_eps ("imag(ctan(0.7 + i 1.2)) == 0.95448...", __imag__ result,
4487 0.9544807059989405538L, CHOOSE(2e-17L, 2e-16, 6e-8));
4489 result = FUNC(ctan) (BUILD_COMPLEX (-2, -3));
4490 check_eps ("real(ctan(-2 - i 3)) == -0.00376...", __real__ result,
4491 0.0037640256415042482L, CHOOSE(1e-19L, 5e-19, 0));
4492 check_eps ("imag(ctan(-2 - i 3)) == -1.00323...", __imag__ result,
4493 -1.0032386273536098014L, CHOOSE(2e-19L, 0, 2e-7));
4497 static void
4498 ctanh_test (void)
4500 __complex__ MATHTYPE result;
4502 result = FUNC(ctanh) (BUILD_COMPLEX (0, 0));
4503 check ("real(ctanh(0 + i0)) = 0", __real__ result, 0);
4504 check ("imag(ctanh(0 + i0)) = 0", __imag__ result, 0);
4505 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_zero));
4506 check ("real(ctanh(0 - i0)) = 0", __real__ result, 0);
4507 check ("imag(ctanh(0 - i0)) = -0", __imag__ result, minus_zero);
4508 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, 0));
4509 check ("real(ctanh(-0 + i0)) = -0", __real__ result, minus_zero);
4510 check ("imag(ctanh(-0 + i0)) = 0", __imag__ result, 0);
4511 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4512 check ("real(ctanh(-0 - i0)) = -0", __real__ result, minus_zero);
4513 check ("imag(ctanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4515 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 0));
4516 check ("real(ctanh(+Inf + i0)) = 1", __real__ result, 1);
4517 check ("imag(ctanh(+Inf + i0)) = 0", __imag__ result, 0);
4518 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 1));
4519 check ("real(ctanh(+Inf + i1)) = 1", __real__ result, 1);
4520 check ("imag(ctanh(+Inf + i1)) = 0", __imag__ result, 0);
4521 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4522 check ("real(ctanh(+Inf - i0)) = 1", __real__ result, 1);
4523 check ("imag(ctanh(+Inf - i0)) = -0", __imag__ result, minus_zero);
4524 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, -1));
4525 check ("real(ctanh(+Inf - i1)) = 1", __real__ result, 1);
4526 check ("imag(ctanh(+Inf - i1)) = -0", __imag__ result, minus_zero);
4527 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 0));
4528 check ("real(ctanh(-Inf + i0)) = -1", __real__ result, -1);
4529 check ("imag(ctanh(-Inf + i0)) = 0", __imag__ result, 0);
4530 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 1));
4531 check ("real(ctanh(-Inf + i1)) = -1", __real__ result, -1);
4532 check ("imag(ctanh(-Inf + i1)) = 0", __imag__ result, 0);
4533 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4534 check ("real(ctanh(-Inf - i0)) = -1", __real__ result, -1);
4535 check ("imag(ctanh(-Inf - i0)) = -0", __imag__ result, minus_zero);
4536 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, -1));
4537 check ("real(ctanh(-Inf - i1)) = -1", __real__ result, -1);
4538 check ("imag(ctanh(-Inf - i1)) = -0", __imag__ result, minus_zero);
4540 result = FUNC(ctanh) (BUILD_COMPLEX (0, plus_infty));
4541 check_isnan_exc ("real(ctanh(0 + i Inf)) = NaN plus invalid exception",
4542 __real__ result, INVALID_EXCEPTION);
4543 check_isnan ("imag(ctanh(0 + i Inf)) = NaN plus invalid exception",
4544 __imag__ result);
4545 result = FUNC(ctanh) (BUILD_COMPLEX (2, plus_infty));
4546 check_isnan_exc ("real(ctanh(2 + i Inf)) = NaN plus invalid exception",
4547 __real__ result, INVALID_EXCEPTION);
4548 check_isnan ("imag(ctanh(2 + i Inf)) = NaN plus invalid exception",
4549 __imag__ result);
4550 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_infty));
4551 check_isnan_exc ("real(ctanh(0 - i Inf)) = NaN plus invalid exception",
4552 __real__ result, INVALID_EXCEPTION);
4553 check_isnan ("imag(ctanh(0 - i Inf)) = NaN plus invalid exception",
4554 __imag__ result);
4555 result = FUNC(ctanh) (BUILD_COMPLEX (2, minus_infty));
4556 check_isnan_exc ("real(ctanh(2 - i Inf)) = NaN plus invalid exception",
4557 __real__ result, INVALID_EXCEPTION);
4558 check_isnan ("imag(ctanh(2 - i Inf)) = NaN plus invalid exception",
4559 __imag__ result);
4560 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4561 check_isnan_exc ("real(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4562 __real__ result, INVALID_EXCEPTION);
4563 check_isnan ("imag(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4564 __imag__ result);
4565 result = FUNC(ctanh) (BUILD_COMPLEX (-2, plus_infty));
4566 check_isnan_exc ("real(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4567 __real__ result, INVALID_EXCEPTION);
4568 check_isnan ("imag(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4569 __imag__ result);
4570 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4571 check_isnan_exc ("real(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4572 __real__ result, INVALID_EXCEPTION);
4573 check_isnan ("imag(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4574 __imag__ result);
4575 result = FUNC(ctanh) (BUILD_COMPLEX (-2, minus_infty));
4576 check_isnan_exc ("real(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4577 __real__ result, INVALID_EXCEPTION);
4578 check_isnan ("imag(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4579 __imag__ result);
4581 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, nan_value));
4582 check ("real(ctanh(+Inf + i NaN)) = 1", __real__ result, 1);
4583 check ("imag(ctanh(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4584 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, nan_value));
4585 check ("real(ctanh(-Inf + i NaN)) = -1", __real__ result, -1);
4586 check ("imag(ctanh(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4588 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0));
4589 check_isnan ("real(ctanh(NaN + i0)) = NaN", __real__ result);
4590 check ("imag(ctanh(NaN + i0)) = 0", __imag__ result, 0);
4591 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, minus_zero));
4592 check_isnan ("real(ctanh(NaN - i0)) = NaN", __real__ result);
4593 check ("imag(ctanh(NaN - i0)) = -0", __imag__ result, minus_zero);
4595 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0.5));
4596 check_isnan_maybe_exc ("real(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4597 __real__ result, INVALID_EXCEPTION);
4598 check_isnan ("imag(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4599 __imag__ result);
4600 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, -4.5));
4601 check_isnan_maybe_exc ("real(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4602 __real__ result, INVALID_EXCEPTION);
4603 check_isnan ("imag(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4604 __imag__ result);
4606 result = FUNC(ctanh) (BUILD_COMPLEX (0, nan_value));
4607 check_isnan_maybe_exc ("real(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4608 __real__ result, INVALID_EXCEPTION);
4609 check_isnan ("imag(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4610 __imag__ result);
4611 result = FUNC(ctanh) (BUILD_COMPLEX (5, nan_value));
4612 check_isnan_maybe_exc ("real(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4613 __real__ result, INVALID_EXCEPTION);
4614 check_isnan ("imag(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4615 __imag__ result);
4616 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, nan_value));
4617 check_isnan_maybe_exc ("real(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4618 __real__ result, INVALID_EXCEPTION);
4619 check_isnan ("imag(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4620 __imag__ result);
4621 result = FUNC(ctanh) (BUILD_COMPLEX (-0.25, nan_value));
4622 check_isnan_maybe_exc ("real(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4623 __real__ result, INVALID_EXCEPTION);
4624 check_isnan ("imag(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4625 __imag__ result);
4627 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, nan_value));
4628 check_isnan ("real(ctanh(NaN + i NaN)) = NaN", __real__ result);
4629 check_isnan ("imag(ctanh(NaN + i NaN)) = NaN", __imag__ result);
4631 result = FUNC(ctanh) (BUILD_COMPLEX (0, M_PI_4l));
4632 check ("real(ctanh (0 + i pi/4)) == 0", __real__ result, 0);
4633 check_eps ("imag(ctanh (0 + i pi/4)) == 1", __imag__ result, 1,
4634 CHOOSE (0, 2e-16, 2e-7));
4636 result = FUNC(ctanh) (BUILD_COMPLEX (0.7, 1.2));
4637 check_eps ("real(ctanh(0.7 + i 1.2)) == 1.34721...", __real__ result,
4638 1.3472197399061191630L, CHOOSE(4e-17L, 5e-16, 2e-7));
4639 check_eps ("imag(ctanh(0.7 + i 1.2)) == -0.47786...", __imag__ result,
4640 0.4778641038326365540L, CHOOSE(9e-17L, 2e-16, 9e-8));
4642 result = FUNC(ctanh) (BUILD_COMPLEX (-2, -3));
4643 check_eps ("real(ctanh(-2 - i 3)) == -0.96538...", __real__ result,
4644 -0.9653858790221331242L, CHOOSE(2e-19L, 2e-16, 2e-7));
4645 check_eps ("imag(ctanh(-2 - i 3)) == 0.00988...", __imag__ result,
4646 0.0098843750383224937L, CHOOSE(7e-20L, 2e-16, 1e-9));
4650 static void
4651 clog_test (void)
4653 __complex__ MATHTYPE result;
4655 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, 0));
4656 check_isinfn_exc ("real(clog(-0 + i0)) = -Inf plus divide-by-zero exception",
4657 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4658 check ("imag(clog(-0 + i0)) = pi plus divide-by-zero exception",
4659 __imag__ result, M_PIl);
4660 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_zero));
4661 check_isinfn_exc ("real(clog(-0 - i0)) = -Inf plus divide-by-zero exception",
4662 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4663 check ("imag(clog(-0 - i0)) = -pi plus divide-by-zero exception",
4664 __imag__ result, -M_PIl);
4666 result = FUNC(clog) (BUILD_COMPLEX (0, 0));
4667 check_isinfn_exc ("real(clog(0 + i0)) = -Inf plus divide-by-zero exception",
4668 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4669 check ("imag(clog(0 + i0)) = 0 plus divide-by-zero exception",
4670 __imag__ result, 0);
4671 result = FUNC(clog) (BUILD_COMPLEX (0, minus_zero));
4672 check_isinfn_exc ("real(clog(0 - i0)) = -Inf plus divide-by-zero exception",
4673 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4674 check ("imag(clog(0 - i0)) = -0 plus divide-by-zero exception",
4675 __imag__ result, minus_zero);
4677 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, plus_infty));
4678 check_isinfp ("real(clog(-Inf + i Inf)) = +Inf", __real__ result);
4679 check ("imag(clog(-Inf + i Inf)) = 3*pi/4", __imag__ result,
4680 M_PIl - M_PI_4l);
4681 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_infty));
4682 check_isinfp ("real(clog(-Inf - i Inf)) = +Inf", __real__ result);
4683 check ("imag(clog(-Inf - i Inf)) = -3*pi/4", __imag__ result,
4684 M_PI_4l - M_PIl);
4686 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, plus_infty));
4687 check_isinfp ("real(clog(+Inf + i Inf)) = +Inf", __real__ result);
4688 check ("imag(clog(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
4689 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_infty));
4690 check_isinfp ("real(clog(+Inf - i Inf)) = +Inf", __real__ result);
4691 check ("imag(clog(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
4693 result = FUNC(clog) (BUILD_COMPLEX (0, plus_infty));
4694 check_isinfp ("real(clog(0 + i Inf)) = +Inf", __real__ result);
4695 check ("imag(clog(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4696 result = FUNC(clog) (BUILD_COMPLEX (3, plus_infty));
4697 check_isinfp ("real(clog(3 + i Inf)) = +Inf", __real__ result);
4698 check ("imag(clog(3 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4699 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, plus_infty));
4700 check_isinfp ("real(clog(-0 + i Inf)) = +Inf", __real__ result);
4701 check ("imag(clog(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4702 result = FUNC(clog) (BUILD_COMPLEX (-3, plus_infty));
4703 check_isinfp ("real(clog(-3 + i Inf)) = +Inf", __real__ result);
4704 check ("imag(clog(-3 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4705 result = FUNC(clog) (BUILD_COMPLEX (0, minus_infty));
4706 check_isinfp ("real(clog(0 - i Inf)) = +Inf", __real__ result);
4707 check ("imag(clog(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4708 result = FUNC(clog) (BUILD_COMPLEX (3, minus_infty));
4709 check_isinfp ("real(clog(3 - i Inf)) = +Inf", __real__ result);
4710 check ("imag(clog(3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4711 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_infty));
4712 check_isinfp ("real(clog(-0 - i Inf)) = +Inf", __real__ result);
4713 check ("imag(clog(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4714 result = FUNC(clog) (BUILD_COMPLEX (-3, minus_infty));
4715 check_isinfp ("real(clog(-3 - i Inf)) = +Inf", __real__ result);
4716 check ("imag(clog(-3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4718 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 0));
4719 check_isinfp ("real(clog(-Inf + i0)) = +Inf", __real__ result);
4720 check ("imag(clog(-Inf + i0)) = pi", __imag__ result, M_PIl);
4721 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 1));
4722 check_isinfp ("real(clog(-Inf + i1)) = +Inf", __real__ result);
4723 check ("imag(clog(-Inf + i1)) = pi", __imag__ result, M_PIl);
4724 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_zero));
4725 check_isinfp ("real(clog(-Inf - i0)) = +Inf", __real__ result);
4726 check ("imag(clog(-Inf - i0)) = -pi", __imag__ result, -M_PIl);
4727 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, -1));
4728 check_isinfp ("real(clog(-Inf - i1)) = +Inf", __real__ result);
4729 check ("imag(clog(-Inf - i1)) = -pi", __imag__ result, -M_PIl);
4731 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 0));
4732 check_isinfp ("real(clog(+Inf + i0)) = +Inf", __real__ result);
4733 check ("imag(clog(+Inf + i0)) = 0", __imag__ result, 0);
4734 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 1));
4735 check_isinfp ("real(clog(+Inf + i1)) = +Inf", __real__ result);
4736 check ("imag(clog(+Inf + i1)) = 0", __imag__ result, 0);
4737 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_zero));
4738 check_isinfp ("real(clog(+Inf - i0)) = +Inf", __real__ result);
4739 check ("imag(clog(+Inf - i0)) = -0", __imag__ result, minus_zero);
4740 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, -1));
4741 check_isinfp ("real(clog(+Inf - i1)) = +Inf", __real__ result);
4742 check ("imag(clog(+Inf - i1)) = -0", __imag__ result, minus_zero);
4744 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, nan_value));
4745 check_isinfp ("real(clog(+Inf + i NaN)) = +Inf", __real__ result);
4746 check_isnan ("imag(clog(+Inf + i NaN)) = NaN", __imag__ result);
4747 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, nan_value));
4748 check_isinfp ("real(clog(-Inf + i NaN)) = +Inf", __real__ result);
4749 check_isnan ("imag(clog(-Inf + i NaN)) = NaN", __imag__ result);
4751 result = FUNC(clog) (BUILD_COMPLEX (nan_value, plus_infty));
4752 check_isinfp ("real(clog(NaN + i Inf)) = +Inf", __real__ result);
4753 check_isnan ("imag(clog(NaN + i Inf)) = NaN", __imag__ result);
4754 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_infty));
4755 check_isinfp ("real(clog(NaN - i Inf)) = +Inf", __real__ result);
4756 check_isnan ("imag(clog(NaN - i Inf)) = NaN", __imag__ result);
4758 result = FUNC(clog) (BUILD_COMPLEX (0, nan_value));
4759 check_isnan_maybe_exc ("real(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4760 __real__ result, INVALID_EXCEPTION);
4761 check_isnan ("imag(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4762 __imag__ result);
4763 result = FUNC(clog) (BUILD_COMPLEX (3, nan_value));
4764 check_isnan_maybe_exc ("real(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4765 __real__ result, INVALID_EXCEPTION);
4766 check_isnan ("imag(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4767 __imag__ result);
4768 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, nan_value));
4769 check_isnan_maybe_exc ("real(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4770 __real__ result, INVALID_EXCEPTION);
4771 check_isnan ("imag(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4772 __imag__ result);
4773 result = FUNC(clog) (BUILD_COMPLEX (-3, nan_value));
4774 check_isnan_maybe_exc ("real(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4775 __real__ result, INVALID_EXCEPTION);
4776 check_isnan ("imag(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4777 __imag__ result);
4779 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 0));
4780 check_isnan_maybe_exc ("real(clog(NaN + i0)) = NaN plus maybe invalid exception",
4781 __real__ result, INVALID_EXCEPTION);
4782 check_isnan ("imag(clog(NaN + i0)) = NaN plus maybe invalid exception",
4783 __imag__ result);
4784 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 5));
4785 check_isnan_maybe_exc ("real(clog(NaN + i5)) = NaN plus maybe invalid exception",
4786 __real__ result, INVALID_EXCEPTION);
4787 check_isnan ("imag(clog(NaN + i5)) = NaN plus maybe invalid exception",
4788 __imag__ result);
4789 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_zero));
4790 check_isnan_maybe_exc ("real(clog(NaN - i0)) = NaN plus maybe invalid exception",
4791 __real__ result, INVALID_EXCEPTION);
4792 check_isnan ("imag(clog(NaN - i0)) = NaN plus maybe invalid exception",
4793 __imag__ result);
4794 result = FUNC(clog) (BUILD_COMPLEX (nan_value, -5));
4795 check_isnan_maybe_exc ("real(clog(NaN - i5)) = NaN plus maybe invalid exception",
4796 __real__ result, INVALID_EXCEPTION);
4797 check_isnan ("imag(clog(NaN - i5)) = NaN plus maybe invalid exception",
4798 __imag__ result);
4800 result = FUNC(clog) (BUILD_COMPLEX (nan_value, nan_value));
4801 check_isnan ("real(clog(NaN + i NaN)) = NaN", __real__ result);
4802 check_isnan ("imag(clog(NaN + i NaN)) = NaN", __imag__ result);
4804 result = FUNC(clog) (BUILD_COMPLEX (0.7, 1.2));
4805 check_eps ("real(clog(0.7 + i 1.2)) == 0.32876...", __real__ result,
4806 0.3287600014583970919L, CHOOSE(5e-17L, 6e-17, 3e-8));
4807 check_eps ("imag(clog(0.7 + i 1.2)) == 1.04272...", __imag__ result,
4808 1.0427218783685369524L, CHOOSE(2e-17L, 0, 0));
4810 result = FUNC(clog) (BUILD_COMPLEX (-2, -3));
4811 check_eps ("real(clog(-2 - i 3)) == 1.28247...", __real__ result,
4812 1.2824746787307683680L, CHOOSE(3e-19L, 0, 0));
4813 check_eps ("imag(clog(-2 - i 3)) == -2.15879...", __imag__ result,
4814 -2.1587989303424641704L, CHOOSE(2e-18L, 5e-16, 8e-7));
4818 static void
4819 clog10_test (void)
4821 __complex__ MATHTYPE result;
4823 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, 0));
4824 check_isinfn_exc ("real(clog10(-0 + i0)) = -Inf plus divide-by-zero exception",
4825 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4826 check ("imag(clog10(-0 + i0)) = pi plus divide-by-zero exception",
4827 __imag__ result, M_PIl);
4828 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_zero));
4829 check_isinfn_exc ("real(clog10(-0 - i0)) = -Inf plus divide-by-zero exception",
4830 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4831 check ("imag(clog10(-0 - i0)) = -pi plus divide-by-zero exception",
4832 __imag__ result, -M_PIl);
4834 result = FUNC(clog10) (BUILD_COMPLEX (0, 0));
4835 check_isinfn_exc ("real(clog10(0 + i0)) = -Inf plus divide-by-zero exception",
4836 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4837 check ("imag(clog10(0 + i0)) = 0 plus divide-by-zero exception",
4838 __imag__ result, 0);
4839 result = FUNC(clog10) (BUILD_COMPLEX (0, minus_zero));
4840 check_isinfn_exc ("real(clog10(0 - i0)) = -Inf plus divide-by-zero exception",
4841 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4842 check ("imag(clog10(0 - i0)) = -0 plus divide-by-zero exception",
4843 __imag__ result, minus_zero);
4845 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, plus_infty));
4846 check_isinfp ("real(clog10(-Inf + i Inf)) = +Inf", __real__ result);
4847 check_eps ("imag(clog10(-Inf + i Inf)) = 3*pi/4*M_LOG10E", __imag__ result,
4848 (M_PIl - M_PI_4l) * M_LOG10El, CHOOSE (0, 3e-16, 0));
4849 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_infty));
4850 check_isinfp ("real(clog10(-Inf - i Inf)) = +Inf", __real__ result);
4851 check_eps ("imag(clog10(-Inf - i Inf)) = -3*pi/4*M_LOG10E", __imag__ result,
4852 (M_PI_4l - M_PIl) * M_LOG10El, CHOOSE (0, 3e-16, 0));
4854 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, plus_infty));
4855 check_isinfp ("real(clog10(+Inf + i Inf)) = +Inf", __real__ result);
4856 check_eps ("imag(clog10(+Inf + i Inf)) = pi/4*M_LOG10E", __imag__ result,
4857 M_PI_4l * M_LOG10El, CHOOSE (0, 6e-17, 3e-8));
4858 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_infty));
4859 check_isinfp ("real(clog10(+Inf - i Inf)) = +Inf", __real__ result);
4860 check_eps ("imag(clog10(+Inf - i Inf)) = -pi/4*M_LOG10E", __imag__ result,
4861 -M_PI_4l * M_LOG10El, CHOOSE (0, 6e-17, 3e-8));
4863 result = FUNC(clog10) (BUILD_COMPLEX (0, plus_infty));
4864 check_isinfp ("real(clog10(0 + i Inf)) = +Inf", __real__ result);
4865 check_eps ("imag(clog10(0 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4866 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4867 result = FUNC(clog10) (BUILD_COMPLEX (3, plus_infty));
4868 check_isinfp ("real(clog10(3 + i Inf)) = +Inf", __real__ result);
4869 check_eps ("imag(clog10(3 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4870 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4871 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, plus_infty));
4872 check_isinfp ("real(clog10(-0 + i Inf)) = +Inf", __real__ result);
4873 check_eps ("imag(clog10(-0 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4874 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4875 result = FUNC(clog10) (BUILD_COMPLEX (-3, plus_infty));
4876 check_isinfp ("real(clog10(-3 + i Inf)) = +Inf", __real__ result);
4877 check_eps ("imag(clog10(-3 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4878 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4879 result = FUNC(clog10) (BUILD_COMPLEX (0, minus_infty));
4880 check_isinfp ("real(clog10(0 - i Inf)) = +Inf", __real__ result);
4881 check_eps ("imag(clog10(0 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4882 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4883 result = FUNC(clog10) (BUILD_COMPLEX (3, minus_infty));
4884 check_isinfp ("real(clog10(3 - i Inf)) = +Inf", __real__ result);
4885 check_eps ("imag(clog10(3 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4886 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4887 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_infty));
4888 check_isinfp ("real(clog10(-0 - i Inf)) = +Inf", __real__ result);
4889 check_eps ("imag(clog10(-0 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4890 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4891 result = FUNC(clog10) (BUILD_COMPLEX (-3, minus_infty));
4892 check_isinfp ("real(clog10(-3 - i Inf)) = +Inf", __real__ result);
4893 check_eps ("imag(clog10(-3 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4894 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4896 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 0));
4897 check_isinfp ("real(clog10(-Inf + i0)) = +Inf", __real__ result);
4898 check_eps ("imag(clog10(-Inf + i0)) = pi*M_LOG10E", __imag__ result,
4899 M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4900 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 1));
4901 check_isinfp ("real(clog10(-Inf + i1)) = +Inf", __real__ result);
4902 check_eps ("imag(clog10(-Inf + i1)) = pi*M_LOG10E", __imag__ result,
4903 M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4904 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_zero));
4905 check_isinfp ("real(clog10(-Inf - i0)) = +Inf", __real__ result);
4906 check_eps ("imag(clog10(-Inf - i0)) = -pi*M_LOG10E", __imag__ result,
4907 -M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4908 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, -1));
4909 check_isinfp ("real(clog10(-Inf - i1)) = +Inf", __real__ result);
4910 check_eps ("imag(clog10(-Inf - i1)) = -pi*M_LOG10E", __imag__ result,
4911 -M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4913 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 0));
4914 check_isinfp ("real(clog10(+Inf + i0)) = +Inf", __real__ result);
4915 check ("imag(clog10(+Inf + i0)) = 0", __imag__ result, 0);
4916 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 1));
4917 check_isinfp ("real(clog10(+Inf + i1)) = +Inf", __real__ result);
4918 check ("imag(clog10(+Inf + i1)) = 0", __imag__ result, 0);
4919 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_zero));
4920 check_isinfp ("real(clog10(+Inf - i0)) = +Inf", __real__ result);
4921 check ("imag(clog10(+Inf - i0)) = -0", __imag__ result, minus_zero);
4922 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, -1));
4923 check_isinfp ("real(clog10(+Inf - i1)) = +Inf", __real__ result);
4924 check ("imag(clog10(+Inf - i1)) = -0", __imag__ result, minus_zero);
4926 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, nan_value));
4927 check_isinfp ("real(clog10(+Inf + i NaN)) = +Inf", __real__ result);
4928 check_isnan ("imag(clog10(+Inf + i NaN)) = NaN", __imag__ result);
4929 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, nan_value));
4930 check_isinfp ("real(clog10(-Inf + i NaN)) = +Inf", __real__ result);
4931 check_isnan ("imag(clog10(-Inf + i NaN)) = NaN", __imag__ result);
4933 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, plus_infty));
4934 check_isinfp ("real(clog10(NaN + i Inf)) = +Inf", __real__ result);
4935 check_isnan ("imag(clog10(NaN + i Inf)) = NaN", __imag__ result);
4936 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_infty));
4937 check_isinfp ("real(clog10(NaN - i Inf)) = +Inf", __real__ result);
4938 check_isnan ("imag(clog10(NaN - i Inf)) = NaN", __imag__ result);
4940 result = FUNC(clog10) (BUILD_COMPLEX (0, nan_value));
4941 check_isnan_maybe_exc ("real(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4942 __real__ result, INVALID_EXCEPTION);
4943 check_isnan ("imag(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4944 __imag__ result);
4945 result = FUNC(clog10) (BUILD_COMPLEX (3, nan_value));
4946 check_isnan_maybe_exc ("real(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4947 __real__ result, INVALID_EXCEPTION);
4948 check_isnan ("imag(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4949 __imag__ result);
4950 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, nan_value));
4951 check_isnan_maybe_exc ("real(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4952 __real__ result, INVALID_EXCEPTION);
4953 check_isnan ("imag(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4954 __imag__ result);
4955 result = FUNC(clog10) (BUILD_COMPLEX (-3, nan_value));
4956 check_isnan_maybe_exc ("real(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4957 __real__ result, INVALID_EXCEPTION);
4958 check_isnan ("imag(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4959 __imag__ result);
4961 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 0));
4962 check_isnan_maybe_exc ("real(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4963 __real__ result, INVALID_EXCEPTION);
4964 check_isnan ("imag(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4965 __imag__ result);
4966 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 5));
4967 check_isnan_maybe_exc ("real(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4968 __real__ result, INVALID_EXCEPTION);
4969 check_isnan ("imag(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4970 __imag__ result);
4971 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_zero));
4972 check_isnan_maybe_exc ("real(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4973 __real__ result, INVALID_EXCEPTION);
4974 check_isnan ("imag(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4975 __imag__ result);
4976 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, -5));
4977 check_isnan_maybe_exc ("real(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4978 __real__ result, INVALID_EXCEPTION);
4979 check_isnan ("imag(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4980 __imag__ result);
4982 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, nan_value));
4983 check_isnan ("real(clog10(NaN + i NaN)) = NaN", __real__ result);
4984 check_isnan ("imag(clog10(NaN + i NaN)) = NaN", __imag__ result);
4986 result = FUNC(clog10) (BUILD_COMPLEX (0.7, 1.2));
4987 check_eps ("real(clog10(0.7 + i 1.2)) == 0.14277...", __real__ result,
4988 0.1427786545038868803L, CHOOSE(2e-17L, 6e-17, 2e-8));
4989 check_eps ("imag(clog10(0.7 + i 1.2)) == 0.45284...", __imag__ result,
4990 0.4528483579352493248L, CHOOSE(6e-18, 6e-17, 3e-8));
4992 result = FUNC(clog10) (BUILD_COMPLEX (-2, -3));
4993 check_eps ("real(clog10(-2 - i 3)) == 0.55697...", __real__ result,
4994 0.5569716761534183846L, CHOOSE(6e-20L, 0, 0));
4995 check_eps ("imag(clog10(-2 - i 3)) == -0.93755...", __imag__ result,
4996 -0.9375544629863747085L, CHOOSE (7e-19L, 2e-16, 3e-7));
5000 static void
5001 csqrt_test (void)
5003 __complex__ MATHTYPE result;
5005 result = FUNC(csqrt) (BUILD_COMPLEX (0, 0));
5006 check ("real(csqrt(0 + i0)) = 0", __real__ result, 0);
5007 check ("imag(csqrt(0 + i0)) = 0", __imag__ result, 0);
5008 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_zero));
5009 check ("real(csqrt(0 - i0)) = 0", __real__ result, 0);
5010 check ("imag(csqrt(0 - i0)) = -0", __imag__ result, minus_zero);
5011 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, 0));
5012 check ("real(csqrt(-0 + i0)) = 0", __real__ result, 0);
5013 check ("imag(csqrt(-0 + i0)) = 0", __imag__ result, 0);
5014 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_zero));
5015 check ("real(csqrt(-0 - i0)) = 0", __real__ result, 0);
5016 check ("imag(csqrt(-0 - i0)) = -0", __imag__ result, minus_zero);
5018 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 0));
5019 check ("real(csqrt(-Inf + i0)) = 0", __real__ result, 0);
5020 check_isinfp ("imag(csqrt(-Inf + i0)) = +Inf", __imag__ result);
5021 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 6));
5022 check ("real(csqrt(-Inf + i6)) = 0", __real__ result, 0);
5023 check_isinfp ("imag(csqrt(-Inf + i6)) = +Inf", __imag__ result);
5024 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_zero));
5025 check ("real(csqrt(-Inf - i0)) = 0", __real__ result, 0);
5026 check_isinfn ("imag(csqrt(-Inf - i0)) = -Inf", __imag__ result);
5027 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, -6));
5028 check ("real(csqrt(-Inf - i6)) = 0", __real__ result, 0);
5029 check_isinfn ("imag(csqrt(-Inf - i6)) = -Inf", __imag__ result);
5031 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 0));
5032 check_isinfp ("real(csqrt(+Inf + i0)) = +Inf", __real__ result);
5033 check ("imag(csqrt(+Inf + i0)) = 0", __imag__ result, 0);
5034 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 6));
5035 check_isinfp ("real(csqrt(+Inf + i6)) = +Inf", __real__ result);
5036 check ("imag(csqrt(+Inf + i6)) = 0", __imag__ result, 0);
5037 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_zero));
5038 check_isinfp ("real(csqrt(+Inf - i0)) = +Inf", __real__ result);
5039 check ("imag(csqrt(+Inf - i0)) = -0", __imag__ result, minus_zero);
5040 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, -6));
5041 check_isinfp ("real(csqrt(+Inf - i6)) = +Inf", __real__ result);
5042 check ("imag(csqrt(+Inf - i6)) = -0", __imag__ result, minus_zero);
5044 result = FUNC(csqrt) (BUILD_COMPLEX (0, plus_infty));
5045 check_isinfp ("real(csqrt(0 + i Inf)) = +Inf", __real__ result);
5046 check_isinfp ("imag(csqrt(0 + i Inf)) = +Inf", __imag__ result);
5047 result = FUNC(csqrt) (BUILD_COMPLEX (4, plus_infty));
5048 check_isinfp ("real(csqrt(4 + i Inf)) = +Inf", __real__ result);
5049 check_isinfp ("imag(csqrt(4 + i Inf)) = +Inf", __imag__ result);
5050 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, plus_infty));
5051 check_isinfp ("real(csqrt(+Inf + i Inf)) = +Inf", __real__ result);
5052 check_isinfp ("imag(csqrt(+Inf + i Inf)) = +Inf", __imag__ result);
5053 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, plus_infty));
5054 check_isinfp ("real(csqrt(-0 + i Inf)) = +Inf", __real__ result);
5055 check_isinfp ("imag(csqrt(-0 + i Inf)) = +Inf", __imag__ result);
5056 result = FUNC(csqrt) (BUILD_COMPLEX (-4, plus_infty));
5057 check_isinfp ("real(csqrt(-4 + i Inf)) = +Inf", __real__ result);
5058 check_isinfp ("imag(csqrt(-4 + i Inf)) = +Inf", __imag__ result);
5059 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, plus_infty));
5060 check_isinfp ("real(csqrt(-Inf + i Inf)) = +Inf", __real__ result);
5061 check_isinfp ("imag(csqrt(-Inf + i Inf)) = +Inf", __imag__ result);
5062 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_infty));
5063 check_isinfp ("real(csqrt(0 - i Inf)) = +Inf", __real__ result);
5064 check_isinfn ("imag(csqrt(0 - i Inf)) = -Inf", __imag__ result);
5065 result = FUNC(csqrt) (BUILD_COMPLEX (4, minus_infty));
5066 check_isinfp ("real(csqrt(4 - i Inf)) = +Inf", __real__ result);
5067 check_isinfn ("imag(csqrt(4 - i Inf)) = -Inf", __imag__ result);
5068 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_infty));
5069 check_isinfp ("real(csqrt(+Inf - i Inf)) = +Inf", __real__ result);
5070 check_isinfn ("imag(csqrt(+Inf - i Inf)) = -Inf", __imag__ result);
5071 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_infty));
5072 check_isinfp ("real(csqrt(-0 - i Inf)) = +Inf", __real__ result);
5073 check_isinfn ("imag(csqrt(-0 - i Inf)) = -Inf", __imag__ result);
5074 result = FUNC(csqrt) (BUILD_COMPLEX (-4, minus_infty));
5075 check_isinfp ("real(csqrt(-4 - i Inf)) = +Inf", __real__ result);
5076 check_isinfn ("imag(csqrt(-4 - i Inf)) = -Inf", __imag__ result);
5077 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_infty));
5078 check_isinfp ("real(csqrt(-Inf - i Inf)) = +Inf", __real__ result);
5079 check_isinfn ("imag(csqrt(-Inf - i Inf)) = -Inf", __imag__ result);
5081 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, nan_value));
5082 check_isnan ("real(csqrt(-Inf + i NaN)) = NaN", __real__ result);
5083 check_isinfp ("imag(csqrt(-Inf + i NaN)) = +-Inf",
5084 FUNC(fabs) (__imag__ result));
5086 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, nan_value));
5087 check_isinfp ("real(csqrt(+Inf + i NaN)) = +Inf", __real__ result);
5088 check_isnan ("imag(csqrt(+Inf + i NaN)) = NaN", __imag__ result);
5090 result = FUNC(csqrt) (BUILD_COMPLEX (0, nan_value));
5091 check_isnan_maybe_exc ("real(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
5092 __real__ result, INVALID_EXCEPTION);
5093 check_isnan ("imag(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
5094 __imag__ result);
5095 result = FUNC(csqrt) (BUILD_COMPLEX (1, nan_value));
5096 check_isnan_maybe_exc ("real(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
5097 __real__ result, INVALID_EXCEPTION);
5098 check_isnan ("imag(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
5099 __imag__ result);
5100 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, nan_value));
5101 check_isnan_maybe_exc ("real(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
5102 __real__ result, INVALID_EXCEPTION);
5103 check_isnan ("imag(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
5104 __imag__ result);
5105 result = FUNC(csqrt) (BUILD_COMPLEX (-1, nan_value));
5106 check_isnan_maybe_exc ("real(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
5107 __real__ result, INVALID_EXCEPTION);
5108 check_isnan ("imag(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
5109 __imag__ result);
5111 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 0));
5112 check_isnan_maybe_exc ("real(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
5113 __real__ result, INVALID_EXCEPTION);
5114 check_isnan ("imag(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
5115 __imag__ result);
5116 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 8));
5117 check_isnan_maybe_exc ("real(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
5118 __real__ result, INVALID_EXCEPTION);
5119 check_isnan ("imag(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
5120 __imag__ result);
5121 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, minus_zero));
5122 check_isnan_maybe_exc ("real(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
5123 __real__ result, INVALID_EXCEPTION);
5124 check_isnan ("imag(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
5125 __imag__ result);
5126 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, -8));
5127 check_isnan_maybe_exc ("real(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
5128 __real__ result, INVALID_EXCEPTION);
5129 check_isnan ("imag(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
5130 __imag__ result);
5132 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, nan_value));
5133 check_isnan ("real(csqrt(NaN + i NaN)) = NaN", __real__ result);
5134 check_isnan ("imag(csqrt(NaN + i NaN)) = NaN", __imag__ result);
5136 result = FUNC(csqrt) (BUILD_COMPLEX (16.0, -30.0));
5137 check ("real(csqrt(16 - 30i)) = 5", __real__ result, 5.0);
5138 check ("imag(csqrt(16 - 30i)) = -3", __imag__ result, -3.0);
5140 result = FUNC(csqrt) (BUILD_COMPLEX (-1, 0));
5141 check ("real(csqrt(1 + i0) = 0", __real__ result, 0);
5142 check ("imag(csqrt(1 + i0) = 1", __imag__ result, 1);
5144 result = FUNC(csqrt) (BUILD_COMPLEX (0, 2));
5145 check ("real(csqrt(0 + i 2) = 1", __real__ result, 1);
5146 check ("imag(csqrt(0 + i 2) = 1", __imag__ result, 1);
5148 result = FUNC(csqrt) (BUILD_COMPLEX (119, 120));
5149 check ("real(csqrt(119 + i 120) = 12", __real__ result, 12);
5150 check ("imag(csqrt(119 + i 120) = 5", __imag__ result, 5);
5152 result = FUNC(csqrt) (BUILD_COMPLEX (0.7, 1.2));
5153 check_eps ("real(csqrt(0.7 + i 1.2)) == 1.02206...", __real__ result,
5154 1.0220676100300264507L, CHOOSE(3e-17L, 3e-16, 2e-7));
5155 check_eps ("imag(csqrt(0.7 + i 1.2)) == 0.58704...", __imag__ result,
5156 0.5870453129635652115L, CHOOSE(7e-18L, 0, 0));
5158 result = FUNC(csqrt) (BUILD_COMPLEX (-2, -3));
5159 check_eps ("real(csqrt(-2 - i 3)) == -0.89597...", __real__ result,
5160 0.8959774761298381247L, CHOOSE(6e-20L, 2e-16, 6e-8));
5161 check_eps ("imag(csqrt(-2 - i 3)) == -1.67414...", __imag__ result,
5162 -1.6741492280355400404L, CHOOSE(0, 5e-16, 0));
5166 static void
5167 cpow_test (void)
5169 __complex__ MATHTYPE result;
5171 result = FUNC (cpow) (BUILD_COMPLEX (1, 0), BUILD_COMPLEX (0, 0));
5172 check ("real(cpow (1 + i0), (0 + i0)) == 0", __real__ result, 1);
5173 check ("imag(cpow (1 + i0), (0 + i0)) == 0", __imag__ result, 0);
5175 result = FUNC (cpow) (BUILD_COMPLEX (2, 0), BUILD_COMPLEX (10, 0));
5176 check_eps ("real(cpow (2 + i0), (10 + i0)) == 1024", __real__ result, 1024,
5177 CHOOSE (2e-16L, 0, 0));
5178 check ("imag(cpow (2 + i0), (10 + i0)) == 0", __imag__ result, 0);
5180 result = FUNC (cpow) (BUILD_COMPLEX (M_El, 0), BUILD_COMPLEX (0, 2 * M_PIl));
5181 check_eps ("real(cpow (e + i0), (0 + i 2*PI)) == 1", __real__ result, 1,
5182 CHOOSE (0, 0, 6e-8));
5183 check_eps ("imag(cpow (e + i0), (0 + i 2*PI)) == 0", __imag__ result, 0,
5184 CHOOSE (3e-18L, 3e-16, 4e-7));
5186 result = FUNC (cpow) (BUILD_COMPLEX (2, 3), BUILD_COMPLEX (4, 0));
5187 check_eps ("real(cpow (2 + i3), (4 + i0)) == -119", __real__ result, -119,
5188 CHOOSE (9e-16L, 2e-14, 4e-5));
5189 check_eps ("imag(cpow (2 + i3), (4 + i0)) == -120", __imag__ result, -120,
5190 CHOOSE (1e-15L, 0, 5e-5));
5194 static void
5195 cabs_test (void)
5197 /* cabs (x + iy) is specified as hypot (x,y) */
5198 MATHTYPE a;
5199 a = random_greater (0);
5200 check_isinfp_ext ("cabs (+inf + i x) == +inf",
5201 FUNC(cabs) (BUILD_COMPLEX (plus_infty, a)), a);
5202 check_isinfp_ext ("cabs (-inf + i x) == +inf",
5203 FUNC(cabs) (BUILD_COMPLEX (minus_infty, a)), a);
5205 check_isinfp ("cabs (+inf+ iNaN) == +inf",
5206 FUNC(cabs) (BUILD_COMPLEX(minus_infty, nan_value)));
5207 check_isinfp ("cabs (-inf+ iNaN) == +inf",
5208 FUNC(cabs) (BUILD_COMPLEX(minus_infty, nan_value)));
5210 check_isnan ("cabs (NaN+ iNaN) == NaN",
5211 FUNC(cabs) (BUILD_COMPLEX(nan_value, nan_value)));
5213 a = FUNC(cabs) (BUILD_COMPLEX (12.4L, 0.7L));
5214 check ("cabs (x,y) == cabs (y,x)",
5215 FUNC(cabs) (BUILD_COMPLEX(0.7L, 12.4L)), a);
5216 check ("cabs (x,y) == cabs (-x,y)",
5217 FUNC(cabs) (BUILD_COMPLEX(-12.4L, 0.7L)), a);
5218 check ("cabs (x,y) == cabs (-y,x)",
5219 FUNC(cabs) (BUILD_COMPLEX(-0.7L, 12.4L)), a);
5220 check ("cabs (x,y) == cabs (-x,-y)",
5221 FUNC(cabs) (BUILD_COMPLEX(-12.4L, -0.7L)), a);
5222 check ("cabs (x,y) == cabs (-y,-x)",
5223 FUNC(cabs) (BUILD_COMPLEX(-0.7L, -12.4L)), a);
5224 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-0.7L, 0)), 0.7L);
5225 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(0.7L, 0)), 0.7L);
5226 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-1.0L, 0)), 1.0L);
5227 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(1.0L, 0)), 1.0L);
5228 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-5.7e7L, 0)),
5229 5.7e7L);
5230 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(5.7e7L, 0)),
5231 5.7e7L);
5233 check_eps ("cabs (0.7 + i 1.2) == 1.38924...", FUNC(cabs) (BUILD_COMPLEX(0.7, 1.2)),
5234 1.3892443989449804508L, CHOOSE(7e-17L, 3e-16, 0));
5238 static void
5239 carg_test (void)
5241 /* carg (x + iy) is specified as atan2 (y, x) */
5242 MATHTYPE x;
5244 x = random_greater (0);
5245 check ("carg (x + i 0) == 0 for x > 0",
5246 FUNC(carg) (BUILD_COMPLEX(x, 0)), 0);
5247 x = random_greater (0);
5248 check ("carg (x - i 0) == -0 for x > 0",
5249 FUNC(carg) (BUILD_COMPLEX(x, minus_zero)), minus_zero);
5251 check ("carg (+0 + i 0) == +0", FUNC(carg) (BUILD_COMPLEX(0, 0)), 0);
5252 check ("carg (+0 - i 0) == -0", FUNC(carg) (BUILD_COMPLEX(0, minus_zero)),
5253 minus_zero);
5255 x = -random_greater (0);
5256 check ("carg (x + i 0) == +pi for x < 0", FUNC(carg) (BUILD_COMPLEX(x, 0)),
5257 M_PIl);
5259 x = -random_greater (0);
5260 check ("carg (x - i 0) == -pi for x < 0",
5261 FUNC(carg) (BUILD_COMPLEX(x, minus_zero)), -M_PIl);
5263 check ("carg (-0 + i 0) == +pi", FUNC(carg) (BUILD_COMPLEX(minus_zero, 0)),
5264 M_PIl);
5265 check ("carg (-0 - i 0) == -pi",
5266 FUNC(carg) (BUILD_COMPLEX(minus_zero, minus_zero)), -M_PIl);
5268 x = random_greater (0);
5269 check ("carg (+0 + i y) == pi/2 for y > 0", FUNC(carg) (BUILD_COMPLEX(0, x)),
5270 M_PI_2l);
5272 x = random_greater (0);
5273 check ("carg (-0 + i y) == pi/2 for y > 0",
5274 FUNC(carg) (BUILD_COMPLEX(minus_zero, x)), M_PI_2l);
5276 x = random_less (0);
5277 check ("carg (+0 + i y) == -pi/2 for y < 0", FUNC(carg) (BUILD_COMPLEX(0, x)),
5278 -M_PI_2l);
5280 x = random_less (0);
5281 check ("carg (-0 + i y) == -pi/2 for y < 0",
5282 FUNC(carg) (BUILD_COMPLEX(minus_zero, x)), -M_PI_2l);
5284 x = random_greater (0);
5285 check ("carg (inf + i y) == +0 for finite y > 0",
5286 FUNC(carg) (BUILD_COMPLEX(plus_infty, x)), 0);
5288 x = -random_greater (0);
5289 check ("carg (inf + i y) == -0 for finite y < 0",
5290 FUNC(carg) (BUILD_COMPLEX(plus_infty, x)), minus_zero);
5292 x = random_value (-1e4, 1e4);
5293 check ("carg(x + i inf) == pi/2 for finite x",
5294 FUNC(carg) (BUILD_COMPLEX(x, plus_infty)), M_PI_2l);
5296 x = random_value (-1e4, 1e4);
5297 check ("carg(x - i inf) == -pi/2 for finite x",
5298 FUNC(carg) (BUILD_COMPLEX(x, minus_infty)), -M_PI_2l);
5300 x = random_greater (0);
5301 check ("carg (-inf + i y) == +pi for finite y > 0",
5302 FUNC(carg) (BUILD_COMPLEX(minus_infty, x)), M_PIl);
5304 x = -random_greater (0);
5305 check ("carg (-inf + i y) == -pi for finite y < 0",
5306 FUNC(carg) (BUILD_COMPLEX(minus_infty, x)), -M_PIl);
5308 check ("carg (+inf + i inf) == +pi/4",
5309 FUNC(carg) (BUILD_COMPLEX(plus_infty, plus_infty)), M_PI_4l);
5311 check ("carg (+inf -i inf) == -pi/4",
5312 FUNC(carg) (BUILD_COMPLEX(plus_infty, minus_infty)), -M_PI_4l);
5314 check ("carg (-inf +i inf) == +3*pi/4",
5315 FUNC(carg) (BUILD_COMPLEX(minus_infty, plus_infty)), 3 * M_PI_4l);
5317 check ("carg (-inf -i inf) == -3*pi/4",
5318 FUNC(carg) (BUILD_COMPLEX(minus_infty, minus_infty)), -3 * M_PI_4l);
5323 static void
5324 nearbyint_test (void)
5326 check ("nearbyint(+0) = 0", FUNC(nearbyint) (0.0), 0.0);
5327 check ("nearbyint(-0) = -0", FUNC(nearbyint) (minus_zero), minus_zero);
5328 check_isinfp ("nearbyint(+Inf) = +Inf", FUNC(nearbyint) (plus_infty));
5329 check_isinfn ("nearbyint(-Inf) = -Inf", FUNC(nearbyint) (minus_infty));
5333 static void
5334 rint_test (void)
5336 check ("rint(0) = 0", FUNC(rint) (0.0), 0.0);
5337 check ("rint(-0) = -0", FUNC(rint) (minus_zero), minus_zero);
5338 check_isinfp ("rint(+Inf) = +Inf", FUNC(rint) (plus_infty));
5339 check_isinfn ("rint(-Inf) = -Inf", FUNC(rint) (minus_infty));
5343 static void
5344 lrint_test (void)
5346 /* XXX this test is incomplete. We need to have a way to specifiy
5347 the rounding method and test the critical cases. So far, only
5348 unproblematic numbers are tested. */
5350 check_long ("lrint(0) = 0", FUNC(lrint) (0.0), 0);
5351 check_long ("lrint(-0) = 0", FUNC(lrint) (minus_zero), 0);
5352 check_long ("lrint(0.2) = 0", FUNC(lrint) (0.2), 0);
5353 check_long ("lrint(-0.2) = 0", FUNC(lrint) (-0.2), 0);
5355 check_long ("lrint(1.4) = 1", FUNC(lrint) (1.4), 1);
5356 check_long ("lrint(-1.4) = -1", FUNC(lrint) (-1.4), -1);
5358 check_long ("lrint(8388600.3) = 8388600", FUNC(lrint) (8388600.3), 8388600);
5359 check_long ("lrint(-8388600.3) = -8388600", FUNC(lrint) (-8388600.3),
5360 -8388600);
5364 static void
5365 llrint_test (void)
5367 /* XXX this test is incomplete. We need to have a way to specifiy
5368 the rounding method and test the critical cases. So far, only
5369 unproblematic numbers are tested. */
5371 check_longlong ("llrint(0) = 0", FUNC(llrint) (0.0), 0);
5372 check_longlong ("llrint(-0) = 0", FUNC(llrint) (minus_zero), 0);
5373 check_longlong ("llrint(0.2) = 0", FUNC(llrint) (0.2), 0);
5374 check_longlong ("llrint(-0.2) = 0", FUNC(llrint) (-0.2), 0);
5376 check_longlong ("llrint(1.4) = 1", FUNC(llrint) (1.4), 1);
5377 check_longlong ("llrint(-1.4) = -1", FUNC(llrint) (-1.4), -1);
5379 check_longlong ("llrint(8388600.3) = 8388600", FUNC(llrint) (8388600.3),
5380 8388600);
5381 check_longlong ("llrint(-8388600.3) = -8388600", FUNC(llrint) (-8388600.3),
5382 -8388600);
5384 /* Test boundary conditions. */
5385 /* 0x1FFFFF */
5386 check_longlong ("llrint(2097151.0) = 2097151", FUNC(llrint) (2097151.0),
5387 2097151LL);
5388 /* 0x800000 */
5389 check_longlong ("llrint(8388608.0) = 8388608", FUNC(llrint) (8388608.0),
5390 8388608LL);
5391 /* 0x1000000 */
5392 check_longlong ("llrint(16777216.0) = 16777216",
5393 FUNC(llrint) (16777216.0), 16777216LL);
5394 /* 0x20000000000 */
5395 check_longlong ("llrint(2199023255552.0) = 2199023255552",
5396 FUNC(llrint) (2199023255552.0), 2199023255552LL);
5397 /* 0x40000000000 */
5398 check_longlong ("llrint(4398046511104.0) = 4398046511104",
5399 FUNC(llrint) (4398046511104.0), 4398046511104LL);
5400 /* 0x10000000000000 */
5401 check_longlong ("llrint(4503599627370496.0) = 4503599627370496",
5402 FUNC(llrint) (4503599627370496.0), 4503599627370496LL);
5403 /* 0x10000080000000 */
5404 check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5405 FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5406 /* 0x20000000000000 */
5407 check_longlong ("llrint(9007199254740992.0) = 9007199254740992",
5408 FUNC(llrint) (9007199254740992.0), 9007199254740992LL);
5409 /* 0x80000000000000 */
5410 check_longlong ("llrint(36028797018963968.0) = 36028797018963968",
5411 FUNC(llrint) (36028797018963968.0), 36028797018963968LL);
5412 /* 0x100000000000000 */
5413 check_longlong ("llrint(72057594037927936.0) = 72057594037927936",
5414 FUNC(llrint) (72057594037927936.0), 72057594037927936LL);
5418 static void
5419 round_test (void)
5421 check ("round(0) = 0", FUNC(round) (0), 0);
5422 check ("round(-0) = -0", FUNC(round) (minus_zero), minus_zero);
5423 check ("round(0.2) = 0", FUNC(round) (0.2), 0.0);
5424 check ("round(-0.2) = -0", FUNC(round) (-0.2), minus_zero);
5425 check ("round(0.5) = 1", FUNC(round) (0.5), 1.0);
5426 check ("round(-0.5) = -1", FUNC(round) (-0.5), -1.0);
5427 check ("round(0.8) = 1", FUNC(round) (0.8), 1.0);
5428 check ("round(-0.8) = -1", FUNC(round) (-0.8), -1.0);
5429 check ("round(1.5) = 2", FUNC(round) (1.5), 2.0);
5430 check ("round(-1.5) = -2", FUNC(round) (-1.5), -2.0);
5431 check ("round(2097152.5) = 2097153", FUNC(round) (2097152.5), 2097153);
5432 check ("round(-2097152.5) = -2097153", FUNC(round) (-2097152.5), -2097153);
5436 static void
5437 lround_test (void)
5439 check_long ("lround(0) = 0", FUNC(lround) (0), 0);
5440 check_long ("lround(-0) = 0", FUNC(lround) (minus_zero), 0);
5441 check_long ("lround(0.2) = 0", FUNC(lround) (0.2), 0.0);
5442 check_long ("lround(-0.2) = 0", FUNC(lround) (-0.2), 0);
5443 check_long ("lround(0.5) = 1", FUNC(lround) (0.5), 1);
5444 check_long ("lround(-0.5) = -1", FUNC(lround) (-0.5), -1);
5445 check_long ("lround(0.8) = 1", FUNC(lround) (0.8), 1);
5446 check_long ("lround(-0.8) = -1", FUNC(lround) (-0.8), -1);
5447 check_long ("lround(1.5) = 2", FUNC(lround) (1.5), 2);
5448 check_long ("lround(-1.5) = -2", FUNC(lround) (-1.5), -2);
5449 check_long ("lround(22514.5) = 22515", FUNC(lround) (22514.5), 22515);
5450 check_long ("lround(-22514.5) = -22515", FUNC(lround) (-22514.5), -22515);
5451 #ifndef TEST_FLOAT
5452 check_long ("lround(2097152.5) = 2097153", FUNC(lround) (2097152.5),
5453 2097153);
5454 check_long ("lround(-2097152.5) = -2097153", FUNC(lround) (-2097152.5),
5455 -2097153);
5456 #endif
5460 static void
5461 llround_test (void)
5463 check_longlong ("llround(0) = 0", FUNC(llround) (0), 0);
5464 check_longlong ("llround(-0) = 0", FUNC(llround) (minus_zero), 0);
5465 check_longlong ("llround(0.2) = 0", FUNC(llround) (0.2), 0.0);
5466 check_longlong ("llround(-0.2) = 0", FUNC(llround) (-0.2), 0);
5467 check_longlong ("llround(0.5) = 1", FUNC(llround) (0.5), 1);
5468 check_longlong ("llround(-0.5) = -1", FUNC(llround) (-0.5), -1);
5469 check_longlong ("llround(0.8) = 1", FUNC(llround) (0.8), 1);
5470 check_longlong ("llround(-0.8) = -1", FUNC(llround) (-0.8), -1);
5471 check_longlong ("llround(1.5) = 2", FUNC(llround) (1.5), 2);
5472 check_longlong ("llround(-1.5) = -2", FUNC(llround) (-1.5), -2);
5473 check_longlong ("llround(22514.5) = 22515", FUNC(llround) (22514.5), 22515);
5474 check_longlong ("llround(-22514.5) = -22515", FUNC(llround) (-22514.5),
5475 -22515);
5476 #ifndef TEST_FLOAT
5477 check_longlong ("llround(2097152.5) = 2097153",
5478 FUNC(llround) (2097152.5), 2097153);
5479 check_longlong ("llround(-2097152.5) = -2097153",
5480 FUNC(llround) (-2097152.5), -2097153);
5481 check_longlong ("llround(34359738368.5) = 34359738369",
5482 FUNC(llround) (34359738368.5), 34359738369ll);
5483 check_longlong ("llround(-34359738368.5) = -34359738369",
5484 FUNC(llround) (-34359738368.5), -34359738369ll);
5485 #endif
5487 /* Test boundary conditions. */
5488 /* 0x1FFFFF */
5489 check_longlong ("llround(2097151.0) = 2097151", FUNC(llround) (2097151.0),
5490 2097151LL);
5491 /* 0x800000 */
5492 check_longlong ("llround(8388608.0) = 8388608", FUNC(llround) (8388608.0),
5493 8388608LL);
5494 /* 0x1000000 */
5495 check_longlong ("llround(16777216.0) = 16777216",
5496 FUNC(llround) (16777216.0), 16777216LL);
5497 /* 0x20000000000 */
5498 check_longlong ("llround(2199023255552.0) = 2199023255552",
5499 FUNC(llround) (2199023255552.0), 2199023255552LL);
5500 /* 0x40000000000 */
5501 check_longlong ("llround(4398046511104.0) = 4398046511104",
5502 FUNC(llround) (4398046511104.0), 4398046511104LL);
5503 /* 0x10000000000000 */
5504 check_longlong ("llround(4503599627370496.0) = 4503599627370496",
5505 FUNC(llround) (4503599627370496.0), 4503599627370496LL);
5506 /* 0x10000080000000 */
5507 check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5508 FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5509 /* 0x20000000000000 */
5510 check_longlong ("llround(9007199254740992.0) = 9007199254740992",
5511 FUNC(llround) (9007199254740992.0), 9007199254740992LL);
5512 /* 0x80000000000000 */
5513 check_longlong ("llround(36028797018963968.0) = 36028797018963968",
5514 FUNC(llround) (36028797018963968.0), 36028797018963968LL);
5515 /* 0x100000000000000 */
5516 check_longlong ("llround(72057594037927936.0) = 72057594037927936",
5517 FUNC(llround) (72057594037927936.0), 72057594037927936LL);
5521 static void
5522 fma_test (void)
5524 check ("fma(1.0, 2.0, 3.0) = 5.0", FUNC(fma) (1.0, 2.0, 3.0), 5.0);
5525 check_isnan ("fma(NaN, 2.0, 3.0) = NaN", FUNC(fma) (nan_value, 2.0, 3.0));
5526 check_isnan ("fma(1.0, NaN, 3.0) = NaN", FUNC(fma) (1.0, nan_value, 3.0));
5527 check_isnan_maybe_exc ("fma(1.0, 2.0, NaN) = NaN",
5528 FUNC(fma) (1.0, 2.0, nan_value), INVALID_EXCEPTION);
5529 check_isnan_maybe_exc ("fma(+Inf, 0.0, NaN) = NaN",
5530 FUNC(fma) (plus_infty, 0.0, nan_value),
5531 INVALID_EXCEPTION);
5532 check_isnan_maybe_exc ("fma(-Inf, 0.0, NaN) = NaN",
5533 FUNC(fma) (minus_infty, 0.0, nan_value),
5534 INVALID_EXCEPTION);
5535 check_isnan_maybe_exc ("fma(0.0, +Inf, NaN) = NaN",
5536 FUNC(fma) (0.0, plus_infty, nan_value),
5537 INVALID_EXCEPTION);
5538 check_isnan_maybe_exc ("fma(0.0, -Inf, NaN) = NaN",
5539 FUNC(fma) (0.0, minus_infty, nan_value),
5540 INVALID_EXCEPTION);
5541 check_isnan_exc ("fma(+Inf, 0.0, 1.0) = NaN",
5542 FUNC(fma) (plus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5543 check_isnan_exc ("fma(-Inf, 0.0, 1.0) = NaN",
5544 FUNC(fma) (minus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5545 check_isnan_exc ("fma(0.0, +Inf, 1.0) = NaN",
5546 FUNC(fma) (0.0, plus_infty, 1.0), INVALID_EXCEPTION);
5547 check_isnan_exc ("fma(0.0, -Inf, 1.0) = NaN",
5548 FUNC(fma) (0.0, minus_infty, 1.0), INVALID_EXCEPTION);
5550 check_isnan_exc ("fma(+Inf, +Inf, -Inf) = NaN",
5551 FUNC(fma) (plus_infty, plus_infty, minus_infty),
5552 INVALID_EXCEPTION);
5553 check_isnan_exc ("fma(-Inf, +Inf, +Inf) = NaN",
5554 FUNC(fma) (minus_infty, plus_infty, plus_infty),
5555 INVALID_EXCEPTION);
5556 check_isnan_exc ("fma(+Inf, -Inf, +Inf) = NaN",
5557 FUNC(fma) (plus_infty, minus_infty, plus_infty),
5558 INVALID_EXCEPTION);
5559 check_isnan_exc ("fma(-Inf, -Inf, -Inf) = NaN",
5560 FUNC(fma) (minus_infty, minus_infty, minus_infty),
5561 INVALID_EXCEPTION);
5566 Tests for the comparison macros
5568 typedef enum {is_less, is_equal, is_greater, is_unordered} comp_result;
5571 static void
5572 comparison2_test (MATHTYPE x, MATHTYPE y, comp_result comp)
5574 char buf[255];
5575 int result;
5576 int expected;
5578 expected = (comp == is_greater);
5579 sprintf (buf, "isgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5580 expected);
5581 result = (isgreater (x, y) == expected);
5582 check_bool (buf, result);
5584 expected = (comp == is_greater || comp == is_equal);
5585 sprintf (buf, "isgreaterequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5586 expected);
5587 result = (isgreaterequal (x, y) == expected);
5588 check_bool (buf, result);
5590 expected = (comp == is_less);
5591 sprintf (buf, "isless (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5592 expected);
5593 result = (isless (x, y) == expected);
5594 check_bool (buf, result);
5596 expected = (comp == is_less || comp == is_equal);
5597 sprintf (buf, "islessequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5598 expected);
5599 result = (islessequal (x, y) == expected);
5600 check_bool (buf, result);
5602 expected = (comp == is_greater || comp == is_less);
5603 sprintf (buf, "islessgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5604 expected);
5605 result = (islessgreater (x, y) == expected);
5606 check_bool (buf, result);
5608 expected = (comp == is_unordered);
5609 sprintf (buf, "isunordered (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5610 expected);
5611 result = (isunordered (x, y) == expected);
5612 check_bool (buf, result);
5617 static void
5618 comparison1_test (MATHTYPE x, MATHTYPE y, comp_result comp)
5620 comp_result comp_swap;
5621 switch (comp)
5623 case is_less:
5624 comp_swap = is_greater;
5625 break;
5626 case is_greater:
5627 comp_swap = is_less;
5628 break;
5629 default:
5630 comp_swap = comp;
5631 break;
5633 comparison2_test (x, y, comp);
5634 comparison2_test (y, x, comp_swap);
5638 static void
5639 comparisons_test (void)
5641 comparison1_test (1, 2, is_less);
5642 comparison1_test (-30, 30, is_less);
5643 comparison1_test (42, 42, is_equal);
5644 comparison1_test (1, plus_infty, is_less);
5645 comparison1_test (35, minus_infty, is_greater);
5646 comparison1_test (1, nan_value, is_unordered);
5647 comparison1_test (nan_value, nan_value, is_unordered);
5648 comparison1_test (plus_infty, nan_value, is_unordered);
5649 comparison1_test (minus_infty, nan_value, is_unordered);
5650 comparison1_test (plus_infty, minus_infty, is_greater);
5654 static void
5655 inverse_func_pair_test (const char *test_name,
5656 mathfunc f1, mathfunc inverse,
5657 MATHTYPE x, MATHTYPE epsilon)
5659 MATHTYPE a, b, difference;
5660 int result;
5662 a = f1 (x);
5663 (void) &a;
5664 b = inverse (a);
5665 (void) &b;
5667 output_new_test (test_name);
5668 result = check_equal (b, x, epsilon, &difference);
5669 output_result (test_name, result,
5670 b, x, difference, PRINT, PRINT);
5674 static void
5675 inverse_functions (void)
5677 inverse_func_pair_test ("asin(sin(x)) == x",
5678 FUNC(sin), FUNC(asin), 1.0,
5679 CHOOSE (2e-18L, 0, 3e-7L));
5680 inverse_func_pair_test ("sin(asin(x)) == x",
5681 FUNC(asin), FUNC(sin), 1.0, 0.0);
5683 inverse_func_pair_test ("acos(cos(x)) == x",
5684 FUNC(cos), FUNC(acos), 1.0,
5685 CHOOSE (4e-18L, 1e-15L, 0));
5686 inverse_func_pair_test ("cos(acos(x)) == x",
5687 FUNC(acos), FUNC(cos), 1.0, 0.0);
5688 inverse_func_pair_test ("atan(tan(x)) == x",
5689 FUNC(tan), FUNC(atan), 1.0, CHOOSE (2e-18L, 0, 0));
5690 inverse_func_pair_test ("tan(atan(x)) == x",
5691 FUNC(atan), FUNC(tan), 1.0,
5692 CHOOSE (2e-18L, 1e-15L, 2e-7));
5694 inverse_func_pair_test ("asinh(sinh(x)) == x",
5695 FUNC(sinh), FUNC(asinh), 1.0, CHOOSE (1e-18L, 0, 1e-7));
5696 inverse_func_pair_test ("sinh(asinh(x)) == x",
5697 FUNC(asinh), FUNC(sinh), 1.0,
5698 CHOOSE (2e-18L, 2e-16L, 2e-7));
5700 inverse_func_pair_test ("acosh(cosh(x)) == x",
5701 FUNC(cosh), FUNC(acosh), 1.0,
5702 CHOOSE (1e-18L, 1e-15L, 6e-8));
5703 inverse_func_pair_test ("cosh(acosh(x)) == x",
5704 FUNC(acosh), FUNC(cosh), 1.0, 0.0);
5706 inverse_func_pair_test ("atanh(tanh(x)) == x",
5707 FUNC(tanh), FUNC(atanh), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
5708 inverse_func_pair_test ("tanh(atanh(x)) == x",
5709 FUNC(atanh), FUNC(tanh), 1.0, 0.0);
5713 /* Test sin and cos with the identity: sin(x)^2 + cos(x)^2 = 1. */
5714 static void
5715 identities1_test (MATHTYPE x, MATHTYPE epsilon)
5717 MATHTYPE res1, res2, res3, diff;
5718 int result;
5720 res1 = FUNC(sin) (x);
5721 (void) &res1;
5722 res2 = FUNC(cos) (x);
5723 (void) &res2;
5724 res3 = res1 * res1 + res2 * res2;
5725 (void) &res3;
5727 output_new_test ("sin^2 + cos^2 == 1");
5728 result = check_equal (res3, 1.0, epsilon, &diff);
5729 output_result_ext ("sin^2 + cos^2 == 1", result,
5730 res3, 1.0, diff, x, PRINT, PRINT);
5734 /* Test sin, cos, tan with the following relation: tan = sin/cos. */
5735 static void
5736 identities2_test (MATHTYPE x, MATHTYPE epsilon)
5738 #ifndef TEST_INLINE
5739 MATHTYPE res1, res2, res3, res4, diff;
5740 int result;
5742 res1 = FUNC(sin) (x);
5743 (void) &res1;
5744 res2 = FUNC(cos) (x);
5745 (void) &res2;
5746 res3 = FUNC(tan) (x);
5747 (void) &res3;
5748 res4 = res1 / res2;
5749 (void) &res4;
5751 output_new_test ("sin/cos == tan");
5752 result = check_equal (res4, res3, epsilon, &diff);
5753 output_result_ext ("sin/cos == tan", result,
5754 res4, res3, diff, x, PRINT, PRINT);
5755 #endif
5759 /* Test cosh and sinh with the identity cosh^2 - sinh^2 = 1. */
5760 static void
5761 identities3_test (MATHTYPE x, MATHTYPE epsilon)
5763 MATHTYPE res1, res2, res3, diff;
5764 int result;
5766 res1 = FUNC(sinh) (x);
5767 (void) &res1;
5768 res2 = FUNC(cosh) (x);
5769 (void) &res2;
5770 res3 = res2 * res2 - res1 * res1;
5771 (void) &res3;
5773 output_new_test ("cosh^2 - sinh^2 == 1");
5774 result = check_equal (res3, 1.0, epsilon, &diff);
5775 output_result_ext ("cosh^2 - sinh^2 == 1", result,
5776 res3, 1.0, diff, x, PRINT, PRINT);
5780 static void
5781 identities (void)
5783 identities1_test (0.2L, CHOOSE (1e-18L, 0, 2e-7));
5784 identities1_test (0.9L, CHOOSE (1e-18L, 0, 2e-7));
5785 identities1_test (0, 0);
5786 identities1_test (-1, CHOOSE (1e-18L, 0, 1e-7));
5788 identities2_test (0.2L, CHOOSE (1e-19L, 1e-16, 0));
5789 identities2_test (0.9L, CHOOSE (3e-19L, 1e-15, 2e-7));
5790 identities2_test (0, 0);
5791 identities2_test (-1, CHOOSE (1e-18L, 1e-15, 2e-7));
5793 identities3_test (0.2L, CHOOSE (1e-18L, 0, 1e-7));
5794 identities3_test (0.9L, CHOOSE (1e-18L, 1e-15, 1e-6));
5795 identities3_test (0, CHOOSE (0, 0, 1e-6));
5796 identities3_test (-1, CHOOSE (1e-18L, 7e-16, 1e-6));
5801 Let's test that basic arithmetic is working
5802 tests: Infinity and NaN
5804 static void
5805 basic_tests (void)
5807 /* variables are declared volatile to forbid some compiler
5808 optimizations */
5809 volatile MATHTYPE Inf_var, NaN_var, zero_var, one_var;
5810 MATHTYPE x1, x2;
5812 zero_var = 0.0;
5813 one_var = 1.0;
5814 NaN_var = nan_value;
5815 Inf_var = one_var / zero_var;
5817 (void) &zero_var;
5818 (void) &one_var;
5819 (void) &NaN_var;
5820 (void) &Inf_var;
5822 /* Clear all exceptions. The previous computations raised exceptions. */
5823 feclearexcept (FE_ALL_EXCEPT);
5825 check_isinfp ("isinf (inf) == +1", Inf_var);
5826 check_isinfn ("isinf (-inf) == -1", -Inf_var);
5827 check_bool ("!isinf (1)", !(FUNC(isinf) (one_var)));
5828 check_bool ("!isinf (NaN)", !(FUNC(isinf) (NaN_var)));
5830 check_isnan ("isnan (NaN)", NaN_var);
5831 check_isnan ("isnan (-NaN)", -NaN_var);
5832 check_bool ("!isnan (1)", !(FUNC(isnan) (one_var)));
5833 check_bool ("!isnan (inf)", !(FUNC(isnan) (Inf_var)));
5835 check_bool ("inf == inf", Inf_var == Inf_var);
5836 check_bool ("-inf == -inf", -Inf_var == -Inf_var);
5837 check_bool ("inf != -inf", Inf_var != -Inf_var);
5838 check_bool ("NaN != NaN", NaN_var != NaN_var);
5841 the same tests but this time with NAN from <bits/nan.h>
5842 NAN is a double const
5844 check_bool ("isnan (NAN)", isnan (NAN));
5845 check_bool ("isnan (-NAN)", isnan (-NAN));
5846 check_bool ("!isinf (NAN)", !(isinf (NAN)));
5847 check_bool ("!isinf (-NAN)", !(isinf (-NAN)));
5848 check_bool ("NAN != NAN", NAN != NAN);
5851 And again with the value returned by the `nan' function.
5853 check_bool ("isnan (NAN)", FUNC(isnan) (FUNC(nan) ("")));
5854 check_bool ("isnan (-NAN)", FUNC(isnan) (-FUNC(nan) ("")));
5855 check_bool ("!isinf (NAN)", !(FUNC(isinf) (FUNC(nan) (""))));
5856 check_bool ("!isinf (-NAN)", !(FUNC(isinf) (-FUNC(nan) (""))));
5857 check_bool ("NAN != NAN", FUNC(nan) ("") != FUNC(nan) (""));
5859 /* test if EPSILON is ok */
5860 x1 = MATHCONST (1.0);
5861 x2 = x1 + CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
5862 check_bool ("1 != 1+EPSILON", x1 != x2);
5864 x1 = MATHCONST (1.0);
5865 x2 = x1 - CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
5866 check_bool ("1 != 1-EPSILON", x1 != x2);
5868 /* test if HUGE_VALx is ok */
5869 x1 = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5870 check_bool ("isinf (HUGE_VALx) == +1", ISINF (x1) == +1);
5871 x1 = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5872 check_bool ("isinf (-HUGE_VALx) == -1", ISINF (x1) == -1);
5877 static void
5878 initialize (void)
5880 fpstack_test ("start *init*");
5881 plus_zero = 0.0;
5882 nan_value = plus_zero / plus_zero; /* Suppress GCC warning */
5884 minus_zero = FUNC (copysign) (0.0, -1.0);
5885 plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5886 minus_infty = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5888 (void) &plus_zero;
5889 (void) &nan_value;
5890 (void) &minus_zero;
5891 (void) &plus_infty;
5892 (void) &minus_infty;
5894 /* Clear all exceptions. From now on we must not get random exceptions. */
5895 feclearexcept (FE_ALL_EXCEPT);
5897 /* Test to make sure we start correctly. */
5898 fpstack_test ("end *init*");
5902 static struct option long_options[] =
5904 {"verbose", optional_argument, NULL, 'v'},
5905 {"silent", no_argument, NULL, 's'},
5906 {0, 0, 0, 0}
5910 static void
5911 parse_options (int argc, char *argv[])
5913 int c;
5914 int option_index;
5916 verbose = 1;
5918 while (1)
5920 c = getopt_long (argc, argv, "v::s",
5921 long_options, &option_index);
5923 /* Detect the end of the options. */
5924 if (c == -1)
5925 break;
5927 switch (c)
5929 case 'v':
5930 if (optarg)
5931 verbose = (unsigned int) strtoul (optarg, NULL, 0);
5932 else
5933 verbose = 4;
5934 break;
5935 case 's':
5936 verbose = 0;
5937 default:
5938 break;
5945 main (int argc, char *argv[])
5948 parse_options (argc, argv);
5950 initialize ();
5951 printf (TEST_MSG);
5953 basic_tests ();
5955 /* keep the tests a wee bit ordered (according to ISO 9X) */
5956 /* classification functions */
5957 fpclassify_test ();
5958 isfinite_test ();
5959 isnormal_test ();
5960 signbit_test ();
5962 comparisons_test ();
5964 /* trigonometric functions */
5965 acos_test ();
5966 asin_test ();
5967 atan_test ();
5968 atan2_test ();
5969 cos_test ();
5970 sin_test ();
5971 sincos_test ();
5972 tan_test ();
5974 /* hyperbolic functions */
5975 acosh_test ();
5976 asinh_test ();
5977 atanh_test ();
5978 cosh_test ();
5979 sinh_test ();
5980 tanh_test ();
5982 /* exponential and logarithmic functions */
5983 exp_test ();
5984 exp10_test ();
5985 exp2_test ();
5986 expm1_test ();
5987 frexp_test ();
5988 ldexp_test ();
5989 log_test ();
5990 log10_test ();
5991 log1p_test ();
5992 log2_test ();
5993 logb_test ();
5994 modf_test ();
5995 ilogb_test ();
5996 scalb_test ();
5997 scalbn_test ();
5999 /* power and absolute value functions */
6000 cbrt_test ();
6001 fabs_test ();
6002 hypot_test ();
6003 pow_test ();
6004 sqrt_test ();
6006 /* error and gamma functions */
6007 erf_test ();
6008 erfc_test ();
6009 gamma_test ();
6010 lgamma_test ();
6012 /* nearest integer functions */
6013 ceil_test ();
6014 floor_test ();
6015 nearbyint_test ();
6016 rint_test ();
6017 lrint_test ();
6018 llrint_test ();
6019 round_test ();
6020 lround_test ();
6021 llround_test ();
6022 trunc_test ();
6024 /* remainder functions */
6025 fmod_test ();
6026 remainder_test ();
6027 remquo_test ();
6029 /* manipulation functions */
6030 copysign_test ();
6031 nextafter_test ();
6033 /* maximum, minimum and positive difference functions */
6034 fdim_test ();
6035 fmin_test ();
6036 fmax_test ();
6038 /* complex functions */
6039 cabs_test ();
6040 carg_test ();
6041 cexp_test ();
6042 csin_test ();
6043 csinh_test ();
6044 ccos_test ();
6045 ccosh_test ();
6046 clog_test ();
6047 clog10_test ();
6048 cacos_test ();
6049 cacosh_test ();
6050 casin_test ();
6051 casinh_test ();
6052 catan_test ();
6053 catanh_test ();
6054 ctan_test ();
6055 ctanh_test ();
6056 csqrt_test ();
6057 cpow_test ();
6059 /* multiply and add */
6060 fma_test ();
6062 /* special tests */
6063 identities ();
6064 inverse_functions ();
6066 printf ("\nTest suite completed:\n");
6067 printf (" %d test cases plus %d tests for exception flags executed.\n",
6068 noTests, noExcTests);
6069 if (noErrors)
6071 printf (" %d errors occured.\n", noErrors);
6072 exit (1);
6074 printf (" All tests passed successfully.\n");
6075 exit (0);