Update.
[glibc.git] / math / libm-test.c
blob40838f57d4abcfb3def463ecb0d326e99fb133d7
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, 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 exp2_test (void)
1197 errno = 0;
1198 FUNC(exp2) (0);
1199 if (errno == ENOSYS)
1200 /* Function not implemented. */
1201 return;
1203 check ("exp2 (+0) == 1", FUNC(exp2) (0), 1);
1204 check ("exp2 (-0) == 1", FUNC(exp2) (minus_zero), 1);
1206 check_isinfp ("exp2 (+inf) == +inf", FUNC(exp2) (plus_infty));
1207 check ("exp2 (-inf) == 0", FUNC(exp2) (minus_infty), 0);
1208 check ("exp2 (10) == 1024", FUNC(exp2) (10), 1024);
1209 check ("exp2 (-1) == 0.5", FUNC(exp2) (-1), 0.5);
1210 check_isinfp ("exp2 (1e6) == +inf", FUNC(exp2) (1e6));
1211 check ("exp2 (-1e6) == 0", FUNC(exp2) (-1e6), 0);
1212 check_eps ("exp2 (0.7) == 1.6245047927...", FUNC(exp2) (0.7),
1213 1.6245047927124710452L, CHOOSE(6e-17L, 0, 6e-8));
1217 static void
1218 expm1_test (void)
1220 check ("expm1 (+0) == 0", FUNC(expm1) (0), 0);
1221 #ifndef TEST_INLINE
1222 check ("expm1 (-0) == -0", FUNC(expm1) (minus_zero), minus_zero);
1224 check_isinfp ("expm1 (+inf) == +inf", FUNC(expm1) (plus_infty));
1225 check ("expm1 (-inf) == -1", FUNC(expm1) (minus_infty), -1);
1226 #endif
1228 check_eps ("expm1 (1) == e-1", FUNC(expm1) (1), M_El - 1.0,
1229 CHOOSE (4e-18L, 0, 2e-7));
1231 check_eps ("expm1 (0.7) == 1.01375...", FUNC(expm1) (0.7),
1232 1.0137527074704765216L, CHOOSE(9e-17L, 0, 0));
1238 static void
1239 check_frexp (const char *test_name, MATHTYPE computed, MATHTYPE expected,
1240 int comp_int, int exp_int)
1242 MATHTYPE diff;
1243 int result;
1245 result = (check_equal (computed, expected, 0, &diff)
1246 && (comp_int == exp_int));
1248 if (result)
1250 if (verbose > 2)
1251 printf ("Pass: %s\n", test_name);
1253 else
1255 if (verbose)
1256 printf ("Fail: %s\n", test_name);
1257 if (verbose > 1)
1259 printf ("Result:\n");
1260 printf (" is: %.20" PRINTF_EXPR " *2^%d %.20"
1261 PRINTF_XEXPR "*2^%d\n",
1262 computed, comp_int, computed, comp_int);
1263 printf (" should be: %.20" PRINTF_EXPR " *2^%d %.20"
1264 PRINTF_XEXPR "*2^%d\n",
1265 expected, exp_int, expected, exp_int);
1266 printf (" difference: %.20" PRINTF_EXPR " %.20" PRINTF_XEXPR "\n",
1267 diff, diff);
1269 noErrors++;
1271 fpstack_test (test_name);
1272 output_result (test_name, result,
1273 computed, expected, diff, PRINT, PRINT);
1277 static void
1278 frexp_test (void)
1280 int x_int;
1281 MATHTYPE result;
1283 result = FUNC(frexp) (plus_infty, &x_int);
1284 check_isinfp ("frexp (+inf, expr) == +inf", result);
1286 result = FUNC(frexp) (minus_infty, &x_int);
1287 check_isinfn ("frexp (-inf, expr) == -inf", result);
1289 result = FUNC(frexp) (nan_value, &x_int);
1290 check_isnan ("frexp (Nan, expr) == NaN", result);
1292 result = FUNC(frexp) (0, &x_int);
1293 check_frexp ("frexp: +0 == 0 * 2^0", result, 0, x_int, 0);
1295 result = FUNC(frexp) (minus_zero, &x_int);
1296 check_frexp ("frexp: -0 == -0 * 2^0", result, minus_zero, x_int, 0);
1298 result = FUNC(frexp) (12.8L, &x_int);
1299 check_frexp ("frexp: 12.8 == 0.8 * 2^4", result, 0.8L, x_int, 4);
1301 result = FUNC(frexp) (-27.34L, &x_int);
1302 check_frexp ("frexp: -27.34 == -0.854375 * 2^5", result, -0.854375L, x_int, 5);
1307 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)
1308 /* All floating-point numbers can be put in one of these categories. */
1309 enum
1311 FP_NAN,
1312 #define FP_NAN FP_NAN
1313 FP_INFINITE,
1314 #define FP_INFINITE FP_INFINITE
1315 FP_ZERO,
1316 #define FP_ZERO FP_ZERO
1317 FP_SUBNORMAL,
1318 #define FP_SUBNORMAL FP_SUBNORMAL
1319 FP_NORMAL
1320 #define FP_NORMAL FP_NORMAL
1322 #endif
1325 static void
1326 fpclassify_test (void)
1328 MATHTYPE x;
1330 /* fpclassify is a macro, don't give it constants as parameter */
1331 check_bool ("fpclassify (NaN) == FP_NAN", fpclassify (nan_value) == FP_NAN);
1332 check_bool ("fpclassify (+inf) == FP_INFINITE",
1333 fpclassify (plus_infty) == FP_INFINITE);
1334 check_bool ("fpclassify (-inf) == FP_INFINITE",
1335 fpclassify (minus_infty) == FP_INFINITE);
1336 check_bool ("fpclassify (+0) == FP_ZERO",
1337 fpclassify (plus_zero) == FP_ZERO);
1338 check_bool ("fpclassify (-0) == FP_ZERO",
1339 fpclassify (minus_zero) == FP_ZERO);
1341 x = 1000.0;
1342 check_bool ("fpclassify (1000) == FP_NORMAL",
1343 fpclassify (x) == FP_NORMAL);
1347 static void
1348 isfinite_test (void)
1350 check_bool ("isfinite (0) != 0", isfinite (0));
1351 check_bool ("isfinite (-0) != 0", isfinite (minus_zero));
1352 check_bool ("isfinite (10) != 0", isfinite (10));
1353 check_bool ("isfinite (+inf) == 0", isfinite (plus_infty) == 0);
1354 check_bool ("isfinite (-inf) == 0", isfinite (minus_infty) == 0);
1355 check_bool ("isfinite (NaN) == 0", isfinite (nan_value) == 0);
1359 static void
1360 isnormal_test (void)
1362 check_bool ("isnormal (0) == 0", isnormal (0) == 0);
1363 check_bool ("isnormal (-0) == 0", isnormal (minus_zero) == 0);
1364 check_bool ("isnormal (10) != 0", isnormal (10));
1365 check_bool ("isnormal (+inf) == 0", isnormal (plus_infty) == 0);
1366 check_bool ("isnormal (-inf) == 0", isnormal (minus_infty) == 0);
1367 check_bool ("isnormal (NaN) == 0", isnormal (nan_value) == 0);
1372 static void
1373 signbit_test (void)
1375 MATHTYPE x;
1377 check_bool ("signbit (+0) == 0", signbit (0) == 0);
1378 check_bool ("signbit (-0) != 0", signbit (minus_zero));
1379 check_bool ("signbit (+inf) == 0", signbit (plus_infty) == 0);
1380 check_bool ("signbit (-inf) != 0", signbit (minus_infty));
1382 x = random_less (0);
1383 check_bool ("signbit (x) != 0 for x < 0", signbit (x));
1385 x = random_greater (0);
1386 check_bool ("signbit (x) == 0 for x > 0", signbit (x) == 0);
1392 gamma has different semantics depending on _LIB_VERSION:
1393 if _LIB_VERSION is _SVID, gamma is just an alias for lgamma,
1394 otherwise gamma is the real gamma function as definied in ISO C 9X.
1396 static void
1397 gamma_test (void)
1399 int save_lib_version = _LIB_VERSION;
1400 errno = 0;
1401 FUNC(gamma) (1);
1402 if (errno == ENOSYS)
1403 /* Function not implemented. */
1404 return;
1405 feclearexcept (FE_ALL_EXCEPT);
1408 _LIB_VERSION = _SVID_;
1410 check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
1411 check_isinfp_exc ("gamma (0) == +inf plus divide by zero exception",
1412 FUNC(gamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1414 check_isinfp_exc ("gamma (x) == +inf plus divide by zero exception for integer x <= 0",
1415 FUNC(gamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1416 check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
1417 FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
1419 signgam = 0;
1420 check ("gamma (1) == 0", FUNC(gamma) (1), 0);
1421 check_int ("gamma (0) sets signgam to 1", signgam, 1);
1423 signgam = 0;
1424 check ("gamma (3) == M_LN2", FUNC(gamma) (3), M_LN2l);
1425 check_int ("gamma (3) sets signgam to 1", signgam, 1);
1427 signgam = 0;
1428 check_eps ("gamma (0.5) == log(sqrt(pi))", FUNC(gamma) (0.5),
1429 FUNC(log) (FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 1e-7));
1430 check_int ("gamma (0.5) sets signgam to 1", signgam, 1);
1432 signgam = 0;
1433 check_eps ("gamma (-0.5) == log(2*sqrt(pi))", FUNC(gamma) (-0.5),
1434 FUNC(log) (2*FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 0));
1436 check_int ("gamma (-0.5) sets signgam to -1", signgam, -1);
1439 _LIB_VERSION = _IEEE_;
1441 check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
1442 check_isnan_exc ("gamma (0) == NaN plus invalid exception",
1443 FUNC(gamma) (0), INVALID_EXCEPTION);
1445 check_isnan_exc_ext ("gamma (x) == NaN plus invalid exception for integer x <= 0",
1446 FUNC(gamma) (-2), INVALID_EXCEPTION, -2);
1447 check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
1448 FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
1450 #ifdef TODO
1451 check_eps ("gamma (0.5) == sqrt(pi)", FUNC(gamma) (0.5), FUNC(sqrt) (M_PIl),
1452 CHOOSE (0, 5e-16, 2e-7));
1453 #endif
1454 check_eps ("gamma (-0.5) == -2*sqrt(pi)", FUNC(gamma) (-0.5),
1455 -2*FUNC(sqrt) (M_PIl), CHOOSE (0, 5e-16, 3e-7));
1457 check ("gamma (1) == 1", FUNC(gamma) (1), 1);
1458 check ("gamma (4) == 6", FUNC(gamma) (4), 6);
1460 check_eps ("gamma (0.7) == 1.29805...", FUNC(gamma) (0.7),
1461 1.29805533264755778568L, CHOOSE(0, 3e-16, 2e-7));
1462 check ("gamma (1.2) == 0.91816...", FUNC(gamma) (1.2), 0.91816874239976061064L);
1464 _LIB_VERSION = save_lib_version;
1468 static void
1469 lgamma_test (void)
1471 errno = 0;
1472 FUNC(lgamma) (0);
1473 if (errno == ENOSYS)
1474 /* Function not implemented. */
1475 return;
1476 feclearexcept (FE_ALL_EXCEPT);
1478 check_isinfp ("lgamma (+inf) == +inf", FUNC(lgamma) (plus_infty));
1479 check_isinfp_exc ("lgamma (0) == +inf plus divide by zero exception",
1480 FUNC(lgamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1482 check_isinfp_exc ("lgamma (x) == +inf plus divide by zero exception for integer x <= 0",
1483 FUNC(lgamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1484 check_isnan_exc ("lgamma (-inf) == NaN plus invalid exception",
1485 FUNC(lgamma) (minus_infty), INVALID_EXCEPTION);
1487 signgam = 0;
1488 check ("lgamma (1) == 0", FUNC(lgamma) (1), 0);
1489 check_int ("lgamma (0) sets signgam to 1", signgam, 1);
1491 signgam = 0;
1492 check ("lgamma (3) == M_LN2", FUNC(lgamma) (3), M_LN2l);
1493 check_int ("lgamma (3) sets signgam to 1", signgam, 1);
1495 signgam = 0;
1496 check_eps ("lgamma (0.5) == log(sqrt(pi))", FUNC(lgamma) (0.5),
1497 FUNC(log) (FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 1e-7));
1498 check_int ("lgamma (0.5) sets signgam to 1", signgam, 1);
1500 signgam = 0;
1501 check_eps ("lgamma (-0.5) == log(2*sqrt(pi))", FUNC(lgamma) (-0.5),
1502 FUNC(log) (2*FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 0));
1504 check_int ("lgamma (-0.5) sets signgam to -1", signgam, -1);
1506 signgam = 0;
1507 check_eps ("lgamma (0.7) == 0.26086...", FUNC(lgamma) (0.7),
1508 0.26086724653166651439L, CHOOSE(0, 6e-17, 3e-8));
1509 check_int ("lgamma (0.7) sets signgam to 1", signgam, 1);
1511 signgam = 0;
1512 check_eps ("lgamma (1.2) == -0.08537...", FUNC(lgamma) (1.2),
1513 -0.853740900033158497197e-1L, CHOOSE(0, 2e-17, 2e-8));
1514 check_int ("lgamma (1.2) sets signgam to 1", signgam, 1);
1519 static void
1520 ilogb_test (void)
1522 int i;
1524 check_int ("ilogb (1) == 0", FUNC(ilogb) (1), 0);
1525 check_int ("ilogb (e) == 1", FUNC(ilogb) (M_El), 1);
1526 check_int ("ilogb (1024) == 10", FUNC(ilogb) (1024), 10);
1527 check_int ("ilogb (-2000) == 10", FUNC(ilogb) (-2000), 10);
1529 /* XXX We have a problem here: the standard does not tell us whether
1530 exceptions are allowed/required. ignore them for now. */
1531 i = FUNC (ilogb) (0.0);
1532 feclearexcept (FE_ALL_EXCEPT);
1533 check_int ("ilogb (0) == FP_ILOGB0", i, FP_ILOGB0);
1534 i = FUNC(ilogb) (nan_value);
1535 feclearexcept (FE_ALL_EXCEPT);
1536 check_int ("ilogb (NaN) == FP_ILOGBNAN", i, FP_ILOGBNAN);
1541 static void
1542 ldexp_test (void)
1544 MATHTYPE x;
1546 check ("ldexp (0, 0) == 0", FUNC(ldexp) (0, 0), 0);
1548 check_isinfp ("ldexp (+inf, 1) == +inf", FUNC(ldexp) (plus_infty, 1));
1549 check_isinfn ("ldexp (-inf, 1) == -inf", FUNC(ldexp) (minus_infty, 1));
1550 check_isnan ("ldexp (NaN, 1) == NaN", FUNC(ldexp) (nan_value, 1));
1552 check ("ldexp (0.8, 4) == 12.8", FUNC(ldexp) (0.8L, 4), 12.8L);
1553 check ("ldexp (-0.854375, 5) == -27.34", FUNC(ldexp) (-0.854375L, 5), -27.34L);
1555 x = random_greater (0.0);
1556 check_ext ("ldexp (x, 0) == x", FUNC(ldexp) (x, 0L), x, x);
1561 static void
1562 log_test (void)
1564 check_isinfn_exc ("log (+0) == -inf plus divide-by-zero exception",
1565 FUNC(log) (0), DIVIDE_BY_ZERO_EXCEPTION);
1566 check_isinfn_exc ("log (-0) == -inf plus divide-by-zero exception",
1567 FUNC(log) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1569 check ("log (1) == 0", FUNC(log) (1), 0);
1571 check_isnan_exc ("log (x) == NaN plus invalid exception if x < 0",
1572 FUNC(log) (-1), INVALID_EXCEPTION);
1573 check_isinfp ("log (+inf) == +inf", FUNC(log) (plus_infty));
1575 check_eps ("log (e) == 1", FUNC(log) (M_El), 1, CHOOSE (1e-18L, 0, 9e-8L));
1576 check_eps ("log (1/e) == -1", FUNC(log) (1.0 / M_El), -1,
1577 CHOOSE (2e-18L, 0, 0));
1578 check ("log (2) == M_LN2", FUNC(log) (2), M_LN2l);
1579 check_eps ("log (10) == M_LN10", FUNC(log) (10), M_LN10l,
1580 CHOOSE (1e-18L, 0, 0));
1581 check_eps ("log (0.7) == -0.3566749439...", FUNC(log) (0.7),
1582 -0.35667494393873237891L, CHOOSE(7e-17L, 6e-17, 3e-8));
1586 static void
1587 log10_test (void)
1589 check_isinfn_exc ("log10 (+0) == -inf plus divide-by-zero exception",
1590 FUNC(log10) (0), DIVIDE_BY_ZERO_EXCEPTION);
1591 check_isinfn_exc ("log10 (-0) == -inf plus divide-by-zero exception",
1592 FUNC(log10) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1594 check ("log10 (1) == +0", FUNC(log10) (1), 0);
1596 check_isnan_exc ("log10 (x) == NaN plus invalid exception if x < 0",
1597 FUNC(log10) (-1), INVALID_EXCEPTION);
1599 check_isinfp ("log10 (+inf) == +inf", FUNC(log10) (plus_infty));
1601 check_eps ("log10 (0.1) == -1", FUNC(log10) (0.1L), -1,
1602 CHOOSE (1e-18L, 0, 0));
1603 check_eps ("log10 (10) == 1", FUNC(log10) (10.0), 1,
1604 CHOOSE (1e-18L, 0, 0));
1605 check_eps ("log10 (100) == 2", FUNC(log10) (100.0), 2,
1606 CHOOSE (1e-18L, 0, 0));
1607 check ("log10 (10000) == 4", FUNC(log10) (10000.0), 4);
1608 check_eps ("log10 (e) == M_LOG10E", FUNC(log10) (M_El), M_LOG10El,
1609 CHOOSE (1e-18, 0, 9e-8));
1610 check_eps ("log10 (0.7) == -0.1549019599...", FUNC(log10) (0.7),
1611 -0.15490195998574316929L, CHOOSE(3e-17L, 3e-17, 2e-8));
1615 static void
1616 log1p_test (void)
1618 check ("log1p (+0) == +0", FUNC(log1p) (0), 0);
1619 check ("log1p (-0) == -0", FUNC(log1p) (minus_zero), minus_zero);
1621 check_isinfn_exc ("log1p (-1) == -inf plus divide-by-zero exception",
1622 FUNC(log1p) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1623 check_isnan_exc ("log1p (x) == NaN plus invalid exception if x < -1",
1624 FUNC(log1p) (-2), INVALID_EXCEPTION);
1626 check_isinfp ("log1p (+inf) == +inf", FUNC(log1p) (plus_infty));
1628 check_eps ("log1p (e-1) == 1", FUNC(log1p) (M_El - 1.0), 1,
1629 CHOOSE (1e-18L, 0, 6e-8));
1631 check_eps ("log1p (-0.3) == -0.35667...", FUNC(log1p) (-0.3),
1632 -0.35667494393873237891L, CHOOSE(2e-17L, 6e-17, 3e-8));
1636 static void
1637 log2_test (void)
1639 check_isinfn_exc ("log2 (+0) == -inf plus divide-by-zero exception",
1640 FUNC(log2) (0), DIVIDE_BY_ZERO_EXCEPTION);
1641 check_isinfn_exc ("log2 (-0) == -inf plus divide-by-zero exception",
1642 FUNC(log2) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1644 check ("log2 (1) == +0", FUNC(log2) (1), 0);
1646 check_isnan_exc ("log2 (x) == NaN plus invalid exception if x < 0",
1647 FUNC(log2) (-1), INVALID_EXCEPTION);
1649 check_isinfp ("log2 (+inf) == +inf", FUNC(log2) (plus_infty));
1651 check_eps ("log2 (e) == M_LOG2E", FUNC(log2) (M_El), M_LOG2El,
1652 CHOOSE (1e-18L, 0, 0));
1653 check ("log2 (2) == 1", FUNC(log2) (2.0), 1);
1654 check_eps ("log2 (16) == 4", FUNC(log2) (16.0), 4, CHOOSE (1e-18L, 0, 0));
1655 check ("log2 (256) == 8", FUNC(log2) (256.0), 8);
1656 check_eps ("log2 (0.7) == -0.5145731728...", FUNC(log2) (0.7),
1657 -0.51457317282975824043L, CHOOSE(1e-16L, 2e-16, 6e-8));
1662 static void
1663 logb_test (void)
1665 check_isinfp ("logb (+inf) == +inf", FUNC(logb) (plus_infty));
1666 check_isinfp ("logb (-inf) == +inf", FUNC(logb) (minus_infty));
1668 check_isinfn_exc ("logb (+0) == -inf plus divide-by-zero exception",
1669 FUNC(logb) (0), DIVIDE_BY_ZERO_EXCEPTION);
1671 check_isinfn_exc ("logb (-0) == -inf plus divide-by-zero exception",
1672 FUNC(logb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1674 check ("logb (1) == 0", FUNC(logb) (1), 0);
1675 check ("logb (e) == 1", FUNC(logb) (M_El), 1);
1676 check ("logb (1024) == 10", FUNC(logb) (1024), 10);
1677 check ("logb (-2000) == 10", FUNC(logb) (-2000), 10);
1682 static void
1683 modf_test (void)
1685 MATHTYPE result, intpart;
1687 result = FUNC(modf) (plus_infty, &intpart);
1688 check ("modf (+inf, &x) returns +0", result, 0);
1689 check_isinfp ("modf (+inf, &x) set x to +inf", intpart);
1691 result = FUNC(modf) (minus_infty, &intpart);
1692 check ("modf (-inf, &x) returns -0", result, minus_zero);
1693 check_isinfn ("modf (-inf, &x) sets x to -inf", intpart);
1695 result = FUNC(modf) (nan_value, &intpart);
1696 check_isnan ("modf (NaN, &x) returns NaN", result);
1697 check_isnan ("modf (NaN, &x) sets x to NaN", intpart);
1699 result = FUNC(modf) (0, &intpart);
1700 check ("modf (0, &x) returns 0", result, 0);
1701 check ("modf (0, &x) sets x to 0", intpart, 0);
1703 result = FUNC(modf) (minus_zero, &intpart);
1704 check ("modf (-0, &x) returns -0", result, minus_zero);
1705 check ("modf (-0, &x) sets x to -0", intpart, minus_zero);
1707 result = FUNC(modf) (1.5, &intpart);
1708 check ("modf (1.5, &x) returns 0.5", result, 0.5);
1709 check ("modf (1.5, &x) sets x to 1", intpart, 1);
1711 result = FUNC(modf) (2.5, &intpart);
1712 check ("modf (2.5, &x) returns 0.5", result, 0.5);
1713 check ("modf (2.5, &x) sets x to 2", intpart, 2);
1715 result = FUNC(modf) (-2.5, &intpart);
1716 check ("modf (-2.5, &x) returns -0.5", result, -0.5);
1717 check ("modf (-2.5, &x) sets x to -2", intpart, -2);
1719 result = FUNC(modf) (20, &intpart);
1720 check ("modf (20, &x) returns 0", result, 0);
1721 check ("modf (20, &x) sets x to 20", intpart, 20);
1723 result = FUNC(modf) (21, &intpart);
1724 check ("modf (21, &x) returns 0", result, 0);
1725 check ("modf (21, &x) sets x to 21", intpart, 21);
1727 result = FUNC(modf) (89.6, &intpart);
1728 check_eps ("modf (89.6, &x) returns 0.6", result, 0.6,
1729 CHOOSE(6e-15L, 6e-15, 2e-6));
1730 check ("modf (89.6, &x) sets x to 89", intpart, 89);
1734 static void
1735 scalb_test (void)
1737 MATHTYPE x;
1739 check_isnan ("scalb (2, 0.5) == NaN", FUNC(scalb) (2, 0.5));
1740 check_isnan ("scalb (3, -2.5) == NaN", FUNC(scalb) (3, -2.5));
1742 check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1743 check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1745 x = random_greater (0.0);
1746 check ("scalb (x, 0) == 0", FUNC(scalb) (x, 0), x);
1747 x = random_greater (0.0);
1748 check ("scalb (-x, 0) == 0", FUNC(scalb) (-x, 0), -x);
1750 check_isnan_exc ("scalb (+0, +inf) == NaN plus invalid exception",
1751 FUNC(scalb) (0, plus_infty), INVALID_EXCEPTION);
1752 check_isnan_exc ("scalb (-0, +inf) == NaN plus invalid exception",
1753 FUNC(scalb) (minus_zero, plus_infty), INVALID_EXCEPTION);
1755 check ("scalb (+0, 2) == +0", FUNC(scalb) (0, 2), 0);
1756 check ("scalb (-0, 4) == -0", FUNC(scalb) (minus_zero, -4), minus_zero);
1757 check ("scalb (+0, 0) == +0", FUNC(scalb) (0, 0), 0);
1758 check ("scalb (-0, 0) == -0", FUNC(scalb) (minus_zero, 0), minus_zero);
1759 check ("scalb (+0, -1) == +0", FUNC(scalb) (0, -1), 0);
1760 check ("scalb (-0, -10) == -0", FUNC(scalb) (minus_zero, -10), minus_zero);
1761 check ("scalb (+0, -inf) == +0", FUNC(scalb) (0, minus_infty), 0);
1762 check ("scalb (-0, -inf) == -0", FUNC(scalb) (minus_zero, minus_infty),
1763 minus_zero);
1765 check_isinfp ("scalb (+inf, -1) == +inf", FUNC(scalb) (plus_infty, -1));
1766 check_isinfn ("scalb (-inf, -10) == -inf", FUNC(scalb) (minus_infty, -10));
1767 check_isinfp ("scalb (+inf, 0) == +inf", FUNC(scalb) (plus_infty, 0));
1768 check_isinfn ("scalb (-inf, 0) == -inf", FUNC(scalb) (minus_infty, 0));
1769 check_isinfp ("scalb (+inf, 2) == +inf", FUNC(scalb) (plus_infty, 2));
1770 check_isinfn ("scalb (-inf, 100) == -inf", FUNC(scalb) (minus_infty, 100));
1772 x = random_greater (0.0);
1773 check ("scalb (x, -inf) == 0", FUNC(scalb) (x, minus_infty), 0.0);
1774 check ("scalb (-x, -inf) == -0", FUNC(scalb) (-x, minus_infty), minus_zero);
1776 x = random_greater (0.0);
1777 check_isinfp ("scalb (x, +inf) == +inf", FUNC(scalb) (x, plus_infty));
1778 x = random_greater (0.0);
1779 check_isinfn ("scalb (-x, +inf) == -inf", FUNC(scalb) (-x, plus_infty));
1780 check_isinfp ("scalb (+inf, +inf) == +inf",
1781 FUNC(scalb) (plus_infty, plus_infty));
1782 check_isinfn ("scalb (-inf, +inf) == -inf",
1783 FUNC(scalb) (minus_infty, plus_infty));
1785 check_isnan ("scalb (+inf, -inf) == NaN",
1786 FUNC(scalb) (plus_infty, minus_infty));
1787 check_isnan ("scalb (-inf, -inf) == NaN",
1788 FUNC(scalb) (minus_infty, minus_infty));
1790 check_isnan ("scalb (NaN, 1) == NaN", FUNC(scalb) (nan_value, 1));
1791 check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1792 check_isnan ("scalb (NaN, 0) == NaN", FUNC(scalb) (nan_value, 0));
1793 check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1794 check_isnan ("scalb (NaN, +inf) == NaN",
1795 FUNC(scalb) (nan_value, plus_infty));
1796 check_isnan ("scalb (+inf, NaN) == NaN",
1797 FUNC(scalb) (plus_infty, nan_value));
1798 check_isnan ("scalb (NaN, NaN) == NaN", FUNC(scalb) (nan_value, nan_value));
1800 check ("scalb (0.8, 4) == 12.8", FUNC(scalb) (0.8L, 4), 12.8L);
1801 check ("scalb (-0.854375, 5) == -27.34", FUNC(scalb) (-0.854375L, 5), -27.34L);
1805 static void
1806 scalbn_test (void)
1808 MATHTYPE x;
1810 check ("scalbn (0, 0) == 0", FUNC(scalbn) (0, 0), 0);
1812 check_isinfp ("scalbn (+inf, 1) == +inf", FUNC(scalbn) (plus_infty, 1));
1813 check_isinfn ("scalbn (-inf, 1) == -inf", FUNC(scalbn) (minus_infty, 1));
1814 check_isnan ("scalbn (NaN, 1) == NaN", FUNC(scalbn) (nan_value, 1));
1816 check ("scalbn (0.8, 4) == 12.8", FUNC(scalbn) (0.8L, 4), 12.8L);
1817 check ("scalbn (-0.854375, 5) == -27.34", FUNC(scalbn) (-0.854375L, 5), -27.34L);
1819 x = random_greater (0.0);
1820 check_ext ("scalbn (x, 0) == x", FUNC(scalbn) (x, 0L), x, x);
1824 static void
1825 sin_test (void)
1827 check ("sin (+0) == +0", FUNC(sin) (0), 0);
1828 check ("sin (-0) == -0", FUNC(sin) (minus_zero), minus_zero);
1829 check_isnan_exc ("sin (+inf) == NaN plus invalid exception",
1830 FUNC(sin) (plus_infty),
1831 INVALID_EXCEPTION);
1832 check_isnan_exc ("sin (-inf) == NaN plus invalid exception",
1833 FUNC(sin) (minus_infty),
1834 INVALID_EXCEPTION);
1836 check_eps ("sin (pi/6) == 0.5", FUNC(sin) (M_PI_6l),
1837 0.5, CHOOSE (4e-18L, 0, 0));
1838 check_eps ("sin (-pi/6) == -0.5", FUNC(sin) (-M_PI_6l),
1839 -0.5, CHOOSE (4e-18L, 0, 0));
1840 check ("sin (pi/2) == 1", FUNC(sin) (M_PI_2l), 1);
1841 check ("sin (-pi/2) == -1", FUNC(sin) (-M_PI_2l), -1);
1842 check_eps ("sin (0.7) == 0.6442176872...", FUNC(sin) (0.7),
1843 0.64421768723769105367L, CHOOSE(4e-17L, 0, 0));
1847 static void
1848 sinh_test (void)
1850 check ("sinh (+0) == +0", FUNC(sinh) (0), 0);
1852 #ifndef TEST_INLINE
1853 check ("sinh (-0) == -0", FUNC(sinh) (minus_zero), minus_zero);
1855 check_isinfp ("sinh (+inf) == +inf", FUNC(sinh) (plus_infty));
1856 check_isinfn ("sinh (-inf) == -inf", FUNC(sinh) (minus_infty));
1857 #endif
1859 check_eps ("sinh (0.7) == 0.7585837018...", FUNC(sinh) (0.7),
1860 0.75858370183953350346L, CHOOSE(6e-17L, 2e-16, 6e-8));
1864 static void
1865 sincos_test (void)
1867 MATHTYPE sin_res, cos_res;
1868 fenv_t fenv;
1870 FUNC(sincos) (0, &sin_res, &cos_res);
1871 fegetenv (&fenv);
1872 check ("sincos (+0, &sin, &cos) puts +0 in sin", sin_res, 0);
1873 fesetenv (&fenv);
1874 check ("sincos (+0, &sin, &cos) puts 1 in cos", cos_res, 1);
1876 FUNC(sincos) (minus_zero, &sin_res, &cos_res);
1877 fegetenv (&fenv);
1878 check ("sincos (-0, &sin, &cos) puts -0 in sin", sin_res, minus_zero);
1879 fesetenv (&fenv);
1880 check ("sincos (-0, &sin, &cos) puts 1 in cos", cos_res, 1);
1882 FUNC(sincos) (plus_infty, &sin_res, &cos_res);
1883 fegetenv (&fenv);
1884 check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in sin plus invalid exception",
1885 sin_res, INVALID_EXCEPTION);
1886 fesetenv (&fenv);
1887 check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in cos plus invalid exception",
1888 cos_res, INVALID_EXCEPTION);
1890 FUNC(sincos) (minus_infty, &sin_res, &cos_res);
1891 fegetenv (&fenv);
1892 check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in sin plus invalid exception",
1893 sin_res, INVALID_EXCEPTION);
1894 fesetenv (&fenv);
1895 check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in cos plus invalid exception",
1896 cos_res, INVALID_EXCEPTION);
1898 FUNC(sincos) (M_PI_2l, &sin_res, &cos_res);
1899 fegetenv (&fenv);
1900 check ("sincos (pi/2, &sin, &cos) puts 1 in sin", sin_res, 1);
1901 fesetenv (&fenv);
1902 check_eps ("sincos (pi/2, &sin, &cos) puts 0 in cos", cos_res, 0,
1903 CHOOSE (1e-18L, 1e-16, 1e-7));
1905 FUNC(sincos) (M_PI_6l, &sin_res, &cos_res);
1906 check_eps ("sincos (pi/6, &sin, &cos) puts 0.5 in sin", sin_res, 0.5,
1907 CHOOSE (5e-18L, 0, 0));
1909 FUNC(sincos) (M_PI_6l*2.0, &sin_res, &cos_res);
1910 check_eps ("sincos (pi/3, &sin, &cos) puts 0.5 in cos", cos_res, 0.5,
1911 CHOOSE (5e-18L, 1e-15, 1e-7));
1913 FUNC(sincos) (0.7, &sin_res, &cos_res);
1914 check_eps ("sincos (0.7, &sin, &cos) puts 0.6442176872... in sin", sin_res,
1915 0.64421768723769105367L, CHOOSE(4e-17L, 0, 0));
1916 check_eps ("sincos (0.7, &sin, &cos) puts 0.7648421872... in cos", cos_res,
1917 0.76484218728448842626L, CHOOSE(3e-17L, 2e-16, 6e-8));
1921 static void
1922 tan_test (void)
1924 check ("tan (+0) == +0", FUNC(tan) (0), 0);
1925 check ("tan (-0) == -0", FUNC(tan) (minus_zero), minus_zero);
1926 check_isnan_exc ("tan (+inf) == NaN plus invalid exception",
1927 FUNC(tan) (plus_infty), INVALID_EXCEPTION);
1928 check_isnan_exc ("tan (-inf) == NaN plus invalid exception",
1929 FUNC(tan) (minus_infty), INVALID_EXCEPTION);
1931 check_eps ("tan (pi/4) == 1", FUNC(tan) (M_PI_4l), 1,
1932 CHOOSE (2e-18L, 1e-15L, 2e-7));
1933 check_eps ("tan (0.7) == 0.8422883804...", FUNC(tan) (0.7),
1934 0.84228838046307944813L, CHOOSE(8e-17L, 0, 0));
1938 static void
1939 tanh_test (void)
1941 check ("tanh (+0) == +0", FUNC(tanh) (0), 0);
1942 #ifndef TEST_INLINE
1943 check ("tanh (-0) == -0", FUNC(tanh) (minus_zero), minus_zero);
1945 check ("tanh (+inf) == +1", FUNC(tanh) (plus_infty), 1);
1946 check ("tanh (-inf) == -1", FUNC(tanh) (minus_infty), -1);
1947 #endif
1948 check_eps ("tanh (0.7) == 0.6043677771...", FUNC(tanh) (0.7),
1949 0.60436777711716349631L, CHOOSE(3e-17L, 2e-16, 6e-8));
1953 static void
1954 fabs_test (void)
1956 check ("fabs (+0) == +0", FUNC(fabs) (0), 0);
1957 check ("fabs (-0) == +0", FUNC(fabs) (minus_zero), 0);
1959 check_isinfp ("fabs (+inf) == +inf", FUNC(fabs) (plus_infty));
1960 check_isinfp ("fabs (-inf) == +inf", FUNC(fabs) (minus_infty));
1962 check ("fabs (+38) == 38", FUNC(fabs) (38.0), 38.0);
1963 check ("fabs (-e) == e", FUNC(fabs) (-M_El), M_El);
1967 static void
1968 floor_test (void)
1970 check ("floor (+0) == +0", FUNC(floor) (0.0), 0.0);
1971 check ("floor (-0) == -0", FUNC(floor) (minus_zero), minus_zero);
1972 check_isinfp ("floor (+inf) == +inf", FUNC(floor) (plus_infty));
1973 check_isinfn ("floor (-inf) == -inf", FUNC(floor) (minus_infty));
1975 check ("floor (pi) == 3", FUNC(floor) (M_PIl), 3.0);
1976 check ("floor (-pi) == -4", FUNC(floor) (-M_PIl), -4.0);
1980 static void
1981 hypot_test (void)
1983 MATHTYPE a;
1985 a = random_greater (0);
1986 check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot) (plus_infty, a), a);
1987 check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot) (minus_infty, a), a);
1989 #ifndef TEST_INLINE
1990 check_isinfp ("hypot (+inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
1991 check_isinfp ("hypot (-inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
1992 #endif
1994 check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot) (nan_value, nan_value));
1996 a = FUNC(hypot) (12.4L, 0.7L);
1997 check ("hypot (x,y) == hypot (y,x)", FUNC(hypot) (0.7L, 12.4L), a);
1998 check ("hypot (x,y) == hypot (-x,y)", FUNC(hypot) (-12.4L, 0.7L), a);
1999 check ("hypot (x,y) == hypot (-y,x)", FUNC(hypot) (-0.7L, 12.4L), a);
2000 check ("hypot (x,y) == hypot (-x,-y)", FUNC(hypot) (-12.4L, -0.7L), a);
2001 check ("hypot (x,y) == hypot (-y,-x)", FUNC(hypot) (-0.7L, -12.4L), a);
2002 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-0.7L, 0), 0.7L);
2003 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (0.7L, 0), 0.7L);
2004 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-1.0L, 0), 1.0L);
2005 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (1.0L, 0), 1.0L);
2006 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-5.7e7L, 0), 5.7e7L);
2007 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (5.7e7L, 0), 5.7e7L);
2009 check_eps ("hypot (0.7,1.2) == 1.38924...", FUNC(hypot) (0.7, 1.2),
2010 1.3892443989449804508L, CHOOSE(7e-17L, 3e-16, 0));
2014 static void
2015 pow_test (void)
2017 MATHTYPE x;
2019 check ("pow (+0, +0) == 1", FUNC(pow) (0, 0), 1);
2020 check ("pow (+0, -0) == 1", FUNC(pow) (0, minus_zero), 1);
2021 check ("pow (-0, +0) == 1", FUNC(pow) (minus_zero, 0), 1);
2022 check ("pow (-0, -0) == 1", FUNC(pow) (minus_zero, minus_zero), 1);
2024 check ("pow (+10, +0) == 1", FUNC(pow) (10, 0), 1);
2025 check ("pow (+10, -0) == 1", FUNC(pow) (10, minus_zero), 1);
2026 check ("pow (-10, +0) == 1", FUNC(pow) (-10, 0), 1);
2027 check ("pow (-10, -0) == 1", FUNC(pow) (-10, minus_zero), 1);
2029 check ("pow (NaN, +0) == 1", FUNC(pow) (nan_value, 0), 1);
2030 check ("pow (NaN, -0) == 1", FUNC(pow) (nan_value, minus_zero), 1);
2032 #ifndef TEST_INLINE
2033 check_isinfp ("pow (+1.1, +inf) == +inf", FUNC(pow) (1.1, plus_infty));
2034 check_isinfp ("pow (+inf, +inf) == +inf", FUNC(pow) (plus_infty, plus_infty));
2035 check_isinfp ("pow (-1.1, +inf) == +inf", FUNC(pow) (-1.1, plus_infty));
2036 check_isinfp ("pow (-inf, +inf) == +inf", FUNC(pow) (minus_infty, plus_infty));
2038 check ("pow (0.9, +inf) == +0", FUNC(pow) (0.9L, plus_infty), 0);
2039 check ("pow (1e-7, +inf) == +0", FUNC(pow) (1e-7L, plus_infty), 0);
2040 check ("pow (-0.9, +inf) == +0", FUNC(pow) (-0.9L, plus_infty), 0);
2041 check ("pow (-1e-7, +inf) == +0", FUNC(pow) (-1e-7L, plus_infty), 0);
2043 check ("pow (+1.1, -inf) == 0", FUNC(pow) (1.1, minus_infty), 0);
2044 check ("pow (+inf, -inf) == 0", FUNC(pow) (plus_infty, minus_infty), 0);
2045 check ("pow (-1.1, -inf) == 0", FUNC(pow) (-1.1, minus_infty), 0);
2046 check ("pow (-inf, -inf) == 0", FUNC(pow) (minus_infty, minus_infty), 0);
2048 check_isinfp ("pow (0.9, -inf) == +inf", FUNC(pow) (0.9L, minus_infty));
2049 check_isinfp ("pow (1e-7, -inf) == +inf", FUNC(pow) (1e-7L, minus_infty));
2050 check_isinfp ("pow (-0.9, -inf) == +inf", FUNC(pow) (-0.9L, minus_infty));
2051 check_isinfp ("pow (-1e-7, -inf) == +inf", FUNC(pow) (-1e-7L, minus_infty));
2053 check_isinfp ("pow (+inf, 1e-7) == +inf", FUNC(pow) (plus_infty, 1e-7L));
2054 check_isinfp ("pow (+inf, 1) == +inf", FUNC(pow) (plus_infty, 1));
2055 check_isinfp ("pow (+inf, 1e7) == +inf", FUNC(pow) (plus_infty, 1e7L));
2057 check ("pow (+inf, -1e-7) == 0", FUNC(pow) (plus_infty, -1e-7L), 0);
2058 check ("pow (+inf, -1) == 0", FUNC(pow) (plus_infty, -1), 0);
2059 check ("pow (+inf, -1e7) == 0", FUNC(pow) (plus_infty, -1e7L), 0);
2061 check_isinfn ("pow (-inf, 1) == -inf", FUNC(pow) (minus_infty, 1));
2062 check_isinfn ("pow (-inf, 11) == -inf", FUNC(pow) (minus_infty, 11));
2063 check_isinfn ("pow (-inf, 1001) == -inf", FUNC(pow) (minus_infty, 1001));
2065 check_isinfp ("pow (-inf, 2) == +inf", FUNC(pow) (minus_infty, 2));
2066 check_isinfp ("pow (-inf, 12) == +inf", FUNC(pow) (minus_infty, 12));
2067 check_isinfp ("pow (-inf, 1002) == +inf", FUNC(pow) (minus_infty, 1002));
2068 check_isinfp ("pow (-inf, 0.1) == +inf", FUNC(pow) (minus_infty, 0.1));
2069 check_isinfp ("pow (-inf, 1.1) == +inf", FUNC(pow) (minus_infty, 1.1));
2070 check_isinfp ("pow (-inf, 11.1) == +inf", FUNC(pow) (minus_infty, 11.1));
2071 check_isinfp ("pow (-inf, 1001.1) == +inf", FUNC(pow) (minus_infty, 1001.1));
2073 check ("pow (-inf, -1) == -0", FUNC(pow) (minus_infty, -1), minus_zero);
2074 check ("pow (-inf, -11) == -0", FUNC(pow) (minus_infty, -11), minus_zero);
2075 check ("pow (-inf, -1001) == -0", FUNC(pow) (minus_infty, -1001), minus_zero);
2077 check ("pow (-inf, -2) == +0", FUNC(pow) (minus_infty, -2), 0);
2078 check ("pow (-inf, -12) == +0", FUNC(pow) (minus_infty, -12), 0);
2079 check ("pow (-inf, -1002) == +0", FUNC(pow) (minus_infty, -1002), 0);
2080 check ("pow (-inf, -0.1) == +0", FUNC(pow) (minus_infty, -0.1), 0);
2081 check ("pow (-inf, -1.1) == +0", FUNC(pow) (minus_infty, -1.1), 0);
2082 check ("pow (-inf, -11.1) == +0", FUNC(pow) (minus_infty, -11.1), 0);
2083 check ("pow (-inf, -1001.1) == +0", FUNC(pow) (minus_infty, -1001.1), 0);
2085 check_isnan ("pow (NaN, NaN) == NaN", FUNC(pow) (nan_value, nan_value));
2086 check_isnan ("pow (0, NaN) == NaN", FUNC(pow) (0, nan_value));
2087 check_isnan ("pow (1, NaN) == NaN", FUNC(pow) (1, nan_value));
2088 check_isnan ("pow (-1, NaN) == NaN", FUNC(pow) (-1, nan_value));
2089 check_isnan ("pow (NaN, 1) == NaN", FUNC(pow) (nan_value, 1));
2090 check_isnan ("pow (NaN, -1) == NaN", FUNC(pow) (nan_value, -1));
2092 x = random_greater (0.0);
2093 check_isnan_ext ("pow (x, NaN) == NaN", FUNC(pow) (x, nan_value), x);
2095 check_isnan_exc ("pow (+1, +inf) == NaN plus invalid exception",
2096 FUNC(pow) (1, plus_infty), INVALID_EXCEPTION);
2097 check_isnan_exc ("pow (-1, +inf) == NaN plus invalid exception",
2098 FUNC(pow) (-1, plus_infty), INVALID_EXCEPTION);
2099 check_isnan_exc ("pow (+1, -inf) == NaN plus invalid exception",
2100 FUNC(pow) (1, minus_infty), INVALID_EXCEPTION);
2101 check_isnan_exc ("pow (-1, -inf) == NaN plus invalid exception",
2102 FUNC(pow) (-1, minus_infty), INVALID_EXCEPTION);
2104 check_isnan_exc ("pow (-0.1, 1.1) == NaN plus invalid exception",
2105 FUNC(pow) (-0.1, 1.1), INVALID_EXCEPTION);
2106 check_isnan_exc ("pow (-0.1, -1.1) == NaN plus invalid exception",
2107 FUNC(pow) (-0.1, -1.1), INVALID_EXCEPTION);
2108 check_isnan_exc ("pow (-10.1, 1.1) == NaN plus invalid exception",
2109 FUNC(pow) (-10.1, 1.1), INVALID_EXCEPTION);
2110 check_isnan_exc ("pow (-10.1, -1.1) == NaN plus invalid exception",
2111 FUNC(pow) (-10.1, -1.1), INVALID_EXCEPTION);
2113 check_isinfp_exc ("pow (+0, -1) == +inf plus divide-by-zero exception",
2114 FUNC(pow) (0, -1), DIVIDE_BY_ZERO_EXCEPTION);
2115 check_isinfp_exc ("pow (+0, -11) == +inf plus divide-by-zero exception",
2116 FUNC(pow) (0, -11), DIVIDE_BY_ZERO_EXCEPTION);
2117 check_isinfn_exc ("pow (-0, -1) == -inf plus divide-by-zero exception",
2118 FUNC(pow) (minus_zero, -1), DIVIDE_BY_ZERO_EXCEPTION);
2119 check_isinfn_exc ("pow (-0, -11) == -inf plus divide-by-zero exception",
2120 FUNC(pow) (minus_zero, -11), DIVIDE_BY_ZERO_EXCEPTION);
2122 check_isinfp_exc ("pow (+0, -2) == +inf plus divide-by-zero exception",
2123 FUNC(pow) (0, -2), DIVIDE_BY_ZERO_EXCEPTION);
2124 check_isinfp_exc ("pow (+0, -11.1) == +inf plus divide-by-zero exception",
2125 FUNC(pow) (0, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2126 check_isinfp_exc ("pow (-0, -2) == +inf plus divide-by-zero exception",
2127 FUNC(pow) (minus_zero, -2), DIVIDE_BY_ZERO_EXCEPTION);
2128 check_isinfp_exc ("pow (-0, -11.1) == +inf plus divide-by-zero exception",
2129 FUNC(pow) (minus_zero, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2130 #endif
2132 check ("pow (+0, 1) == +0", FUNC(pow) (0, 1), 0);
2133 check ("pow (+0, 11) == +0", FUNC(pow) (0, 11), 0);
2134 #ifndef TEST_INLINE
2135 check ("pow (-0, 1) == -0", FUNC(pow) (minus_zero, 1), minus_zero);
2136 check ("pow (-0, 11) == -0", FUNC(pow) (minus_zero, 11), minus_zero);
2137 #endif
2139 check ("pow (+0, 2) == +0", FUNC(pow) (0, 2), 0);
2140 check ("pow (+0, 11.1) == +0", FUNC(pow) (0, 11.1), 0);
2142 #ifndef TEST_INLINE
2143 check ("pow (-0, 2) == +0", FUNC(pow) (minus_zero, 2), 0);
2144 check ("pow (-0, 11.1) == +0", FUNC(pow) (minus_zero, 11.1), 0);
2146 x = random_greater (1.0);
2147 check_isinfp_ext ("pow (x, +inf) == +inf for |x| > 1",
2148 FUNC(pow) (x, plus_infty), x);
2150 x = random_value (-1.0, 1.0);
2151 check_ext ("pow (x, +inf) == +0 for |x| < 1",
2152 FUNC(pow) (x, plus_infty), 0.0, x);
2154 x = random_greater (1.0);
2155 check_ext ("pow (x, -inf) == +0 for |x| > 1",
2156 FUNC(pow) (x, minus_infty), 0.0, x);
2158 x = random_value (-1.0, 1.0);
2159 check_isinfp_ext ("pow (x, -inf) == +inf for |x| < 1",
2160 FUNC(pow) (x, minus_infty), x);
2162 x = random_greater (0.0);
2163 check_isinfp_ext ("pow (+inf, y) == +inf for y > 0",
2164 FUNC(pow) (plus_infty, x), x);
2166 x = random_less (0.0);
2167 check_ext ("pow (+inf, y) == +0 for y < 0",
2168 FUNC(pow) (plus_infty, x), 0.0, x);
2170 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2171 check_isinfn_ext ("pow (-inf, y) == -inf for y an odd integer > 0",
2172 FUNC(pow) (minus_infty, x), x);
2174 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2175 check_isinfp_ext ("pow (-inf, y) == +inf for y > 0 and not an odd integer",
2176 FUNC(pow) (minus_infty, x), x);
2178 x = -((rand () % 1000000) * 2.0 + 1); /* Get random odd integer < 0 */
2179 check_ext ("pow (-inf, y) == -0 for y an odd integer < 0",
2180 FUNC(pow) (minus_infty, x), minus_zero, x);
2182 x = ((rand () % 1000000) + 1) * -2.0; /* Get random even integer < 0 */
2183 check_ext ("pow (-inf, y) == +0 for y < 0 and not an odd integer",
2184 FUNC(pow) (minus_infty, x), 0.0, x);
2185 #endif
2187 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2188 check_ext ("pow (+0, y) == +0 for y an odd integer > 0",
2189 FUNC(pow) (0.0, x), 0.0, x);
2190 #ifndef TEST_INLINE
2191 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2192 check_ext ("pow (-0, y) == -0 for y an odd integer > 0",
2193 FUNC(pow) (minus_zero, x), minus_zero, x);
2194 #endif
2196 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2197 check_ext ("pow (+0, y) == +0 for y > 0 and not an odd integer",
2198 FUNC(pow) (0.0, x), 0.0, x);
2200 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2201 check_ext ("pow (-0, y) == +0 for y > 0 and not an odd integer",
2202 FUNC(pow) (minus_zero, x), 0.0, x);
2204 check_eps ("pow (0.7, 1.2) == 0.65180...", FUNC(pow) (0.7, 1.2),
2205 0.65180494056638638188L, CHOOSE(4e-17L, 0, 0));
2207 #ifdef TEST_DOUBLE
2208 check ("pow (-7.49321e+133, -9.80818e+16) == 0",
2209 FUNC(pow) (-7.49321e+133, -9.80818e+16), 0);
2210 #endif
2214 static void
2215 fdim_test (void)
2217 check ("fdim (+0, +0) = +0", FUNC(fdim) (0, 0), 0);
2218 check ("fdim (9, 0) = 9", FUNC(fdim) (9, 0), 9);
2219 check ("fdim (0, 9) = 0", FUNC(fdim) (0, 9), 0);
2220 check ("fdim (-9, 0) = 9", FUNC(fdim) (-9, 0), 0);
2221 check ("fdim (0, -9) = 9", FUNC(fdim) (0, -9), 9);
2223 check_isinfp ("fdim (+inf, 9) = +inf", FUNC(fdim) (plus_infty, 9));
2224 check_isinfp ("fdim (+inf, -9) = +inf", FUNC(fdim) (plus_infty, -9));
2225 check ("fdim (-inf, 9) = 0", FUNC(fdim) (minus_infty, 9), 0);
2226 check ("fdim (-inf, -9) = 0", FUNC(fdim) (minus_infty, -9), 0);
2227 check_isinfp ("fdim (+9, -inf) = +inf", FUNC(fdim) (9, minus_infty));
2228 check_isinfp ("fdim (-9, -inf) = +inf", FUNC(fdim) (-9, minus_infty));
2229 check ("fdim (9, inf) = 0", FUNC(fdim) (9, plus_infty), 0);
2230 check ("fdim (-9, inf) = 0", FUNC(fdim) (-9, plus_infty), 0);
2232 check_isnan ("fdim (0, NaN) = NaN", FUNC(fdim) (0, nan_value));
2233 check_isnan ("fdim (9, NaN) = NaN", FUNC(fdim) (9, nan_value));
2234 check_isnan ("fdim (-9, NaN) = NaN", FUNC(fdim) (-9, nan_value));
2235 check_isnan ("fdim (NaN, 9) = NaN", FUNC(fdim) (nan_value, 9));
2236 check_isnan ("fdim (NaN, -9) = NaN", FUNC(fdim) (nan_value, -9));
2237 check_isnan ("fdim (+inf, NaN) = NaN", FUNC(fdim) (plus_infty, nan_value));
2238 check_isnan ("fdim (-inf, NaN) = NaN", FUNC(fdim) (minus_infty, nan_value));
2239 check_isnan ("fdim (NaN, +inf) = NaN", FUNC(fdim) (nan_value, plus_infty));
2240 check_isnan ("fdim (NaN, -inf) = NaN", FUNC(fdim) (nan_value, minus_infty));
2241 check_isnan ("fdim (NaN, NaN) = NaN", FUNC(fdim) (nan_value, nan_value));
2245 static void
2246 fmin_test (void)
2248 check ("fmin (+0, +0) = +0", FUNC(fmin) (0, 0), 0);
2249 check ("fmin (9, 0) = 0", FUNC(fmin) (9, 0), 0);
2250 check ("fmin (0, 9) = 0", FUNC(fmin) (0, 9), 0);
2251 check ("fmin (-9, 0) = -9", FUNC(fmin) (-9, 0), -9);
2252 check ("fmin (0, -9) = -9", FUNC(fmin) (0, -9), -9);
2254 check ("fmin (+inf, 9) = 9", FUNC(fmin) (plus_infty, 9), 9);
2255 check ("fmin (9, +inf) = 9", FUNC(fmin) (9, plus_infty), 9);
2256 check ("fmin (+inf, -9) = -9", FUNC(fmin) (plus_infty, -9), -9);
2257 check ("fmin (-9, +inf) = -9", FUNC(fmin) (-9, plus_infty), -9);
2258 check_isinfn ("fmin (-inf, 9) = -inf", FUNC(fmin) (minus_infty, 9));
2259 check_isinfn ("fmin (-inf, -9) = -inf", FUNC(fmin) (minus_infty, -9));
2260 check_isinfn ("fmin (+9, -inf) = -inf", FUNC(fmin) (9, minus_infty));
2261 check_isinfn ("fmin (-9, -inf) = -inf", FUNC(fmin) (-9, minus_infty));
2263 check ("fmin (0, NaN) = 0", FUNC(fmin) (0, nan_value), 0);
2264 check ("fmin (9, NaN) = 9", FUNC(fmin) (9, nan_value), 9);
2265 check ("fmin (-9, NaN) = 9", FUNC(fmin) (-9, nan_value), -9);
2266 check ("fmin (NaN, 0) = 0", FUNC(fmin) (nan_value, 0), 0);
2267 check ("fmin (NaN, 9) = NaN", FUNC(fmin) (nan_value, 9), 9);
2268 check ("fmin (NaN, -9) = NaN", FUNC(fmin) (nan_value, -9), -9);
2269 check_isinfp ("fmin (+inf, NaN) = +inf", FUNC(fmin) (plus_infty, nan_value));
2270 check_isinfn ("fmin (-inf, NaN) = -inf", FUNC(fmin) (minus_infty, nan_value));
2271 check_isinfp ("fmin (NaN, +inf) = +inf", FUNC(fmin) (nan_value, plus_infty));
2272 check_isinfn ("fmin (NaN, -inf) = -inf", FUNC(fmin) (nan_value, minus_infty));
2273 check_isnan ("fmin (NaN, NaN) = NaN", FUNC(fmin) (nan_value, nan_value));
2277 static void
2278 fmax_test (void)
2280 check ("fmax (+0, +0) = +0", FUNC(fmax) (0, 0), 0);
2281 check ("fmax (9, 0) = 9", FUNC(fmax) (9, 0), 9);
2282 check ("fmax (0, 9) = 9", FUNC(fmax) (0, 9), 9);
2283 check ("fmax (-9, 0) = 0", FUNC(fmax) (-9, 0), 0);
2284 check ("fmax (0, -9) = 0", FUNC(fmax) (0, -9), 0);
2286 check_isinfp ("fmax (+inf, 9) = +inf", FUNC(fmax) (plus_infty, 9));
2287 check_isinfp ("fmax (9, +inf) = +inf", FUNC(fmax) (0, plus_infty));
2288 check_isinfp ("fmax (-9, +inf) = +inf", FUNC(fmax) (-9, plus_infty));
2289 check_isinfp ("fmax (+inf, -9) = +inf", FUNC(fmax) (plus_infty, -9));
2290 check ("fmax (-inf, 9) = 9", FUNC(fmax) (minus_infty, 9), 9);
2291 check ("fmax (-inf, -9) = -9", FUNC(fmax) (minus_infty, -9), -9);
2292 check ("fmax (+9, -inf) = 9", FUNC(fmax) (9, minus_infty), 9);
2293 check ("fmax (-9, -inf) = -9", FUNC(fmax) (-9, minus_infty), -9);
2295 check ("fmax (0, NaN) = 0", FUNC(fmax) (0, nan_value), 0);
2296 check ("fmax (9, NaN) = 9", FUNC(fmax) (9, nan_value), 9);
2297 check ("fmax (-9, NaN) = 9", FUNC(fmax) (-9, nan_value), -9);
2298 check ("fmax (NaN, 0) = 0", FUNC(fmax) (nan_value, 0), 0);
2299 check ("fmax (NaN, 9) = NaN", FUNC(fmax) (nan_value, 9), 9);
2300 check ("fmax (NaN, -9) = NaN", FUNC(fmax) (nan_value, -9), -9);
2301 check_isinfp ("fmax (+inf, NaN) = +inf", FUNC(fmax) (plus_infty, nan_value));
2302 check_isinfn ("fmax (-inf, NaN) = -inf", FUNC(fmax) (minus_infty, nan_value));
2303 check_isinfp ("fmax (NaN, +inf) = +inf", FUNC(fmax) (nan_value, plus_infty));
2304 check_isinfn ("fmax (NaN, -inf) = -inf", FUNC(fmax) (nan_value, minus_infty));
2305 check_isnan ("fmax (NaN, NaN) = NaN", FUNC(fmax) (nan_value, nan_value));
2309 static void
2310 fmod_test (void)
2312 MATHTYPE x;
2314 x = random_greater (0);
2315 check_ext ("fmod (+0, y) == +0 for y != 0", FUNC(fmod) (0, x), 0, x);
2317 x = random_greater (0);
2318 check_ext ("fmod (-0, y) == -0 for y != 0", FUNC(fmod) (minus_zero, x),
2319 minus_zero, x);
2321 check_isnan_exc_ext ("fmod (+inf, y) == NaN plus invalid exception",
2322 FUNC(fmod) (plus_infty, x), INVALID_EXCEPTION, x);
2323 check_isnan_exc_ext ("fmod (-inf, y) == NaN plus invalid exception",
2324 FUNC(fmod) (minus_infty, x), INVALID_EXCEPTION, x);
2325 check_isnan_exc_ext ("fmod (x, +0) == NaN plus invalid exception",
2326 FUNC(fmod) (x, 0), INVALID_EXCEPTION, x);
2327 check_isnan_exc_ext ("fmod (x, -0) == NaN plus invalid exception",
2328 FUNC(fmod) (x, minus_zero), INVALID_EXCEPTION, x);
2330 x = random_greater (0);
2331 check_ext ("fmod (x, +inf) == x for x not infinite",
2332 FUNC(fmod) (x, plus_infty), x, x);
2333 x = random_greater (0);
2334 check_ext ("fmod (x, -inf) == x for x not infinite",
2335 FUNC(fmod) (x, minus_infty), x, x);
2337 check_eps ("fmod (6.5, 2.3) == 1.9", FUNC(fmod) (6.5, 2.3), 1.9,
2338 CHOOSE(5e-16, 1e-15, 2e-7));
2339 check_eps ("fmod (-6.5, 2.3) == -1.9", FUNC(fmod) (-6.5, 2.3), -1.9,
2340 CHOOSE(5e-16, 1e-15, 2e-7));
2341 check_eps ("fmod (6.5, -2.3) == 1.9", FUNC(fmod) (6.5, -2.3), 1.9,
2342 CHOOSE(5e-16, 1e-15, 2e-7));
2343 check_eps ("fmod (-6.5, -2.3) == -1.9", FUNC(fmod) (-6.5, -2.3), -1.9,
2344 CHOOSE(5e-16, 1e-15, 2e-7));
2350 static void
2351 nextafter_test (void)
2353 MATHTYPE x;
2355 check ("nextafter (+0, +0) = +0", FUNC(nextafter) (0, 0), 0);
2356 check ("nextafter (-0, +0) = +0", FUNC(nextafter) (minus_zero, 0), 0);
2357 check ("nextafter (+0, -0) = -0", FUNC(nextafter) (0, minus_zero),
2358 minus_zero);
2359 check ("nextafter (-0, -0) = -0", FUNC(nextafter) (minus_zero, minus_zero),
2360 minus_zero);
2362 check ("nextafter (9, 9) = 9", FUNC(nextafter) (9, 9), 9);
2363 check ("nextafter (-9, -9) = -9", FUNC(nextafter) (-9, -9), -9);
2364 check_isinfp ("nextafter (+inf, +inf) = +inf",
2365 FUNC(nextafter) (plus_infty, plus_infty));
2366 check_isinfn ("nextafter (-inf, -inf) = -inf",
2367 FUNC(nextafter) (minus_infty, minus_infty));
2369 x = rand () * 1.1;
2370 check_isnan ("nextafter (NaN, x) = NaN", FUNC(nextafter) (nan_value, x));
2371 check_isnan ("nextafter (x, NaN) = NaN", FUNC(nextafter) (x, nan_value));
2372 check_isnan ("nextafter (NaN, NaN) = NaN", FUNC(nextafter) (nan_value,
2373 nan_value));
2375 /* XXX We need the hexadecimal FP number representation here for further
2376 tests. */
2380 static void
2381 copysign_test (void)
2383 check ("copysign (0, 4) = 0", FUNC(copysign) (0, 4), 0);
2384 check ("copysign (0, -4) = -0", FUNC(copysign) (0, -4), minus_zero);
2385 check ("copysign (-0, 4) = 0", FUNC(copysign) (minus_zero, 4), 0);
2386 check ("copysign (-0, -4) = -0", FUNC(copysign) (minus_zero, -4),
2387 minus_zero);
2389 check_isinfp ("copysign (+inf, 0) = +inf", FUNC(copysign) (plus_infty, 0));
2390 check_isinfn ("copysign (+inf, -0) = -inf", FUNC(copysign) (plus_infty,
2391 minus_zero));
2392 check_isinfp ("copysign (-inf, 0) = +inf", FUNC(copysign) (minus_infty, 0));
2393 check_isinfn ("copysign (-inf, -0) = -inf", FUNC(copysign) (minus_infty,
2394 minus_zero));
2396 check ("copysign (0, +inf) = 0", FUNC(copysign) (0, plus_infty), 0);
2397 check ("copysign (0, -inf) = -0", FUNC(copysign) (0, minus_zero),
2398 minus_zero);
2399 check ("copysign (-0, +inf) = 0", FUNC(copysign) (minus_zero, plus_infty),
2401 check ("copysign (-0, -inf) = -0", FUNC(copysign) (minus_zero, minus_zero),
2402 minus_zero);
2404 /* XXX More correctly we would have to check the sign of the NaN. */
2405 check_isnan ("copysign (+NaN, 0) = +NaN", FUNC(copysign) (nan_value, 0));
2406 check_isnan ("copysign (+NaN, -0) = -NaN", FUNC(copysign) (nan_value,
2407 minus_zero));
2408 check_isnan ("copysign (-NaN, 0) = +NaN", FUNC(copysign) (-nan_value, 0));
2409 check_isnan ("copysign (-NaN, -0) = -NaN", FUNC(copysign) (-nan_value,
2410 minus_zero));
2414 static void
2415 trunc_test (void)
2417 check ("trunc(0) = 0", FUNC(trunc) (0), 0);
2418 check ("trunc(-0) = -0", FUNC(trunc) (minus_zero), minus_zero);
2419 check ("trunc(0.625) = 0", FUNC(trunc) (0.625), 0);
2420 check ("trunc(-0.625) = -0", FUNC(trunc) (-0.625), minus_zero);
2421 check ("trunc(1) = 1", FUNC(trunc) (1), 1);
2422 check ("trunc(-1) = -1", FUNC(trunc) (-1), -1);
2423 check ("trunc(1.625) = 1", FUNC(trunc) (1.625), 1);
2424 check ("trunc(-1.625) = -1", FUNC(trunc) (-1.625), -1);
2426 check ("trunc(1048580.625) = 1048580", FUNC(trunc) (1048580.625L),
2427 1048580L);
2428 check ("trunc(-1048580.625) = -1048580", FUNC(trunc) (-1048580.625L),
2429 -1048580L);
2431 check ("trunc(8388610.125) = 8388610", FUNC(trunc) (8388610.125L),
2432 8388610.0L);
2433 check ("trunc(-8388610.125) = -8388610", FUNC(trunc) (-8388610.125L),
2434 -8388610.0L);
2436 check ("trunc(4294967296.625) = 4294967296", FUNC(trunc) (4294967296.625L),
2437 4294967296.0L);
2438 check ("trunc(-4294967296.625) = -4294967296",
2439 FUNC(trunc) (-4294967296.625L), -4294967296.0L);
2441 check_isinfp ("trunc(+inf) = +inf", FUNC(trunc) (plus_infty));
2442 check_isinfn ("trunc(-inf) = -inf", FUNC(trunc) (minus_infty));
2443 check_isnan ("trunc(NaN) = NaN", FUNC(trunc) (nan_value));
2447 static void
2448 sqrt_test (void)
2450 MATHTYPE x;
2453 /* XXX Tests fuer negative x are missing */
2454 check ("sqrt (0) == 0", FUNC(sqrt) (0), 0);
2455 check_isnan ("sqrt (NaN) == NaN", FUNC(sqrt) (nan_value));
2456 check_isinfp ("sqrt (+inf) == +inf", FUNC(sqrt) (plus_infty));
2458 check ("sqrt (-0) == -0", FUNC(sqrt) (0), 0);
2460 x = random_less (0.0);
2461 check_isnan_exc_ext ("sqrt (x) == NaN plus invalid exception for x < 0",
2462 FUNC(sqrt) (x), INVALID_EXCEPTION, x);
2464 x = random_value (0, 10000);
2465 check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x);
2466 check ("sqrt (4) == 2", FUNC(sqrt) (4), 2);
2467 check ("sqrt (2) == 1.14142...", FUNC(sqrt) (2), M_SQRT2l);
2468 check ("sqrt (0.25) == 0.5", FUNC(sqrt) (0.25), 0.5);
2469 check ("sqrt (6642.25) == 81.5", FUNC(sqrt) (6642.25), 81.5);
2470 check_eps ("sqrt (15239.903) == 123.45", FUNC(sqrt) (15239.903), 123.45,
2471 CHOOSE (3e-6L, 3e-6, 8e-6));
2472 check_eps ("sqrt (0.7) == 0.8366600265", FUNC(sqrt) (0.7),
2473 0.83666002653407554798L, CHOOSE(3e-17L, 0, 0));
2476 static void
2477 remainder_test (void)
2479 MATHTYPE result;
2481 result = FUNC(remainder) (1, 0);
2482 check_isnan_exc ("remainder(1, +0) == NaN plus invalid exception",
2483 result, INVALID_EXCEPTION);
2485 result = FUNC(remainder) (1, minus_zero);
2486 check_isnan_exc ("remainder(1, -0) == NaN plus invalid exception",
2487 result, INVALID_EXCEPTION);
2489 result = FUNC(remainder) (plus_infty, 1);
2490 check_isnan_exc ("remainder(+inf, 1) == NaN plus invalid exception",
2491 result, INVALID_EXCEPTION);
2493 result = FUNC(remainder) (minus_infty, 1);
2494 check_isnan_exc ("remainder(-inf, 1) == NaN plus invalid exception",
2495 result, INVALID_EXCEPTION);
2497 result = FUNC(remainder) (1.625, 1.0);
2498 check ("remainder(1.625, 1.0) == -0.375", result, -0.375);
2500 result = FUNC(remainder) (-1.625, 1.0);
2501 check ("remainder(-1.625, 1.0) == 0.375", result, 0.375);
2503 result = FUNC(remainder) (1.625, -1.0);
2504 check ("remainder(1.625, -1.0) == -0.375", result, -0.375);
2506 result = FUNC(remainder) (-1.625, -1.0);
2507 check ("remainder(-1.625, -1.0) == 0.375", result, 0.375);
2509 result = FUNC(remainder) (5.0, 2.0);
2510 check ("remainder(5.0, 2.0) == 1.0", result, 1.0);
2512 result = FUNC(remainder) (3.0, 2.0);
2513 check ("remainder(3.0, 2.0) == -1.0", result, -1.0);
2517 static void
2518 remquo_test (void)
2520 int quo;
2521 MATHTYPE result;
2523 result = FUNC(remquo) (1, 0, &quo);
2524 check_isnan_exc ("remquo(1, +0, &x) == NaN plus invalid exception",
2525 result, INVALID_EXCEPTION);
2527 result = FUNC(remquo) (1, minus_zero, &quo);
2528 check_isnan_exc ("remquo(1, -0, &x) == NaN plus invalid exception",
2529 result, INVALID_EXCEPTION);
2531 result = FUNC(remquo) (plus_infty, 1, &quo);
2532 check_isnan_exc ("remquo(+inf, 1, &x) == NaN plus invalid exception",
2533 result, INVALID_EXCEPTION);
2535 result = FUNC(remquo) (minus_infty, 1, &quo);
2536 check_isnan_exc ("remquo(-inf, 1, &x) == NaN plus invalid exception",
2537 result, INVALID_EXCEPTION);
2539 result = FUNC(remquo) (1.625, 1.0, &quo);
2540 check ("remquo(1.625, 1.0, &x) == -0.375", result, -0.375);
2541 check_long ("remquo(1.625, 1.0, &x) puts 2 in x", quo, 2);
2543 result = FUNC(remquo) (-1.625, 1.0, &quo);
2544 check ("remquo(-1.625, 1.0, &x) == 0.375", result, 0.375);
2545 check_long ("remquo(-1.625, 1.0, &x) puts -2 in x", quo, -2);
2547 result = FUNC(remquo) (1.625, -1.0, &quo);
2548 check ("remquo(1.625, -1.0, &x) == -0.375", result, -0.375);
2549 check_long ("remquo(1.625, -1.0, &x) puts -2 in x", quo, -2);
2551 result = FUNC(remquo) (-1.625, -1.0, &quo);
2552 check ("remquo(-1.625, -1.0, &x) == 0.375", result, 0.375);
2553 check_long ("remquo(-1.625, -1.0, &x) puts 2 in x", quo, 2);
2555 result = FUNC(remquo) (5.0, 2.0, &quo);
2556 check ("remquo(5.0, 2.0, &x) == 1.0", result, 1.0);
2557 check_long ("remquo (5.0, 2.0, &x) puts 2 in x", quo, 2);
2559 result = FUNC(remquo) (3.0, 2.0, &quo);
2560 check ("remquo(3.0, 2.0, &x) == -1.0", result, -1.0);
2561 check_long ("remquo (3.0, 2.0, &x) puts 2 in x", quo, 2);
2565 static void
2566 cexp_test (void)
2568 __complex__ MATHTYPE result;
2570 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, plus_zero));
2571 check ("real(cexp(0 + 0i)) = 1", __real__ result, 1);
2572 check ("imag(cexp(0 + 0i)) = 0", __imag__ result, 0);
2573 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_zero));
2574 check ("real(cexp(-0 + 0i)) = 1", __real__ result, 1);
2575 check ("imag(cexp(-0 + 0i)) = 0", __imag__ result, 0);
2576 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, minus_zero));
2577 check ("real(cexp(0 - 0i)) = 1", __real__ result, 1);
2578 check ("imag(cexp(0 - 0i)) = -0", __imag__ result, minus_zero);
2579 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_zero));
2580 check ("real(cexp(-0 - 0i)) = 1", __real__ result, 1);
2581 check ("imag(cexp(-0 - 0i)) = -0", __imag__ result, minus_zero);
2583 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_zero));
2584 check_isinfp ("real(cexp(+inf + 0i)) = +inf", __real__ result);
2585 check ("imag(cexp(+inf + 0i)) = 0", __imag__ result, 0);
2586 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_zero));
2587 check_isinfp ("real(cexp(+inf - 0i)) = +inf", __real__ result);
2588 check ("imag(cexp(+inf - 0i)) = -0", __imag__ result, minus_zero);
2590 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_zero));
2591 check ("real(cexp(-inf + 0i)) = 0", __real__ result, 0);
2592 check ("imag(cexp(-inf + 0i)) = 0", __imag__ result, 0);
2593 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_zero));
2594 check ("real(cexp(-inf - 0i)) = 0", __real__ result, 0);
2595 check ("imag(cexp(-inf - 0i)) = -0", __imag__ result, minus_zero);
2598 result = FUNC(cexp) (BUILD_COMPLEX (0.0, plus_infty));
2599 check_isnan_exc ("real(cexp(0 + i inf)) = NaN plus invalid exception",
2600 __real__ result, INVALID_EXCEPTION);
2601 check_isnan ("imag(cexp(0 + i inf)) = NaN plus invalid exception",
2602 __imag__ result);
2604 #if defined __GNUC__ && __GNUC__ <= 2 && __GNUC_MINOR__ <= 7
2605 if (verbose)
2606 printf ("The following test for cexp might fail due to a gcc compiler error!\n");
2607 #endif
2609 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_infty));
2610 check_isnan_exc ("real(cexp(-0 + i inf)) = NaN plus invalid exception",
2611 __real__ result, INVALID_EXCEPTION);
2612 check_isnan ("imag(cexp(-0 + i inf)) = NaN plus invalid exception",
2613 __imag__ result);
2614 result = FUNC(cexp) (BUILD_COMPLEX (0.0, minus_infty));
2615 check_isnan_exc ("real(cexp(0 - i inf)) = NaN plus invalid exception",
2616 __real__ result, INVALID_EXCEPTION);
2617 check_isnan ("imag(cexp(0 - i inf)) = NaN plus invalid exception",
2618 __imag__ result);
2619 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_infty));
2620 check_isnan_exc ("real(cexp(-0 - i inf)) = NaN plus invalid exception",
2621 __real__ result, INVALID_EXCEPTION);
2622 check_isnan ("imag(cexp(-0 - i inf)) = NaN plus invalid exception",
2623 __imag__ result);
2625 result = FUNC(cexp) (BUILD_COMPLEX (100.0, plus_infty));
2626 check_isnan_exc ("real(cexp(100.0 + i inf)) = NaN plus invalid exception",
2627 __real__ result, INVALID_EXCEPTION);
2628 check_isnan ("imag(cexp(100.0 + i inf)) = NaN plus invalid exception",
2629 __imag__ result);
2630 result = FUNC(cexp) (BUILD_COMPLEX (-100.0, plus_infty));
2631 check_isnan_exc ("real(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2632 __real__ result, INVALID_EXCEPTION);
2633 check_isnan ("imag(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2634 __imag__ result);
2635 result = FUNC(cexp) (BUILD_COMPLEX (100.0, minus_infty));
2636 check_isnan_exc ("real(cexp(100.0 - i inf)) = NaN plus invalid exception",
2637 __real__ result, INVALID_EXCEPTION);
2638 check_isnan ("imag(cexp(100.0 - i inf)) = NaN plus invalid exception",
2639 __imag__ result);
2640 result = FUNC(cexp) (BUILD_COMPLEX (-100.0, minus_infty));
2641 check_isnan_exc ("real(cexp(-100.0 - i inf)) = NaN plus invalid exception",
2642 __real__ result, INVALID_EXCEPTION);
2643 check_isnan ("imag(cexp(-100.0 - i inf)) = NaN", __imag__ result);
2645 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 2.0));
2646 check ("real(cexp(-inf + 2.0i)) = -0", __real__ result, minus_zero);
2647 check ("imag(cexp(-inf + 2.0i)) = 0", __imag__ result, 0);
2648 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 4.0));
2649 check ("real(cexp(-inf + 4.0i)) = -0", __real__ result, minus_zero);
2650 check ("imag(cexp(-inf + 4.0i)) = -0", __imag__ result, minus_zero);
2652 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 2.0));
2653 check_isinfn ("real(cexp(+inf + 2.0i)) = -inf", __real__ result);
2654 check_isinfp ("imag(cexp(+inf + 2.0i)) = +inf", __imag__ result);
2655 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 4.0));
2656 check_isinfn ("real(cexp(+inf + 4.0i)) = -inf", __real__ result);
2657 check_isinfn ("imag(cexp(+inf + 4.0i)) = -inf", __imag__ result);
2659 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_infty));
2660 check_isinfp_exc ("real(cexp(+inf + i inf)) = +inf plus invalid exception",
2661 __real__ result, INVALID_EXCEPTION);
2662 check_isnan ("imag(cexp(+inf + i inf)) = NaN plus invalid exception",
2663 __imag__ result);
2664 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_infty));
2665 check_isinfp_exc ("real(cexp(+inf - i inf)) = +inf plus invalid exception",
2666 __real__ result, INVALID_EXCEPTION);
2667 check_isnan ("imag(cexp(+inf - i inf)) = NaN plus invalid exception",
2668 __imag__ result);
2670 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_infty));
2671 check ("real(cexp(-inf + i inf)) = 0", __real__ result, 0);
2672 check ("imag(cexp(-inf + i inf)) = 0", __imag__ result, 0);
2673 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_infty));
2674 check ("real(cexp(-inf - i inf)) = 0", __real__ result, 0);
2675 check ("imag(cexp(-inf - i inf)) = -0", __imag__ result, minus_zero);
2677 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, nan_value));
2678 check ("real(cexp(-inf + i NaN)) = 0", __real__ result, 0);
2679 check ("imag(cexp(-inf + i NaN)) = 0", fabs (__imag__ result), 0);
2681 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, nan_value));
2682 check_isinfp ("real(cexp(+inf + i NaN)) = +inf", __real__ result);
2683 check_isnan ("imag(cexp(+inf + i NaN)) = NaN", __imag__ result);
2685 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 0.0));
2686 check_isnan_maybe_exc ("real(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2687 __real__ result, INVALID_EXCEPTION);
2688 check_isnan ("imag(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2689 __imag__ result);
2690 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
2691 check_isnan_maybe_exc ("real(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2692 __real__ result, INVALID_EXCEPTION);
2693 check_isnan ("imag(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2694 __imag__ result);
2695 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, plus_infty));
2696 check_isnan_maybe_exc ("real(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2697 __real__ result, INVALID_EXCEPTION);
2698 check_isnan ("imag(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2699 __imag__ result);
2701 result = FUNC(cexp) (BUILD_COMPLEX (0, nan_value));
2702 check_isnan_maybe_exc ("real(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2703 __real__ result, INVALID_EXCEPTION);
2704 check_isnan ("imag(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2705 __imag__ result);
2706 result = FUNC(cexp) (BUILD_COMPLEX (1, nan_value));
2707 check_isnan_maybe_exc ("real(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2708 __real__ result, INVALID_EXCEPTION);
2709 check_isnan ("imag(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2710 __imag__ result);
2712 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, nan_value));
2713 check_isnan ("real(cexp(NaN + i NaN)) = NaN", __real__ result);
2714 check_isnan ("imag(cexp(NaN + i NaN)) = NaN", __imag__ result);
2716 result = FUNC(cexp) (BUILD_COMPLEX (0.7, 1.2));
2717 check_eps ("real(cexp(0.7 + i 1.2)) == 0.72969...", __real__ result,
2718 0.7296989091503236012L, CHOOSE(6e-17L, 2e-16, 2e-7));
2719 check_eps ("imag(cexp(0.7 + i 1.2)) == 1.87689...", __imag__ result,
2720 1.8768962328348102821L, CHOOSE(2e-16L, 0, 3e-7));
2722 result = FUNC(cexp) (BUILD_COMPLEX (-2, -3));
2723 check_eps ("real(cexp(-2 - i 3)) == -0.13398...", __real__ result,
2724 -0.1339809149295426134L, CHOOSE(6e-20L, 0, 2e-8));
2725 check_eps ("imag(cexp(-2 - i 3)) == -0.01909...", __imag__ result,
2726 -0.0190985162611351964L, CHOOSE(4e-20L, 0, 2e-9));
2730 static void
2731 csin_test (void)
2733 __complex__ MATHTYPE result;
2735 result = FUNC(csin) (BUILD_COMPLEX (0.0, 0.0));
2736 check ("real(csin(0 + 0i)) = 0", __real__ result, 0);
2737 check ("imag(csin(0 + 0i)) = 0", __imag__ result, 0);
2738 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, 0.0));
2739 check ("real(csin(-0 + 0i)) = -0", __real__ result, minus_zero);
2740 check ("imag(csin(-0 + 0i)) = 0", __imag__ result, 0);
2741 result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_zero));
2742 check ("real(csin(0 - 0i)) = 0", __real__ result, 0);
2743 check ("imag(csin(0 - 0i)) = -0", __imag__ result, minus_zero);
2744 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_zero));
2745 check ("real(csin(-0 - 0i)) = -0", __real__ result, minus_zero);
2746 check ("imag(csin(-0 - 0i)) = -0", __imag__ result, minus_zero);
2748 result = FUNC(csin) (BUILD_COMPLEX (0.0, plus_infty));
2749 check ("real(csin(0 + i Inf)) = 0", __real__ result, 0);
2750 check_isinfp ("imag(csin(0 + i Inf)) = +Inf", __imag__ result);
2751 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, plus_infty));
2752 check ("real(csin(-0 + i Inf)) = -0", __real__ result, minus_zero);
2753 check_isinfp ("imag(csin(-0 + i Inf)) = +Inf", __imag__ result);
2754 result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_infty));
2755 check ("real(csin(0 - i Inf)) = 0", __real__ result, 0);
2756 check_isinfn ("imag(csin(0 - i Inf)) = -Inf", __imag__ result);
2757 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_infty));
2758 check ("real(csin(-0 - i Inf)) = -0", __real__ result, minus_zero);
2759 check_isinfn("imag(csin(-0 - i Inf)) = -Inf", __imag__ result);
2761 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 0.0));
2762 check_isnan_exc ("real(csin(+Inf + 0i)) = NaN plus invalid exception",
2763 __real__ result, INVALID_EXCEPTION);
2764 check ("imag(csin(+Inf + 0i)) = +-0 plus invalid exception",
2765 FUNC(fabs) (__imag__ result), 0);
2766 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 0.0));
2767 check_isnan_exc ("real(csin(-Inf + 0i)) = NaN plus invalid exception",
2768 __real__ result, INVALID_EXCEPTION);
2769 check ("imag(csin(-Inf + 0i)) = +-0 plus invalid exception",
2770 FUNC(fabs) (__imag__ result), 0);
2771 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_zero));
2772 check_isnan_exc ("real(csin(+Inf - 0i)) = NaN plus invalid exception",
2773 __real__ result, INVALID_EXCEPTION);
2774 check ("imag(csin(+Inf - 0i)) = +-0 plus invalid exception",
2775 FUNC(fabs) (__imag__ result), 0.0);
2776 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_zero));
2777 check_isnan_exc ("real(csin(-Inf - 0i)) = NaN plus invalid exception",
2778 __real__ result, INVALID_EXCEPTION);
2779 check ("imag(csin(-Inf - 0i)) = +-0 plus invalid exception",
2780 FUNC(fabs) (__imag__ result), 0.0);
2782 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, plus_infty));
2783 check_isnan_exc ("real(csin(+Inf + i Inf)) = NaN plus invalid exception",
2784 __real__ result, INVALID_EXCEPTION);
2785 check_isinfp ("imag(csin(+Inf + i Inf)) = +-Inf plus invalid exception",
2786 FUNC(fabs) (__imag__ result));
2787 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, plus_infty));
2788 check_isnan_exc ("real(csin(-Inf + i Inf)) = NaN plus invalid exception",
2789 __real__ result, INVALID_EXCEPTION);
2790 check_isinfp ("imag(csin(-Inf + i Inf)) = +-Inf plus invalid exception",
2791 FUNC(fabs) (__imag__ result));
2792 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_infty));
2793 check_isnan_exc ("real(csin(Inf - i Inf)) = NaN plus invalid exception",
2794 __real__ result, INVALID_EXCEPTION);
2795 check_isinfp ("imag(csin(Inf - i Inf)) = +-Inf plus invalid exception",
2796 FUNC(fabs) (__imag__ result));
2797 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_infty));
2798 check_isnan_exc ("real(csin(-Inf - i Inf)) = NaN plus invalid exception",
2799 __real__ result, INVALID_EXCEPTION);
2800 check_isinfp ("imag(csin(-Inf - i Inf)) = +-Inf plus invalid exception",
2801 FUNC(fabs) (__imag__ result));
2803 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 6.75));
2804 check_isnan_exc ("real(csin(+Inf + i 6.75)) = NaN plus invalid exception",
2805 __real__ result, INVALID_EXCEPTION);
2806 check_isnan ("imag(csin(+Inf + i6.75)) = NaN plus invalid exception",
2807 __imag__ result);
2808 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, -6.75));
2809 check_isnan_exc ("real(csin(+Inf - i 6.75)) = NaN plus invalid exception",
2810 __real__ result, INVALID_EXCEPTION);
2811 check_isnan ("imag(csin(+Inf - i6.75)) = NaN plus invalid exception",
2812 __imag__ result);
2813 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 6.75));
2814 check_isnan_exc ("real(csin(-Inf + i6.75)) = NaN plus invalid exception",
2815 __real__ result, INVALID_EXCEPTION);
2816 check_isnan ("imag(csin(-Inf + i6.75)) = NaN plus invalid exception",
2817 __imag__ result);
2818 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, -6.75));
2819 check_isnan_exc ("real(csin(-Inf - i6.75)) = NaN plus invalid exception",
2820 __real__ result, INVALID_EXCEPTION);
2821 check_isnan ("imag(csin(-Inf - i6.75)) = NaN plus invalid exception",
2822 __imag__ result);
2824 result = FUNC(csin) (BUILD_COMPLEX (4.625, plus_infty));
2825 check_isinfn ("real(csin(4.625 + i Inf)) = -Inf", __real__ result);
2826 check_isinfn ("imag(csin(4.625 + i Inf)) = -Inf", __imag__ result);
2827 result = FUNC(csin) (BUILD_COMPLEX (4.625, minus_infty));
2828 check_isinfn ("real(csin(4.625 - i Inf)) = -Inf", __real__ result);
2829 check_isinfp ("imag(csin(4.625 - i Inf)) = +Inf", __imag__ result);
2830 result = FUNC(csin) (BUILD_COMPLEX (-4.625, plus_infty));
2831 check_isinfp ("real(csin(-4.625 + i Inf)) = +Inf", __real__ result);
2832 check_isinfn ("imag(csin(-4.625 + i Inf)) = -Inf", __imag__ result);
2833 result = FUNC(csin) (BUILD_COMPLEX (-4.625, minus_infty));
2834 check_isinfp ("real(csin(-4.625 - i Inf)) = +Inf", __real__ result);
2835 check_isinfp ("imag(csin(-4.625 - i Inf)) = +Inf", __imag__ result);
2837 result = FUNC(csin) (BUILD_COMPLEX (nan_value, 0.0));
2838 check_isnan ("real(csin(NaN + i0)) = NaN", __real__ result);
2839 check ("imag(csin(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2840 result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_zero));
2841 check_isnan ("real(csin(NaN - i0)) = NaN", __real__ result);
2842 check ("imag(csin(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2844 result = FUNC(csin) (BUILD_COMPLEX (nan_value, plus_infty));
2845 check_isnan ("real(csin(NaN + i Inf)) = NaN", __real__ result);
2846 check_isinfp ("imag(csin(NaN + i Inf)) = +-Inf",
2847 FUNC(fabs) (__imag__ result));
2848 result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_infty));
2849 check_isnan ("real(csin(NaN - i Inf)) = NaN", __real__ result);
2850 check_isinfp ("real(csin(NaN - i Inf)) = +-Inf",
2851 FUNC(fabs) (__imag__ result));
2853 result = FUNC(csin) (BUILD_COMPLEX (nan_value, 9.0));
2854 check_isnan_maybe_exc ("real(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2855 __real__ result, INVALID_EXCEPTION);
2856 check_isnan ("imag(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2857 __imag__ result);
2858 result = FUNC(csin) (BUILD_COMPLEX (nan_value, -9.0));
2859 check_isnan_maybe_exc ("real(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2860 __real__ result, INVALID_EXCEPTION);
2861 check_isnan ("imag(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2862 __imag__ result);
2864 result = FUNC(csin) (BUILD_COMPLEX (0.0, nan_value));
2865 check ("real(csin(0 + i NaN))", __real__ result, 0.0);
2866 check_isnan ("imag(csin(0 + i NaN)) = NaN", __imag__ result);
2867 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, nan_value));
2868 check ("real(csin(-0 + i NaN)) = -0", __real__ result, minus_zero);
2869 check_isnan ("imag(csin(-0 + NaN)) = NaN", __imag__ result);
2871 result = FUNC(csin) (BUILD_COMPLEX (10.0, nan_value));
2872 check_isnan_maybe_exc ("real(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2873 __real__ result, INVALID_EXCEPTION);
2874 check_isnan ("imag(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2875 __imag__ result);
2876 result = FUNC(csin) (BUILD_COMPLEX (nan_value, -10.0));
2877 check_isnan_maybe_exc ("real(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2878 __real__ result, INVALID_EXCEPTION);
2879 check_isnan ("imag(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2880 __imag__ result);
2882 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, nan_value));
2883 check_isnan_maybe_exc ("real(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2884 __real__ result, INVALID_EXCEPTION);
2885 check_isnan ("imag(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2886 __imag__ result);
2887 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, nan_value));
2888 check_isnan_maybe_exc ("real(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2889 __real__ result, INVALID_EXCEPTION);
2890 check_isnan ("imag(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2891 __imag__ result);
2893 result = FUNC(csin) (BUILD_COMPLEX (nan_value, nan_value));
2894 check_isnan ("real(csin(NaN + i NaN)) = NaN", __real__ result);
2895 check_isnan ("imag(csin(NaN + i NaN)) = NaN", __imag__ result);
2897 result = FUNC(csin) (BUILD_COMPLEX (0.7, 1.2));
2898 check_eps ("real(csin(0.7 + i 1.2)) = 1.166456341...", __real__ result,
2899 1.1664563419657581376L, CHOOSE(2e-16L, 0, 0));
2900 check_eps ("imag(csin(0.7 + i 1.2)) = 1.154499724...", __imag__ result,
2901 1.1544997246948547371L, CHOOSE(2e-17L, 0, 2e-7));
2903 result = FUNC(csin) (BUILD_COMPLEX (-2, -3));
2904 check_eps ("real(csin(-2 - i 3)) == -9.15449...", __real__ result,
2905 -9.1544991469114295734L, CHOOSE(4e-18L, 0, 1e-6));
2906 check_eps ("imag(csin(-2 - i 3)) == -4.16890...", __imag__ result,
2907 4.1689069599665643507L, CHOOSE(2e-17L, 0, 5e-7));
2911 static void
2912 csinh_test (void)
2914 __complex__ MATHTYPE result;
2916 result = FUNC(csinh) (BUILD_COMPLEX (0.0, 0.0));
2917 check ("real(csinh(0 + 0i)) = 0", __real__ result, 0);
2918 check ("imag(csinh(0 + 0i)) = 0", __imag__ result, 0);
2919 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, 0.0));
2920 check ("real(csinh(-0 + 0i)) = -0", __real__ result, minus_zero);
2921 check ("imag(csinh(-0 + 0i)) = 0", __imag__ result, 0);
2922 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_zero));
2923 check ("real(csinh(0 - 0i)) = 0", __real__ result, 0);
2924 check ("imag(csinh(0 - 0i)) = -0", __imag__ result, minus_zero);
2925 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_zero));
2926 check ("real(csinh(-0 - 0i)) = -0", __real__ result, minus_zero);
2927 check ("imag(csinh(-0 - 0i)) = -0", __imag__ result, minus_zero);
2929 result = FUNC(csinh) (BUILD_COMPLEX (0.0, plus_infty));
2930 check_exc ("real(csinh(0 + i Inf)) = +-0 plus invalid exception",
2931 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2932 check_isnan ("imag(csinh(0 + i Inf)) = NaN plus invalid exception",
2933 __imag__ result);
2934 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, plus_infty));
2935 check_exc ("real(csinh(-0 + i Inf)) = +-0 plus invalid exception",
2936 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2937 check_isnan ("imag(csinh(-0 + i Inf)) = NaN plus invalid exception",
2938 __imag__ result);
2939 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_infty));
2940 check_exc ("real(csinh(0 - i Inf)) = +-0 plus invalid exception",
2941 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2942 check_isnan ("imag(csinh(0 - i Inf)) = NaN plus invalid exception",
2943 __imag__ result);
2944 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_infty));
2945 check_exc ("real(csinh(-0 - i Inf)) = +-0 plus invalid exception",
2946 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2947 check_isnan ("imag(csinh(-0 - i Inf)) = NaN plus invalid exception",
2948 __imag__ result);
2950 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 0.0));
2951 check_isinfp ("real(csinh(+Inf + 0i)) = +Inf", __real__ result);
2952 check ("imag(csinh(+Inf + 0i)) = 0", __imag__ result, 0);
2953 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 0.0));
2954 check_isinfn ("real(csinh(-Inf + 0i)) = -Inf", __real__ result);
2955 check ("imag(csinh(-Inf + 0i)) = 0", __imag__ result, 0);
2956 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_zero));
2957 check_isinfp ("real(csinh(+Inf - 0i)) = +Inf", __real__ result);
2958 check ("imag(csinh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
2959 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_zero));
2960 check_isinfn ("real(csinh(-Inf - 0i)) = -Inf", __real__ result);
2961 check ("imag(csinh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
2963 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, plus_infty));
2964 check_isinfp_exc ("real(csinh(+Inf + i Inf)) = +-Inf plus invalid exception",
2965 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2966 check_isnan ("imag(csinh(+Inf + i Inf)) = NaN plus invalid exception",
2967 __imag__ result);
2968 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, plus_infty));
2969 check_isinfp_exc ("real(csinh(-Inf + i Inf)) = +-Inf plus invalid exception",
2970 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2971 check_isnan ("imag(csinh(-Inf + i Inf)) = NaN plus invalid exception",
2972 __imag__ result);
2973 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_infty));
2974 check_isinfp_exc ("real(csinh(Inf - i Inf)) = +-Inf plus invalid exception",
2975 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2976 check_isnan ("imag(csinh(Inf - i Inf)) = NaN plus invalid exception",
2977 __imag__ result);
2978 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_infty));
2979 check_isinfp_exc ("real(csinh(-Inf - i Inf)) = +-Inf plus invalid exception",
2980 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2981 check_isnan ("imag(csinh(-Inf - i Inf)) = NaN plus invalid exception",
2982 __imag__ result);
2984 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 4.625));
2985 check_isinfn ("real(csinh(+Inf + i4.625)) = -Inf", __real__ result);
2986 check_isinfn ("imag(csinh(+Inf + i4.625)) = -Inf", __imag__ result);
2987 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 4.625));
2988 check_isinfp ("real(csinh(-Inf + i4.625)) = +Inf", __real__ result);
2989 check_isinfn ("imag(csinh(-Inf + i4.625)) = -Inf", __imag__ result);
2990 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, -4.625));
2991 check_isinfn ("real(csinh(+Inf - i4.625)) = -Inf", __real__ result);
2992 check_isinfp ("imag(csinh(+Inf - i4.625)) = +Inf", __imag__ result);
2993 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, -4.625));
2994 check_isinfp ("real(csinh(-Inf - i4.625)) = +Inf", __real__ result);
2995 check_isinfp ("imag(csinh(-Inf - i4.625)) = +Inf", __imag__ result);
2997 result = FUNC(csinh) (BUILD_COMPLEX (6.75, plus_infty));
2998 check_isnan_exc ("real(csinh(6.75 + i Inf)) = NaN plus invalid exception",
2999 __real__ result, INVALID_EXCEPTION);
3000 check_isnan ("imag(csinh(6.75 + i Inf)) = NaN plus invalid exception",
3001 __imag__ result);
3002 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, plus_infty));
3003 check_isnan_exc ("real(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
3004 __real__ result, INVALID_EXCEPTION);
3005 check_isnan ("imag(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
3006 __imag__ result);
3007 result = FUNC(csinh) (BUILD_COMPLEX (6.75, minus_infty));
3008 check_isnan_exc ("real(csinh(6.75 - i Inf)) = NaN plus invalid exception",
3009 __real__ result, INVALID_EXCEPTION);
3010 check_isnan ("imag(csinh(6.75 - i Inf)) = NaN plus invalid exception",
3011 __imag__ result);
3012 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, minus_infty));
3013 check_isnan_exc ("real(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
3014 __real__ result, INVALID_EXCEPTION);
3015 check_isnan ("imag(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
3016 __imag__ result);
3018 result = FUNC(csinh) (BUILD_COMPLEX (0.0, nan_value));
3019 check ("real(csinh(0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
3020 check_isnan ("imag(csinh(0 + i NaN)) = NaN", __imag__ result);
3021 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, nan_value));
3022 check ("real(csinh(-0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
3023 check_isnan ("imag(csinh(-0 + i NaN)) = NaN", __imag__ result);
3025 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, nan_value));
3026 check_isinfp ("real(csinh(+Inf + i NaN)) = +-Inf",
3027 FUNC(fabs) (__real__ result));
3028 check_isnan ("imag(csinh(+Inf + i NaN)) = NaN", __imag__ result);
3029 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, nan_value));
3030 check_isinfp ("real(csinh(-Inf + i NaN)) = +-Inf",
3031 FUNC(fabs) (__real__ result));
3032 check_isnan ("imag(csinh(-Inf + i NaN)) = NaN", __imag__ result);
3034 result = FUNC(csinh) (BUILD_COMPLEX (9.0, nan_value));
3035 check_isnan_maybe_exc ("real(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3036 __real__ result, INVALID_EXCEPTION);
3037 check_isnan ("imag(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3038 __imag__ result);
3039 result = FUNC(csinh) (BUILD_COMPLEX (-9.0, nan_value));
3040 check_isnan_maybe_exc ("real(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3041 __real__ result, INVALID_EXCEPTION);
3042 check_isnan ("imag(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3043 __imag__ result);
3045 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 0.0));
3046 check_isnan ("real(csinh(NaN + i0)) = NaN", __real__ result);
3047 check ("imag(csinh(NaN + i0)) = 0", __imag__ result, 0.0);
3048 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_zero));
3049 check_isnan ("real(csinh(NaN - i0)) = NaN", __real__ result);
3050 check ("imag(csinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3052 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 10.0));
3053 check_isnan_maybe_exc ("real(csinh(NaN + i10)) = NaN plus maybe invalid exception",
3054 __real__ result, INVALID_EXCEPTION);
3055 check_isnan ("imag(csinh(NaN + i10)) = NaN plus maybe invalid exception",
3056 __imag__ result);
3057 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, -10.0));
3058 check_isnan_maybe_exc ("real(csinh(NaN - i10)) = NaN plus maybe invalid exception",
3059 __real__ result, INVALID_EXCEPTION);
3060 check_isnan ("imag(csinh(NaN - i10)) = NaN plus maybe invalid exception",
3061 __imag__ result);
3063 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, plus_infty));
3064 check_isnan_maybe_exc ("real(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
3065 __real__ result, INVALID_EXCEPTION);
3066 check_isnan ("imag(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
3067 __imag__ result);
3068 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_infty));
3069 check_isnan_maybe_exc ("real(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
3070 __real__ result, INVALID_EXCEPTION);
3071 check_isnan ("imag(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
3072 __imag__ result);
3074 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, nan_value));
3075 check_isnan ("real(csinh(NaN + i NaN)) = NaN", __real__ result);
3076 check_isnan ("imag(csinh(NaN + i NaN)) = NaN", __imag__ result);
3078 result = FUNC(csinh) (BUILD_COMPLEX (0.7, 1.2));
3079 check_eps ("real(csinh(0.7 + i 1.2)) = 0.274878686...", __real__ result,
3080 0.27487868678117583582L, CHOOSE(2e-17L, 6e-17, 3e-8));
3081 check_eps ("imag(csinh(0.7 + i 1.2)) = 1.169866572...", __imag__ result,
3082 1.1698665727426565139L, CHOOSE(6e-17L, 0, 2e-7));
3084 result = FUNC(csinh) (BUILD_COMPLEX (-2, -3));
3085 check_eps ("real(csinh(-2 - i 3)) == -3.59056...", __real__ result,
3086 3.5905645899857799520L, CHOOSE(7e-19L, 5e-16, 3e-7));
3087 check_eps ("imag(csinh(-2 - i 3)) == -0.53092...", __imag__ result,
3088 -0.5309210862485198052L, CHOOSE(3e-19L, 2e-16, 6e-8));
3092 static void
3093 ccos_test (void)
3095 __complex__ MATHTYPE result;
3097 result = FUNC(ccos) (BUILD_COMPLEX (0.0, 0.0));
3098 check ("real(ccos(0 + 0i)) = 1.0", __real__ result, 1.0);
3099 check ("imag(ccos(0 + 0i)) = -0", __imag__ result, minus_zero);
3100 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, 0.0));
3101 check ("real(ccos(-0 + 0i)) = 1.0", __real__ result, 1.0);
3102 check ("imag(ccos(-0 + 0i)) = 0", __imag__ result, 0.0);
3103 result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_zero));
3104 check ("real(ccos(0 - 0i)) = 1.0", __real__ result, 1.0);
3105 check ("imag(ccos(0 - 0i)) = 0", __imag__ result, 0.0);
3106 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_zero));
3107 check ("real(ccos(-0 - 0i)) = 1.0", __real__ result, 1.0);
3108 check ("imag(ccos(-0 - 0i)) = -0", __imag__ result, minus_zero);
3110 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 0.0));
3111 check_isnan_exc ("real(ccos(+Inf + i0)) = NaN plus invalid exception",
3112 __real__ result, INVALID_EXCEPTION);
3113 check ("imag(ccos(Inf + i0)) = +-0 plus invalid exception",
3114 FUNC(fabs) (__imag__ result), 0);
3115 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_zero));
3116 check_isnan_exc ("real(ccos(Inf - i0)) = NaN plus invalid exception",
3117 __real__ result, INVALID_EXCEPTION);
3118 check ("imag(ccos(Inf - i0)) = +-0 plus invalid exception",
3119 FUNC(fabs) (__imag__ result), 0);
3120 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 0.0));
3121 check_isnan_exc ("real(ccos(-Inf + i0)) = NaN plus invalid exception",
3122 __real__ result, INVALID_EXCEPTION);
3123 check ("imag(ccos(-Inf + i0)) = +-0 plus invalid exception",
3124 FUNC(fabs) (__imag__ result), 0);
3125 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_zero));
3126 check_isnan_exc ("real(ccos(-Inf - i0)) = NaN plus invalid exception",
3127 __real__ result, INVALID_EXCEPTION);
3128 check ("imag(ccos(-Inf - i0)) = +-0 plus invalid exception",
3129 FUNC(fabs) (__imag__ result), 0);
3131 result = FUNC(ccos) (BUILD_COMPLEX (0.0, plus_infty));
3132 check_isinfp ("real(ccos(0 + i Inf)) = +Inf", __real__ result);
3133 check ("imag(ccos(0 + i Inf)) = -0", __imag__ result, minus_zero);
3134 result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_infty));
3135 check_isinfp ("real(ccos(0 - i Inf)) = +Inf", __real__ result);
3136 check ("imag(ccos(0 - i Inf)) = 0", __imag__ result, 0);
3137 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, plus_infty));
3138 check_isinfp ("real(ccos(-0 + i Inf)) = +Inf", __real__ result);
3139 check ("imag(ccos(-0 + i Inf)) = 0", __imag__ result, 0.0);
3140 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_infty));
3141 check_isinfp ("real(ccos(-0 - i Inf)) = +Inf", __real__ result);
3142 check ("imag(ccos(-0 - i Inf)) = -0", __imag__ result, minus_zero);
3144 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, plus_infty));
3145 check_isinfp_exc ("real(ccos(+Inf + i Inf)) = +Inf plus invalid exception",
3146 __real__ result, INVALID_EXCEPTION);
3147 check_isnan ("imag(ccos(+Inf + i Inf)) = NaN plus invalid exception",
3148 __imag__ result);
3149 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, plus_infty));
3150 check_isinfp_exc ("real(ccos(-Inf + i Inf)) = +Inf plus invalid exception",
3151 __real__ result, INVALID_EXCEPTION);
3152 check_isnan ("imag(ccos(-Inf + i Inf)) = NaN plus invalid exception",
3153 __imag__ result);
3154 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_infty));
3155 check_isinfp_exc ("real(ccos(Inf - i Inf)) = +Inf plus invalid exception",
3156 __real__ result, INVALID_EXCEPTION);
3157 check_isnan ("imag(ccos(Inf - i Inf)) = NaN plus invalid exception",
3158 __imag__ result);
3159 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_infty));
3160 check_isinfp_exc ("real(ccos(-Inf - i Inf)) = +Inf plus invalid exception",
3161 __real__ result, INVALID_EXCEPTION);
3162 check_isnan ("imag(ccos(-Inf - i Inf)) = NaN plus invalid exception",
3163 __imag__ result);
3165 result = FUNC(ccos) (BUILD_COMPLEX (4.625, plus_infty));
3166 check_isinfn ("real(ccos(4.625 + i Inf)) = -Inf", __real__ result);
3167 check_isinfp ("imag(ccos(4.625 + i Inf)) = +Inf", __imag__ result);
3168 result = FUNC(ccos) (BUILD_COMPLEX (4.625, minus_infty));
3169 check_isinfn ("real(ccos(4.625 - i Inf)) = -Inf", __real__ result);
3170 check_isinfn ("imag(ccos(4.625 - i Inf)) = -Inf", __imag__ result);
3171 result = FUNC(ccos) (BUILD_COMPLEX (-4.625, plus_infty));
3172 check_isinfn ("real(ccos(-4.625 + i Inf)) = -Inf", __real__ result);
3173 check_isinfn ("imag(ccos(-4.625 + i Inf)) = -Inf", __imag__ result);
3174 result = FUNC(ccos) (BUILD_COMPLEX (-4.625, minus_infty));
3175 check_isinfn ("real(ccos(-4.625 - i Inf)) = -Inf", __real__ result);
3176 check_isinfp ("imag(ccos(-4.625 - i Inf)) = +Inf", __imag__ result);
3178 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 6.75));
3179 check_isnan_exc ("real(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3180 __real__ result, INVALID_EXCEPTION);
3181 check_isnan ("imag(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3182 __imag__ result);
3183 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, -6.75));
3184 check_isnan_exc ("real(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3185 __real__ result, INVALID_EXCEPTION);
3186 check_isnan ("imag(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3187 __imag__ result);
3188 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 6.75));
3189 check_isnan_exc ("real(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3190 __real__ result, INVALID_EXCEPTION);
3191 check_isnan ("imag(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3192 __imag__ result);
3193 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, -6.75));
3194 check_isnan_exc ("real(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3195 __real__ result, INVALID_EXCEPTION);
3196 check_isnan ("imag(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3197 __imag__ result);
3199 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 0.0));
3200 check_isnan ("real(ccos(NaN + i0)) = NaN", __real__ result);
3201 check ("imag(ccos(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3202 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_zero));
3203 check_isnan ("real(ccos(NaN - i0)) = NaN", __real__ result);
3204 check ("imag(ccos(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3206 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, plus_infty));
3207 check_isinfp ("real(ccos(NaN + i Inf)) = +Inf", __real__ result);
3208 check_isnan ("imag(ccos(NaN + i Inf)) = NaN", __imag__ result);
3209 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_infty));
3210 check_isinfp ("real(ccos(NaN - i Inf)) = +Inf", __real__ result);
3211 check_isnan ("imag(ccos(NaN - i Inf)) = NaN", __imag__ result);
3213 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 9.0));
3214 check_isnan_maybe_exc ("real(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3215 __real__ result, INVALID_EXCEPTION);
3216 check_isnan ("imag(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3217 __imag__ result);
3218 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, -9.0));
3219 check_isnan_maybe_exc ("real(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3220 __real__ result, INVALID_EXCEPTION);
3221 check_isnan ("imag(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3222 __imag__ result);
3224 result = FUNC(ccos) (BUILD_COMPLEX (0.0, nan_value));
3225 check_isnan ("real(ccos(0 + i NaN)) = NaN", __real__ result);
3226 check ("imag(ccos(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3227 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, nan_value));
3228 check_isnan ("real(ccos(-0 + i NaN)) = NaN", __real__ result);
3229 check ("imag(ccos(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3231 result = FUNC(ccos) (BUILD_COMPLEX (10.0, nan_value));
3232 check_isnan_maybe_exc ("real(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3233 __real__ result, INVALID_EXCEPTION);
3234 check_isnan ("imag(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3235 __imag__ result);
3236 result = FUNC(ccos) (BUILD_COMPLEX (-10.0, nan_value));
3237 check_isnan_maybe_exc ("real(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3238 __real__ result, INVALID_EXCEPTION);
3239 check_isnan ("imag(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3240 __imag__ result);
3242 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, nan_value));
3243 check_isnan_maybe_exc ("real(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3244 __real__ result, INVALID_EXCEPTION);
3245 check_isnan ("imag(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3246 __imag__ result);
3247 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, nan_value));
3248 check_isnan_maybe_exc ("real(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3249 __real__ result, INVALID_EXCEPTION);
3250 check_isnan ("imag(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3251 __imag__ result);
3253 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, nan_value));
3254 check_isnan ("real(ccos(NaN + i NaN)) = NaN", __real__ result);
3255 check_isnan ("imag(ccos(NaN + i NaN)) = NaN", __imag__ result);
3257 result = FUNC(ccos) (BUILD_COMPLEX (0.7, 1.2));
3258 check_eps ("real(ccos(0.7 + i 1.2)) = 1.384865764...", __real__ result,
3259 1.3848657645312111080L, CHOOSE(4e-18L, 3e-16, 2e-7));
3260 check_eps ("imag(ccos(0.7 + i 1.2)) = -0.972421703...", __imag__ result,
3261 -0.97242170335830028619L, CHOOSE(2e-16L, 2e-16, 0));
3263 result = FUNC(ccos) (BUILD_COMPLEX (-2, -3));
3264 check_eps ("real(ccos(-2 - i 3)) == -4.18962...", __real__ result,
3265 -4.1896256909688072301L, CHOOSE(2e-17L, 0, 5e-7));
3266 check_eps ("imag(ccos(-2 - i 3)) == -9.10922...", __imag__ result,
3267 -9.1092278937553365979L, CHOOSE(3e-18L, 0, 1e-6));
3271 static void
3272 ccosh_test (void)
3274 __complex__ MATHTYPE result;
3276 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, 0.0));
3277 check ("real(ccosh(0 + 0i)) = 1.0", __real__ result, 1.0);
3278 check ("imag(ccosh(0 + 0i)) = 0", __imag__ result, 0);
3279 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, 0.0));
3280 check ("real(ccosh(-0 + 0i)) = 1.0", __real__ result, 1.0);
3281 check ("imag(ccosh(-0 + 0i)) = -0", __imag__ result, minus_zero);
3282 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_zero));
3283 check ("real(ccosh(0 - 0i)) = 1.0", __real__ result, 1.0);
3284 check ("imag(ccosh(0 - 0i)) = -0", __imag__ result, minus_zero);
3285 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3286 check ("real(ccosh(-0 - 0i)) = 1.0", __real__ result, 1.0);
3287 check ("imag(ccosh(-0 - 0i)) = 0", __imag__ result, 0.0);
3289 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, plus_infty));
3290 check_isnan_exc ("real(ccosh(0 + i Inf)) = NaN plus invalid exception",
3291 __real__ result, INVALID_EXCEPTION);
3292 check ("imag(ccosh(0 + i Inf)) = +-0 plus invalid exception",
3293 FUNC(fabs) (__imag__ result), 0);
3294 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, plus_infty));
3295 check_isnan_exc ("real(ccosh(-0 + i Inf)) = NaN plus invalid exception",
3296 __real__ result, INVALID_EXCEPTION);
3297 check ("imag(ccosh(-0 + i Inf)) = +-0 plus invalid exception",
3298 FUNC(fabs) (__imag__ result), 0);
3299 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_infty));
3300 check_isnan_exc ("real(ccosh(0 - i Inf)) = NaN plus invalid exception",
3301 __real__ result, INVALID_EXCEPTION);
3302 check ("imag(ccosh(0 - i Inf)) = +-0 plus invalid exception",
3303 FUNC(fabs) (__imag__ result), 0);
3304 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_infty));
3305 check_isnan_exc ("real(ccosh(-0 - i Inf)) = NaN plus invalid exception",
3306 __real__ result, INVALID_EXCEPTION);
3307 check ("imag(ccosh(-0 - i Inf)) = +-0 plus invalid exception",
3308 FUNC(fabs) (__imag__ result), 0);
3310 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 0.0));
3311 check_isinfp ("real(ccosh(+Inf + 0i)) = +Inf", __real__ result);
3312 check ("imag(ccosh(+Inf + 0i)) = 0", __imag__ result, 0);
3313 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 0.0));
3314 check_isinfp ("real(ccosh(-Inf + 0i)) = +Inf", __real__ result);
3315 check ("imag(ccosh(-Inf + 0i)) = -0", __imag__ result, minus_zero);
3316 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3317 check_isinfp ("real(ccosh(+Inf - 0i)) = +Inf", __real__ result);
3318 check ("imag(ccosh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
3319 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3320 check_isinfp ("real(ccosh(-Inf - 0i)) = +Inf", __real__ result);
3321 check ("imag(ccosh(-Inf - 0i)) = 0", __imag__ result, 0.0);
3323 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3324 check_isinfp_exc ("real(ccosh(+Inf + i Inf)) = +Inf plus invalid exception",
3325 __real__ result, INVALID_EXCEPTION);
3326 check_isnan ("imag(ccosh(+Inf + i Inf)) = NaN plus invalid exception",
3327 __imag__ result);
3328 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3329 check_isinfp_exc ("real(ccosh(-Inf + i Inf)) = +Inf plus invalid exception",
3330 __real__ result, INVALID_EXCEPTION);
3331 check_isnan ("imag(ccosh(-Inf + i Inf)) = NaN plus invalid exception",
3332 __imag__ result);
3333 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3334 check_isinfp_exc ("real(ccosh(Inf - i Inf)) = +Inf plus invalid exception",
3335 __real__ result, INVALID_EXCEPTION);
3336 check_isnan ("imag(ccosh(Inf - i Inf)) = NaN plus invalid exception",
3337 __imag__ result);
3338 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3339 check_isinfp_exc ("real(ccosh(-Inf - i Inf)) = +Inf plus invalid exception",
3340 __real__ result, INVALID_EXCEPTION);
3341 check_isnan ("imag(ccosh(-Inf - i Inf)) = NaN plus invalid exception",
3342 __imag__ result);
3344 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 4.625));
3345 check_isinfn ("real(ccosh(+Inf + i4.625)) = -Inf", __real__ result);
3346 check_isinfn ("imag(ccosh(+Inf + i4.625)) = -Inf", __imag__ result);
3347 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 4.625));
3348 check_isinfn ("real(ccosh(-Inf + i4.625)) = -Inf", __real__ result);
3349 check_isinfp ("imag(ccosh(-Inf + i4.625)) = Inf", __imag__ result);
3350 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, -4.625));
3351 check_isinfn ("real(ccosh(+Inf - i4.625)) = -Inf", __real__ result);
3352 check_isinfp ("imag(ccosh(+Inf - i4.625)) = +Inf", __imag__ result);
3353 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, -4.625));
3354 check_isinfn ("real(ccosh(-Inf - i4.625)) = -Inf", __real__ result);
3355 check_isinfn ("imag(ccosh(-Inf - i4.625)) = -Inf", __imag__ result);
3357 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, plus_infty));
3358 check_isnan_exc ("real(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3359 __real__ result, INVALID_EXCEPTION);
3360 check_isnan ("imag(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3361 __imag__ result);
3362 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, plus_infty));
3363 check_isnan_exc ("real(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3364 __real__ result, INVALID_EXCEPTION);
3365 check_isnan ("imag(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3366 __imag__ result);
3367 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, minus_infty));
3368 check_isnan_exc ("real(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3369 __real__ result, INVALID_EXCEPTION);
3370 check_isnan ("imag(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3371 __imag__ result);
3372 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, minus_infty));
3373 check_isnan_exc ("real(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3374 __real__ result, INVALID_EXCEPTION);
3375 check_isnan ("imag(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3376 __imag__ result);
3378 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, nan_value));
3379 check_isnan ("real(ccosh(0 + i NaN)) = NaN", __real__ result);
3380 check ("imag(ccosh(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3381 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, nan_value));
3382 check_isnan ("real(ccosh(-0 + i NaN)) = NaN", __real__ result);
3383 check ("imag(ccosh(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3385 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, nan_value));
3386 check_isinfp ("real(ccosh(+Inf + i NaN)) = +Inf", __real__ result);
3387 check_isnan ("imag(ccosh(+Inf + i NaN)) = NaN", __imag__ result);
3388 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, nan_value));
3389 check_isinfp ("real(ccosh(-Inf + i NaN)) = +Inf", __real__ result);
3390 check_isnan ("imag(ccosh(-Inf + i NaN)) = NaN", __imag__ result);
3392 result = FUNC(ccosh) (BUILD_COMPLEX (9.0, nan_value));
3393 check_isnan_maybe_exc ("real(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3394 __real__ result, INVALID_EXCEPTION);
3395 check_isnan ("imag(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3396 __imag__ result);
3397 result = FUNC(ccosh) (BUILD_COMPLEX (-9.0, nan_value));
3398 check_isnan_maybe_exc ("real(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3399 __real__ result, INVALID_EXCEPTION);
3400 check_isnan ("imag(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3401 __imag__ result);
3403 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 0.0));
3404 check_isnan ("real(ccosh(NaN + i0)) = NaN", __real__ result);
3405 check ("imag(ccosh(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3406 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_zero));
3407 check_isnan ("real(ccosh(NaN - i0)) = NaN", __real__ result);
3408 check ("imag(ccosh(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3410 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 10.0));
3411 check_isnan_maybe_exc ("real(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3412 __real__ result, INVALID_EXCEPTION);
3413 check_isnan ("imag(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3414 __imag__ result);
3415 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, -10.0));
3416 check_isnan_maybe_exc ("real(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3417 __real__ result, INVALID_EXCEPTION);
3418 check_isnan ("imag(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3419 __imag__ result);
3421 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, plus_infty));
3422 check_isnan_maybe_exc ("real(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3423 __real__ result, INVALID_EXCEPTION);
3424 check_isnan ("imag(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3425 __imag__ result);
3426 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_infty));
3427 check_isnan_maybe_exc ("real(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3428 __real__ result, INVALID_EXCEPTION);
3429 check_isnan ("imag(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3430 __imag__ result);
3432 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, nan_value));
3433 check_isnan ("real(ccosh(NaN + i NaN)) = NaN", __real__ result);
3434 check_isnan ("imag(ccosh(NaN + i NaN)) = NaN", __imag__ result);
3436 result = FUNC(ccosh) (BUILD_COMPLEX (0.7, 1.2));
3437 check_eps ("real(ccosh(0.7 + i 1.2)) == 0.45482...", __real__ result,
3438 0.4548202223691477654L, CHOOSE(5e-17L, 6e-17, 9e-8));
3439 check_eps ("imag(ccosh(0.7 + i 1.2)) == 0.70702...", __imag__ result,
3440 0.7070296600921537682L, CHOOSE(7e-17L, 2e-16, 0));
3442 result = FUNC(ccosh) (BUILD_COMPLEX (-2, -3));
3443 check_eps ("real(ccosh(-2 - i 3)) == -3.72454...", __real__ result,
3444 -3.7245455049153225654L, CHOOSE(7e-19L, 0, 3e-7));
3445 check_eps ("imag(ccosh(-2 - i 3)) == -0.51182...", __imag__ result,
3446 0.5118225699873846088L, CHOOSE(3e-19L, 2e-16, 6e-8));
3450 static void
3451 cacos_test (void)
3453 __complex__ MATHTYPE result;
3455 result = FUNC(cacos) (BUILD_COMPLEX (0, 0));
3456 check ("real(cacos(0 + i0)) = pi/2", __real__ result, M_PI_2l);
3457 check ("imag(cacos(0 + i0)) = -0", __imag__ result, minus_zero);
3458 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, 0));
3459 check ("real(cacos(-0 + i0)) = pi/2", __real__ result, M_PI_2l);
3460 check ("imag(cacos(-0 + i0)) = -0", __imag__ result, minus_zero);
3461 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_zero));
3462 check ("real(cacos(0 - i0)) = pi/2", __real__ result, M_PI_2l);
3463 check ("imag(cacos(0 - i0)) = 0", __imag__ result, 0);
3464 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, minus_zero));
3465 check ("real(cacos(-0 - i0)) = pi/2", __real__ result, M_PI_2l);
3466 check ("imag(cacos(-0 - i0)) = 0", __imag__ result, 0);
3468 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, plus_infty));
3469 check ("real(cacos(-Inf + i Inf)) = 3*pi/4", __real__ result,
3470 M_PIl - M_PI_4l);
3471 check_isinfn ("imag(cacos(-Inf + i Inf)) = -Inf", __imag__ result);
3472 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_infty));
3473 check ("real(cacos(-Inf - i Inf)) = 3*pi/4", __real__ result,
3474 M_PIl - M_PI_4l);
3475 check_isinfp ("imag(cacos(-Inf - i Inf)) = +Inf", __imag__ result);
3477 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, plus_infty));
3478 check ("real(cacos(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4l);
3479 check_isinfn ("imag(cacos(+Inf + i Inf)) = -Inf", __imag__ result);
3480 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_infty));
3481 check ("real(cacos(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4l);
3482 check_isinfp ("imag(cacos(+Inf - i Inf)) = +Inf", __imag__ result);
3484 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, plus_infty));
3485 check ("real(cacos(-10.0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3486 check_isinfn ("imag(cacos(-10.0 + i Inf)) = -Inf", __imag__ result);
3487 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, minus_infty));
3488 check ("real(cacos(-10.0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3489 check_isinfp ("imag(cacos(-10.0 - i Inf)) = +Inf", __imag__ result);
3490 result = FUNC(cacos) (BUILD_COMPLEX (0, plus_infty));
3491 check ("real(cacos(0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3492 check_isinfn ("imag(cacos(0 + i Inf)) = -Inf", __imag__ result);
3493 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_infty));
3494 check ("real(cacos(0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3495 check_isinfp ("imag(cacos(0 - i Inf)) = +Inf", __imag__ result);
3496 result = FUNC(cacos) (BUILD_COMPLEX (0.1, plus_infty));
3497 check ("real(cacos(0.1 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3498 check_isinfn ("imag(cacos(0.1 + i Inf)) = -Inf", __imag__ result);
3499 result = FUNC(cacos) (BUILD_COMPLEX (0.1, minus_infty));
3500 check ("real(cacos(0.1 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3501 check_isinfp ("imag(cacos(0.1 - i Inf)) = +Inf", __imag__ result);
3503 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 0));
3504 check ("real(cacos(-Inf + i0)) = pi", __real__ result, M_PIl);
3505 check_isinfn ("imag(cacos(-Inf + i0)) = -Inf", __imag__ result);
3506 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_zero));
3507 check ("real(cacos(-Inf - i0)) = pi", __real__ result, M_PIl);
3508 check_isinfp ("imag(cacos(-Inf - i0)) = +Inf", __imag__ result);
3509 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 100));
3510 check ("real(cacos(-Inf + i100)) = pi", __real__ result, M_PIl);
3511 check_isinfn ("imag(cacos(-Inf + i100)) = -Inf", __imag__ result);
3512 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, -100));
3513 check ("real(cacos(-Inf - i100)) = pi", __real__ result, M_PIl);
3514 check_isinfp ("imag(cacos(-Inf - i100)) = +Inf", __imag__ result);
3516 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0));
3517 check ("real(cacos(+Inf + i0)) = 0", __real__ result, 0);
3518 check_isinfn ("imag(cacos(+Inf + i0)) = -Inf", __imag__ result);
3519 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_zero));
3520 check ("real(cacos(+Inf - i0)) = 0", __real__ result, 0);
3521 check_isinfp ("imag(cacos(+Inf - i0)) = +Inf", __imag__ result);
3522 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0.5));
3523 check ("real(cacos(+Inf + i0.5)) = 0", __real__ result, 0);
3524 check_isinfn ("imag(cacos(+Inf + i0.5)) = -Inf", __imag__ result);
3525 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, -0.5));
3526 check ("real(cacos(+Inf - i0.5)) = 0", __real__ result, 0);
3527 check_isinfp ("imag(cacos(+Inf - i0.5)) = +Inf", __imag__ result);
3529 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, nan_value));
3530 check_isnan ("real(cacos(+Inf + i NaN)) = NaN", __real__ result);
3531 check_isinfp ("imag(cacos(+Inf + i NaN)) = +-Inf",
3532 FUNC(fabs) (__imag__ result));
3533 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, nan_value));
3534 check_isnan ("real(cacos(-Inf + i NaN)) = NaN", __real__ result);
3535 check_isinfp ("imag(cacos(-Inf + i NaN)) = +-Inf",
3536 FUNC(fabs) (__imag__ result));
3538 result = FUNC(cacos) (BUILD_COMPLEX (0, nan_value));
3539 check ("real(cacos(0 + i NaN)) = pi/2", __real__ result, M_PI_2l);
3540 check_isnan ("imag(cacos(0 + i NaN)) = NaN", __imag__ result);
3541 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, nan_value));
3542 check ("real(cacos(-0 + i NaN)) = pi/2", __real__ result, M_PI_2l);
3543 check_isnan ("imag(cacos(-0 + i NaN)) = NaN", __imag__ result);
3545 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, plus_infty));
3546 check_isnan ("real(cacos(NaN + i Inf)) = NaN", __real__ result);
3547 check_isinfn ("imag(cacos(NaN + i Inf)) = -Inf", __imag__ result);
3548 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, minus_infty));
3549 check_isnan ("real(cacos(NaN - i Inf)) = NaN", __real__ result);
3550 check_isinfp ("imag(cacos(NaN - i Inf)) = +Inf", __imag__ result);
3552 result = FUNC(cacos) (BUILD_COMPLEX (10.5, nan_value));
3553 check_isnan_maybe_exc ("real(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3554 __real__ result, INVALID_EXCEPTION);
3555 check_isnan ("imag(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3556 __imag__ result);
3557 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3558 check_isnan_maybe_exc ("real(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3559 __real__ result, INVALID_EXCEPTION);
3560 check_isnan ("imag(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3561 __imag__ result);
3563 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, 0.75));
3564 check_isnan_maybe_exc ("real(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3565 __real__ result, INVALID_EXCEPTION);
3566 check_isnan ("imag(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3567 __imag__ result);
3568 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3569 check_isnan_maybe_exc ("real(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3570 __real__ result, INVALID_EXCEPTION);
3571 check_isnan ("imag(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3572 __imag__ result);
3574 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, nan_value));
3575 check_isnan ("real(cacos(NaN + i NaN)) = NaN", __real__ result);
3576 check_isnan ("imag(cacos(NaN + i NaN)) = NaN", __imag__ result);
3578 result = FUNC(cacos) (BUILD_COMPLEX (0.7, 1.2));
3579 check_eps ("real(cacos(0.7 + i 1.2)) == 1.13518...", __real__ result,
3580 1.1351827477151551089L, CHOOSE(2e-17L, 3e-16, 2e-7));
3581 check_eps ("imag(cacos(0.7 + i 1.2)) == -1.09276...", __imag__ result,
3582 -1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 3e-7));
3584 result = FUNC(cacos) (BUILD_COMPLEX (-2, -3));
3585 check_eps ("real(cacos(-2 - i 3)) == 2.14144...", __real__ result,
3586 2.1414491111159960199L, CHOOSE(3e-19L, 0, 0));
3587 check_eps ("imag(cacos(-2 - i 3)) == -1.98338...", __imag__ result,
3588 1.9833870299165354323L, CHOOSE(3e-19L, 0, 0));
3592 static void
3593 cacosh_test (void)
3595 __complex__ MATHTYPE result;
3597 result = FUNC(cacosh) (BUILD_COMPLEX (0, 0));
3598 check ("real(cacosh(0 + i0)) = 0", __real__ result, 0);
3599 check ("imag(cacosh(0 + i0)) = pi/2", __imag__ result, M_PI_2l);
3600 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, 0));
3601 check ("real(cacosh(-0 + i0)) = 0", __real__ result, 0);
3602 check ("imag(cacosh(-0 + i0)) = pi/2", __imag__ result, M_PI_2l);
3603 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_zero));
3604 check ("real(cacosh(0 - i0)) = 0", __real__ result, 0);
3605 check ("imag(cacosh(0 - i0)) = -pi/2", __imag__ result, -M_PI_2l);
3606 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3607 check ("real(cacosh(-0 - i0)) = 0", __real__ result, 0);
3608 check ("imag(cacosh(-0 - i0)) = -pi/2", __imag__ result, -M_PI_2l);
3610 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3611 check_isinfp ("real(cacosh(-Inf + i Inf)) = +Inf", __real__ result);
3612 check ("imag(cacosh(-Inf + i Inf)) = 3*pi/4", __imag__ result,
3613 M_PIl - M_PI_4l);
3614 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3615 check_isinfp ("real(cacosh(-Inf - i Inf)) = +Inf", __real__ result);
3616 check ("imag(cacosh(-Inf - i Inf)) = -3*pi/4", __imag__ result,
3617 M_PI_4l - M_PIl);
3619 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3620 check_isinfp ("real(cacosh(+Inf + i Inf)) = +Inf", __real__ result);
3621 check ("imag(cacosh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3622 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3623 check_isinfp ("real(cacosh(+Inf - i Inf)) = +Inf", __real__ result);
3624 check ("imag(cacosh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3626 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, plus_infty));
3627 check_isinfp ("real(cacosh(-10.0 + i Inf)) = +Inf", __real__ result);
3628 check ("imag(cacosh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3629 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, minus_infty));
3630 check_isinfp ("real(cacosh(-10.0 - i Inf)) = +Inf", __real__ result);
3631 check ("imag(cacosh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3632 result = FUNC(cacosh) (BUILD_COMPLEX (0, plus_infty));
3633 check_isinfp ("real(cacosh(0 + i Inf)) = +Inf", __real__ result);
3634 check ("imag(cacosh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3635 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_infty));
3636 check_isinfp ("real(cacosh(0 - i Inf)) = +Inf", __real__ result);
3637 check ("imag(cacosh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3638 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, plus_infty));
3639 check_isinfp ("real(cacosh(0.1 + i Inf)) = +Inf", __real__ result);
3640 check ("imag(cacosh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3641 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, minus_infty));
3642 check_isinfp ("real(cacosh(0.1 - i Inf)) = +Inf", __real__ result);
3643 check ("imag(cacosh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3645 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 0));
3646 check_isinfp ("real(cacosh(-Inf + i0)) = +Inf", __real__ result);
3647 check ("imag(cacosh(-Inf + i0)) = pi", __imag__ result, M_PIl);
3648 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3649 check_isinfp ("real(cacosh(-Inf - i0)) = +Inf", __real__ result);
3650 check ("imag(cacosh(-Inf - i0)) = -pi", __imag__ result, -M_PIl);
3651 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 100));
3652 check_isinfp ("real(cacosh(-Inf + i100)) = +Inf", __real__ result);
3653 check ("imag(cacosh(-Inf + i100)) = pi", __imag__ result, M_PIl);
3654 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, -100));
3655 check_isinfp ("real(cacosh(-Inf - i100)) = +Inf", __real__ result);
3656 check ("imag(cacosh(-Inf - i100)) = -pi", __imag__ result, -M_PIl);
3658 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0));
3659 check_isinfp ("real(cacosh(+Inf + i0)) = +Inf", __real__ result);
3660 check ("imag(cacosh(+Inf + i0)) = 0", __imag__ result, 0);
3661 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3662 check_isinfp ("real(cacosh(+Inf - i0)) = +Inf", __real__ result);
3663 check ("imag(cacosh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3664 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0.5));
3665 check_isinfp ("real(cacosh(+Inf + i0.5)) = +Inf", __real__ result);
3666 check ("imag(cacosh(+Inf + i0.5)) = 0", __imag__ result, 0);
3667 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, -0.5));
3668 check_isinfp ("real(cacosh(+Inf - i0.5)) = +Inf", __real__ result);
3669 check ("imag(cacosh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3671 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, nan_value));
3672 check_isinfp ("real(cacosh(+Inf + i NaN)) = +Inf", __real__ result);
3673 check_isnan ("imag(cacosh(+Inf + i NaN)) = NaN", __imag__ result);
3674 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, nan_value));
3675 check_isinfp ("real(cacosh(-Inf + i NaN)) = +Inf", __real__ result);
3676 check_isnan ("imag(cacosh(-Inf + i NaN)) = NaN", __imag__ result);
3678 result = FUNC(cacosh) (BUILD_COMPLEX (0, nan_value));
3679 check_isnan ("real(cacosh(0 + i NaN)) = NaN", __real__ result);
3680 check_isnan ("imag(cacosh(0 + i NaN)) = NaN", __imag__ result);
3681 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, nan_value));
3682 check_isnan ("real(cacosh(-0 + i NaN)) = NaN", __real__ result);
3683 check_isnan ("imag(cacosh(-0 + i NaN)) = NaN", __imag__ result);
3685 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, plus_infty));
3686 check_isinfp ("real(cacosh(NaN + i Inf)) = +Inf", __real__ result);
3687 check_isnan ("imag(cacosh(NaN + i Inf)) = NaN", __imag__ result);
3688 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, minus_infty));
3689 check_isinfp ("real(cacosh(NaN - i Inf)) = +Inf", __real__ result);
3690 check_isnan ("imag(cacosh(NaN - i Inf)) = NaN", __imag__ result);
3692 result = FUNC(cacosh) (BUILD_COMPLEX (10.5, nan_value));
3693 check_isnan_maybe_exc ("real(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3694 __real__ result, INVALID_EXCEPTION);
3695 check_isnan ("imag(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3696 __imag__ result);
3697 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3698 check_isnan_maybe_exc ("real(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3699 __real__ result, INVALID_EXCEPTION);
3700 check_isnan ("imag(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3701 __imag__ result);
3703 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, 0.75));
3704 check_isnan_maybe_exc ("real(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3705 __real__ result, INVALID_EXCEPTION);
3706 check_isnan ("imag(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3707 __imag__ result);
3708 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3709 check_isnan_maybe_exc ("real(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3710 __real__ result, INVALID_EXCEPTION);
3711 check_isnan ("imag(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3712 __imag__ result);
3714 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, nan_value));
3715 check_isnan ("real(cacosh(NaN + i NaN)) = NaN", __real__ result);
3716 check_isnan ("imag(cacosh(NaN + i NaN)) = NaN", __imag__ result);
3718 result = FUNC(cacosh) (BUILD_COMPLEX (0.7, 1.2));
3719 check_eps ("real(cacosh(0.7 + i 1.2)) == 1.09276...", __real__ result,
3720 1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 2e-7));
3721 check_eps ("imag(cacosh(0.7 + i 1.2)) == 1.13518...", __imag__ result,
3722 1.1351827477151551089L, CHOOSE(2e-17L, 0, 0));
3724 result = FUNC(cacosh) (BUILD_COMPLEX (-2, -3));
3725 check_eps ("real(cacosh(-2 - i 3)) == -1.98338...", __real__ result,
3726 -1.9833870299165354323L, CHOOSE (2e-18L, 3e-16, 9e-7));
3727 check_eps ("imag(cacosh(-2 - i 3)) == 2.14144...", __imag__ result,
3728 2.1414491111159960199L, CHOOSE (3e-19, 5e-16, 1e-6));
3732 static void
3733 casin_test (void)
3735 __complex__ MATHTYPE result;
3737 result = FUNC(casin) (BUILD_COMPLEX (0, 0));
3738 check ("real(casin(0 + i0)) = 0", __real__ result, 0);
3739 check ("imag(casin(0 + i0)) = 0", __imag__ result, 0);
3740 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, 0));
3741 check ("real(casin(-0 + i0)) = -0", __real__ result, minus_zero);
3742 check ("imag(casin(-0 + i0)) = 0", __imag__ result, 0);
3743 result = FUNC(casin) (BUILD_COMPLEX (0, minus_zero));
3744 check ("real(casin(0 - i0)) = 0", __real__ result, 0);
3745 check ("imag(casin(0 - i0)) = -0", __imag__ result, minus_zero);
3746 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_zero));
3747 check ("real(casin(-0 - i0)) = -0", __real__ result, minus_zero);
3748 check ("imag(casin(-0 - i0)) = -0", __imag__ result, minus_zero);
3750 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, plus_infty));
3751 check ("real(casin(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4l);
3752 check_isinfp ("imag(casin(+Inf + i Inf)) = +Inf", __imag__ result);
3753 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_infty));
3754 check ("real(casin(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4l);
3755 check_isinfn ("imag(casin(+Inf - i Inf)) = -Inf", __imag__ result);
3756 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, plus_infty));
3757 check ("real(casin(-Inf + i Inf)) = -pi/4", __real__ result, -M_PI_4l);
3758 check_isinfp ("imag(casin(-Inf + i Inf)) = +Inf", __imag__ result);
3759 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_infty));
3760 check ("real(casin(-Inf - i Inf)) = -pi/4", __real__ result, -M_PI_4l);
3761 check_isinfn ("imag(casin(-Inf - i Inf)) = -Inf", __imag__ result);
3763 result = FUNC(casin) (BUILD_COMPLEX (-10.0, plus_infty));
3764 check ("real(casin(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
3765 check_isinfp ("imag(casin(-10.0 + i Inf)) = +Inf", __imag__ result);
3766 result = FUNC(casin) (BUILD_COMPLEX (-10.0, minus_infty));
3767 check ("real(casin(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
3768 check_isinfn ("imag(casin(-10.0 - i Inf)) = -Inf", __imag__ result);
3769 result = FUNC(casin) (BUILD_COMPLEX (0, plus_infty));
3770 check ("real(casin(0 + i Inf)) = 0", __real__ result, 0.0);
3771 check_isinfp ("imag(casin(0 + i Inf)) = +Inf", __imag__ result);
3772 result = FUNC(casin) (BUILD_COMPLEX (0, minus_infty));
3773 check ("real(casin(0 - i Inf)) = 0", __real__ result, 0.0);
3774 check_isinfn ("imag(casin(0 - i Inf)) = -Inf", __imag__ result);
3775 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, plus_infty));
3776 check ("real(casin(-0 + i Inf)) = -0", __real__ result, minus_zero);
3777 check_isinfp ("imag(casin(-0 + i Inf)) = +Inf", __imag__ result);
3778 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_infty));
3779 check ("real(casin(-0 - i Inf)) = -0", __real__ result, minus_zero);
3780 check_isinfn ("imag(casin(-0 - i Inf)) = -Inf", __imag__ result);
3781 result = FUNC(casin) (BUILD_COMPLEX (0.1, plus_infty));
3782 check ("real(casin(0.1 + i Inf)) = 0", __real__ result, 0);
3783 check_isinfp ("imag(casin(0.1 + i Inf)) = +Inf", __imag__ result);
3784 result = FUNC(casin) (BUILD_COMPLEX (0.1, minus_infty));
3785 check ("real(casin(0.1 - i Inf)) = 0", __real__ result, 0);
3786 check_isinfn ("imag(casin(0.1 - i Inf)) = -Inf", __imag__ result);
3788 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 0));
3789 check ("real(casin(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2l);
3790 check_isinfp ("imag(casin(-Inf + i0)) = +Inf", __imag__ result);
3791 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_zero));
3792 check ("real(casin(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2l);
3793 check_isinfn ("imag(casin(-Inf - i0)) = -Inf", __imag__ result);
3794 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 100));
3795 check ("real(casin(-Inf + i100)) = -pi/2", __real__ result, -M_PI_2l);
3796 check_isinfp ("imag(casin(-Inf + i100)) = +Inf", __imag__ result);
3797 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, -100));
3798 check ("real(casin(-Inf - i100)) = -pi/2", __real__ result, -M_PI_2l);
3799 check_isinfn ("imag(casin(-Inf - i100)) = -Inf", __imag__ result);
3801 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0));
3802 check ("real(casin(+Inf + i0)) = pi/2", __real__ result, M_PI_2l);
3803 check_isinfp ("imag(casin(+Inf + i0)) = +Inf", __imag__ result);
3804 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_zero));
3805 check ("real(casin(+Inf - i0)) = pi/2", __real__ result, M_PI_2l);
3806 check_isinfn ("imag(casin(+Inf - i0)) = -Inf", __imag__ result);
3807 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0.5));
3808 check ("real(casin(+Inf + i0.5)) = pi/2", __real__ result, M_PI_2l);
3809 check_isinfp ("imag(casin(+Inf + i0.5)) = +Inf", __imag__ result);
3810 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, -0.5));
3811 check ("real(casin(+Inf - i0.5)) = pi/2", __real__ result, M_PI_2l);
3812 check_isinfn ("imag(casin(+Inf - i0.5)) = -Inf", __imag__ result);
3814 result = FUNC(casin) (BUILD_COMPLEX (nan_value, plus_infty));
3815 check_isnan ("real(casin(NaN + i Inf)) = NaN", __real__ result);
3816 check_isinfp ("imag(casin(NaN + i Inf)) = +Inf", __imag__ result);
3817 result = FUNC(casin) (BUILD_COMPLEX (nan_value, minus_infty));
3818 check_isnan ("real(casin(NaN - i Inf)) = NaN", __real__ result);
3819 check_isinfn ("imag(casin(NaN - i Inf)) = -Inf", __imag__ result);
3821 result = FUNC(casin) (BUILD_COMPLEX (0.0, nan_value));
3822 check ("real(casin(0 + i NaN)) = 0", __real__ result, 0.0);
3823 check_isnan ("imag(casin(0 + i NaN)) = NaN", __imag__ result);
3824 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, nan_value));
3825 check ("real(casin(-0 + i NaN)) = -0", __real__ result, minus_zero);
3826 check_isnan ("imag(casin(-0 + i NaN)) = NaN", __imag__ result);
3828 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, nan_value));
3829 check_isnan ("real(casin(+Inf + i NaN)) = NaN", __real__ result);
3830 check_isinfp ("imag(casin(+Inf + i NaN)) = +-Inf",
3831 FUNC(fabs) (__imag__ result));
3832 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, nan_value));
3833 check_isnan ("real(casin(-Inf + i NaN)) = NaN", __real__ result);
3834 check_isinfp ("imag(casin(-Inf + NaN)) = +-Inf",
3835 FUNC(fabs) (__imag__ result));
3837 result = FUNC(casin) (BUILD_COMPLEX (nan_value, 10.5));
3838 check_isnan_maybe_exc ("real(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3839 __real__ result, INVALID_EXCEPTION);
3840 check_isnan ("imag(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3841 __imag__ result);
3842 result = FUNC(casin) (BUILD_COMPLEX (nan_value, -10.5));
3843 check_isnan_maybe_exc ("real(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3844 __real__ result, INVALID_EXCEPTION);
3845 check_isnan ("imag(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3846 __imag__ result);
3848 result = FUNC(casin) (BUILD_COMPLEX (0.75, nan_value));
3849 check_isnan_maybe_exc ("real(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3850 __real__ result, INVALID_EXCEPTION);
3851 check_isnan ("imag(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3852 __imag__ result);
3853 result = FUNC(casin) (BUILD_COMPLEX (-0.75, nan_value));
3854 check_isnan_maybe_exc ("real(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3855 __real__ result, INVALID_EXCEPTION);
3856 check_isnan ("imag(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3857 __imag__ result);
3859 result = FUNC(casin) (BUILD_COMPLEX (nan_value, nan_value));
3860 check_isnan ("real(casin(NaN + i NaN)) = NaN", __real__ result);
3861 check_isnan ("imag(casin(NaN + i NaN)) = NaN", __imag__ result);
3863 result = FUNC(casin) (BUILD_COMPLEX (0.7, 1.2));
3864 check_eps ("real(casin(0.7 + i 1.2)) == 0.43561...", __real__ result,
3865 0.4356135790797415103L, CHOOSE(2e-17L, 2e-16, 2e-7));
3866 check_eps ("imag(casin(0.7 + i 1.2)) == 1.09276...", __imag__ result,
3867 1.0927647857577371459L, CHOOSE(4e-17L, 3e-16, 3e-7));
3869 result = FUNC(casin) (BUILD_COMPLEX (-2, -3));
3870 check_eps ("real(casin(-2 - i 3)) == -0.57065...", __real__ result,
3871 -0.5706527843210994007L, CHOOSE(4e-19L, 0, 0));
3872 check_eps ("imag(casin(-2 - i 3)) == -1.98338...", __imag__ result,
3873 -1.9833870299165354323L, CHOOSE(3e-19L, 0, 0));
3877 static void
3878 casinh_test (void)
3880 __complex__ MATHTYPE result;
3882 result = FUNC(casinh) (BUILD_COMPLEX (0, 0));
3883 check ("real(casinh(0 + i0)) = 0", __real__ result, 0);
3884 check ("imag(casinh(0 + i0)) = 0", __imag__ result, 0);
3885 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, 0));
3886 check ("real(casinh(-0 + i0)) = -0", __real__ result, minus_zero);
3887 check ("imag(casinh(-0 + i0)) = 0", __imag__ result, 0);
3888 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_zero));
3889 check ("real(casinh(0 - i0)) = 0", __real__ result, 0);
3890 check ("imag(casinh(0 - i0)) = -0", __imag__ result, minus_zero);
3891 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_zero));
3892 check ("real(casinh(-0 - i0)) = -0", __real__ result, minus_zero);
3893 check ("imag(casinh(-0 - i0)) = -0", __imag__ result, minus_zero);
3895 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, plus_infty));
3896 check_isinfp ("real(casinh(+Inf + i Inf)) = +Inf", __real__ result);
3897 check ("imag(casinh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3898 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_infty));
3899 check_isinfp ("real(casinh(+Inf - i Inf)) = +Inf", __real__ result);
3900 check ("imag(casinh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3901 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, plus_infty));
3902 check_isinfn ("real(casinh(-Inf + i Inf)) = -Inf", __real__ result);
3903 check ("imag(casinh(-Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3904 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_infty));
3905 check_isinfn ("real(casinh(-Inf - i Inf)) = -Inf", __real__ result);
3906 check ("imag(casinh(-Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3908 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, plus_infty));
3909 check_isinfn ("real(casinh(-10.0 + i Inf)) = -Inf", __real__ result);
3910 check ("imag(casinh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3911 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, minus_infty));
3912 check_isinfn ("real(casinh(-10.0 - i Inf)) = -Inf", __real__ result);
3913 check ("imag(casinh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3914 result = FUNC(casinh) (BUILD_COMPLEX (0, plus_infty));
3915 check_isinfp ("real(casinh(0 + i Inf)) = +Inf", __real__ result);
3916 check ("imag(casinh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3917 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_infty));
3918 check_isinfp ("real(casinh(0 - i Inf)) = +Inf", __real__ result);
3919 check ("imag(casinh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3920 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, plus_infty));
3921 check_isinfn ("real(casinh(-0 + i Inf)) = -Inf", __real__ result);
3922 check ("imag(casinh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3923 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_infty));
3924 check_isinfn ("real(casinh(-0 - i Inf)) = -Inf", __real__ result);
3925 check ("imag(casinh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3926 result = FUNC(casinh) (BUILD_COMPLEX (0.1, plus_infty));
3927 check_isinfp ("real(casinh(0.1 + i Inf)) = +Inf", __real__ result);
3928 check ("imag(casinh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3929 result = FUNC(casinh) (BUILD_COMPLEX (0.1, minus_infty));
3930 check_isinfp ("real(casinh(0.1 - i Inf)) = +Inf", __real__ result);
3931 check ("imag(casinh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3933 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 0));
3934 check_isinfn ("real(casinh(-Inf + i0)) = -Inf", __real__ result);
3935 check ("imag(casinh(-Inf + i0)) = 0", __imag__ result, 0);
3936 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_zero));
3937 check_isinfn ("real(casinh(-Inf - i0)) = -Inf", __real__ result);
3938 check ("imag(casinh(-Inf - i0)) = -0", __imag__ result, minus_zero);
3939 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 100));
3940 check_isinfn ("real(casinh(-Inf + i100)) = -Inf", __real__ result);
3941 check ("imag(casinh(-Inf + i100)) = 0", __imag__ result, 0);
3942 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, -100));
3943 check_isinfn ("real(casinh(-Inf - i100)) = -Inf", __real__ result);
3944 check ("imag(casinh(-Inf - i100)) = -0", __imag__ result, minus_zero);
3946 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0));
3947 check_isinfp ("real(casinh(+Inf + i0)) = +Inf", __real__ result);
3948 check ("imag(casinh(+Inf + i0)) = 0", __imag__ result, 0);
3949 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_zero));
3950 check_isinfp ("real(casinh(+Inf - i0)) = +Inf", __real__ result);
3951 check ("imag(casinh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3952 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0.5));
3953 check_isinfp ("real(casinh(+Inf + i0.5)) = +Inf", __real__ result);
3954 check ("imag(casinh(+Inf + i0.5)) = 0", __imag__ result, 0);
3955 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, -0.5));
3956 check_isinfp ("real(casinh(+Inf - i0.5)) = +Inf", __real__ result);
3957 check ("imag(casinh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3959 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, nan_value));
3960 check_isinfp ("real(casinh(+Inf + i NaN)) = +Inf", __real__ result);
3961 check_isnan ("imag(casinh(+Inf + i NaN)) = NaN", __imag__ result);
3962 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, nan_value));
3963 check_isinfn ("real(casinh(-Inf + i NaN)) = -Inf", __real__ result);
3964 check_isnan ("imag(casinh(-Inf + i NaN)) = NaN", __imag__ result);
3966 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0));
3967 check_isnan ("real(casinh(NaN + i0)) = NaN", __real__ result);
3968 check ("imag(casinh(NaN + i0)) = 0", __imag__ result, 0);
3969 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_zero));
3970 check_isnan ("real(casinh(NaN - i0)) = NaN", __real__ result);
3971 check ("imag(casinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3973 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, plus_infty));
3974 check_isinfp ("real(casinh(NaN + i Inf)) = +-Inf",
3975 FUNC(fabs) (__real__ result));
3976 check_isnan ("imag(casinh(NaN + i Inf)) = NaN", __imag__ result);
3977 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_infty));
3978 check_isinfp ("real(casinh(NaN - i Inf)) = +-Inf",
3979 FUNC(fabs) (__real__ result));
3980 check_isnan ("imag(casinh(NaN - i Inf)) = NaN", __imag__ result);
3982 result = FUNC(casinh) (BUILD_COMPLEX (10.5, nan_value));
3983 check_isnan_maybe_exc ("real(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3984 __real__ result, INVALID_EXCEPTION);
3985 check_isnan ("imag(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3986 __imag__ result);
3987 result = FUNC(casinh) (BUILD_COMPLEX (-10.5, nan_value));
3988 check_isnan_maybe_exc ("real(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3989 __real__ result, INVALID_EXCEPTION);
3990 check_isnan ("imag(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3991 __imag__ result);
3993 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0.75));
3994 check_isnan_maybe_exc ("real(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
3995 __real__ result, INVALID_EXCEPTION);
3996 check_isnan ("imag(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
3997 __imag__ result);
3998 result = FUNC(casinh) (BUILD_COMPLEX (-0.75, nan_value));
3999 check_isnan_maybe_exc ("real(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
4000 __real__ result, INVALID_EXCEPTION);
4001 check_isnan ("imag(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
4002 __imag__ result);
4004 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, nan_value));
4005 check_isnan ("real(casinh(NaN + i NaN)) = NaN", __real__ result);
4006 check_isnan ("imag(casinh(NaN + i NaN)) = NaN", __imag__ result);
4008 result = FUNC(casinh) (BUILD_COMPLEX (0.7, 1.2));
4009 check_eps ("real(casinh(0.7 + i 1.2)) == 0.97865...", __real__ result,
4010 0.9786545955936738768L, CHOOSE(5e-17L, 2e-16, 0));
4011 check_eps ("imag(casinh(0.7 + i 1.2)) == 0.91135...", __imag__ result,
4012 0.9113541895315601156L, CHOOSE(7e-19L, 2e-16, 6e-8));
4014 result = FUNC(casinh) (BUILD_COMPLEX (-2, -3));
4015 check_eps ("real(casinh(-2 - i 3)) == -1.96863...", __real__ result,
4016 -1.9686379257930962917L, CHOOSE(7e-19L, 2e-15, 2e-7));
4017 check_eps ("imag(casinh(-2 - i 3)) == -0.96465...", __imag__ result,
4018 -0.9646585044076027920L, CHOOSE(4e-19L, 2e-15, 4e-7));
4022 static void
4023 catan_test (void)
4025 __complex__ MATHTYPE result;
4027 result = FUNC(catan) (BUILD_COMPLEX (0, 0));
4028 check ("real(catan(0 + i0)) = 0", __real__ result, 0);
4029 check ("imag(catan(0 + i0)) = 0", __imag__ result, 0);
4030 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, 0));
4031 check ("real(catan(-0 + i0)) = -0", __real__ result, minus_zero);
4032 check ("imag(catan(-0 + i0)) = 0", __imag__ result, 0);
4033 result = FUNC(catan) (BUILD_COMPLEX (0, minus_zero));
4034 check ("real(catan(0 - i0)) = 0", __real__ result, 0);
4035 check ("imag(catan(0 - i0)) = -0", __imag__ result, minus_zero);
4036 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_zero));
4037 check ("real(catan(-0 - i0)) = -0", __real__ result, minus_zero);
4038 check ("imag(catan(-0 - i0)) = -0", __imag__ result, minus_zero);
4040 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, plus_infty));
4041 check ("real(catan(+Inf + i Inf)) = pi/2", __real__ result, M_PI_2l);
4042 check ("imag(catan(+Inf + i Inf)) = 0", __imag__ result, 0);
4043 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_infty));
4044 check ("real(catan(+Inf - i Inf)) = pi/2", __real__ result, M_PI_2l);
4045 check ("imag(catan(+Inf - i Inf)) = -0", __imag__ result, minus_zero);
4046 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, plus_infty));
4047 check ("real(catan(-Inf + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4048 check ("imag(catan(-Inf + i Inf)) = 0", __imag__ result, 0.0);
4049 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_infty));
4050 check ("real(catan(-Inf - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4051 check ("imag(catan(-Inf - i Inf)) = -0", __imag__ result, minus_zero);
4053 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, -10.0));
4054 check ("real(catan(+Inf - i10.0)) = pi/2", __real__ result, M_PI_2l);
4055 check ("imag(catan(+Inf - i10.0)) = -0", __imag__ result, minus_zero);
4056 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, -10.0));
4057 check ("real(catan(-Inf - i10.0)) = -pi/2", __real__ result, -M_PI_2l);
4058 check ("imag(catan(-Inf - i10.0)) = -0", __imag__ result, minus_zero);
4059 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_zero));
4060 check ("real(catan(Inf - i0)) = pi/2", __real__ result, M_PI_2l);
4061 check ("imag(catan(Inf - i0)) = -0", __imag__ result, minus_zero);
4062 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_zero));
4063 check ("real(catan(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2l);
4064 check ("imag(catan(-Inf - i0)) = -0", __imag__ result, minus_zero);
4065 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.0));
4066 check ("real(catan(Inf + i0)) = pi/2", __real__ result, M_PI_2l);
4067 check ("imag(catan(Inf + i0)) = 0", __imag__ result, 0.0);
4068 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.0));
4069 check ("real(catan(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2l);
4070 check ("imag(catan(-Inf + i0)) = 0", __imag__ result, 0.0);
4071 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.1));
4072 check ("real(catan(+Inf + i0.1)) = pi/2", __real__ result, M_PI_2l);
4073 check ("imag(catan(+Inf + i0.1)) = 0", __imag__ result, 0);
4074 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.1));
4075 check ("real(catan(-Inf + i0.1)) = -pi/2", __real__ result, -M_PI_2l);
4076 check ("imag(catan(-Inf + i0.1)) = 0", __imag__ result, 0);
4078 result = FUNC(catan) (BUILD_COMPLEX (0.0, minus_infty));
4079 check ("real(catan(0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
4080 check ("imag(catan(0 - i Inf)) = -0", __imag__ result, minus_zero);
4081 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_infty));
4082 check ("real(catan(-0 - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4083 check ("imag(catan(-0 - i Inf)) = -0", __imag__ result, minus_zero);
4084 result = FUNC(catan) (BUILD_COMPLEX (100.0, minus_infty));
4085 check ("real(catan(100 - i Inf)) = pi/2", __real__ result, M_PI_2l);
4086 check ("imag(catan(100 - i Inf)) = -0", __imag__ result, minus_zero);
4087 result = FUNC(catan) (BUILD_COMPLEX (-100.0, minus_infty));
4088 check ("real(catan(-100 - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4089 check ("imag(catan(-100 - i Inf)) = -0", __imag__ result, minus_zero);
4091 result = FUNC(catan) (BUILD_COMPLEX (0.0, plus_infty));
4092 check ("real(catan(0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
4093 check ("imag(catan(0 + i Inf)) = 0", __imag__ result, 0);
4094 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, plus_infty));
4095 check ("real(catan(-0 + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4096 check ("imag(catan(-0 + i Inf)) = 0", __imag__ result, 0);
4097 result = FUNC(catan) (BUILD_COMPLEX (0.5, plus_infty));
4098 check ("real(catan(0.5 + i Inf)) = pi/2", __real__ result, M_PI_2l);
4099 check ("imag(catan(0.5 + i Inf)) = 0", __imag__ result, 0);
4100 result = FUNC(catan) (BUILD_COMPLEX (-0.5, plus_infty));
4101 check ("real(catan(-0.5 + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4102 check ("imag(catan(-0.5 + i Inf)) = 0", __imag__ result, 0);
4104 result = FUNC(catan) (BUILD_COMPLEX (nan_value, 0.0));
4105 check_isnan ("real(catan(NaN + i0)) = NaN", __real__ result);
4106 check ("imag(catan(NaN + i0)) = 0", __imag__ result, 0.0);
4107 result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_zero));
4108 check_isnan ("real(catan(NaN - i0)) = NaN", __real__ result);
4109 check ("imag(catan(NaN - i0)) = -0", __imag__ result, minus_zero);
4111 result = FUNC(catan) (BUILD_COMPLEX (nan_value, plus_infty));
4112 check_isnan ("real(catan(NaN + i Inf)) = NaN", __real__ result);
4113 check ("imag(catan(NaN + i Inf)) = 0", __imag__ result, 0);
4114 result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_infty));
4115 check_isnan ("real(catan(NaN - i Inf)) = NaN", __real__ result);
4116 check ("imag(catan(NaN - i Inf)) = -0", __imag__ result, minus_zero);
4118 result = FUNC(catan) (BUILD_COMPLEX (0.0, nan_value));
4119 check_isnan ("real(catan(0 + i NaN)) = NaN", __real__ result);
4120 check_isnan ("imag(catan(0 + i NaN)) = NaN", __imag__ result);
4121 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, nan_value));
4122 check_isnan ("real(catan(-0 + i NaN)) = NaN", __real__ result);
4123 check_isnan ("imag(catan(-0 + i NaN)) = NaN", __imag__ result);
4125 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, nan_value));
4126 check ("real(catan(+Inf + i NaN)) = pi/2", __real__ result, M_PI_2l);
4127 check ("imag(catan(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4128 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, nan_value));
4129 check ("real(catan(-Inf + i NaN)) = -pi/2", __real__ result, -M_PI_2l);
4130 check ("imag(catan(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4132 result = FUNC(catan) (BUILD_COMPLEX (nan_value, 10.5));
4133 check_isnan_maybe_exc ("real(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
4134 __real__ result, INVALID_EXCEPTION);
4135 check_isnan ("imag(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
4136 __imag__ result);
4137 result = FUNC(catan) (BUILD_COMPLEX (nan_value, -10.5));
4138 check_isnan_maybe_exc ("real(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
4139 __real__ result, INVALID_EXCEPTION);
4140 check_isnan ("imag(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
4141 __imag__ result);
4143 result = FUNC(catan) (BUILD_COMPLEX (0.75, nan_value));
4144 check_isnan_maybe_exc ("real(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
4145 __real__ result, INVALID_EXCEPTION);
4146 check_isnan ("imag(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
4147 __imag__ result);
4148 result = FUNC(catan) (BUILD_COMPLEX (-0.75, nan_value));
4149 check_isnan_maybe_exc ("real(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
4150 __real__ result, INVALID_EXCEPTION);
4151 check_isnan ("imag(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
4152 __imag__ result);
4154 result = FUNC(catan) (BUILD_COMPLEX (nan_value, nan_value));
4155 check_isnan ("real(catan(NaN + i NaN)) = NaN", __real__ result);
4156 check_isnan ("imag(catan(NaN + i NaN)) = NaN", __imag__ result);
4158 result = FUNC(catan) (BUILD_COMPLEX (0.7, 1.2));
4159 check_eps ("real(catan(0.7 + i 1.2)) == 1.07857...", __real__ result,
4160 1.0785743834118921877L, CHOOSE (3e-17, 0, 5e-7));
4161 check_eps ("imag(catan(0.7 + i 1.2)) == 0.57705...", __imag__ result,
4162 0.5770573776534306764L, CHOOSE(3e-17L, 2e-16, 6e-8));
4164 result = FUNC(catan) (BUILD_COMPLEX (-2, -3));
4165 check_eps ("real(catan(-2 - i 3)) == -1.40992...", __real__ result,
4166 -1.4099210495965755225L, CHOOSE(0, 0, 4e-7));
4167 check_eps ("imag(catan(-2 - i 3)) == -0.22907...", __imag__ result,
4168 -0.2290726829685387662L, CHOOSE(1.1e-19L, 3e-17, 2e-8));
4172 static void
4173 catanh_test (void)
4175 __complex__ MATHTYPE result;
4177 result = FUNC(catanh) (BUILD_COMPLEX (0, 0));
4178 check ("real(catanh(0 + i0)) = 0", __real__ result, 0);
4179 check ("imag(catanh(0 + i0)) = 0", __imag__ result, 0);
4180 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, 0));
4181 check ("real(catanh(-0 + i0)) = -0", __real__ result, minus_zero);
4182 check ("imag(catanh(-0 + i0)) = 0", __imag__ result, 0);
4183 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_zero));
4184 check ("real(catanh(0 - i0)) = 0", __real__ result, 0);
4185 check ("imag(catanh(0 - i0)) = -0", __imag__ result, minus_zero);
4186 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4187 check ("real(catanh(-0 - i0)) = -0", __real__ result, minus_zero);
4188 check ("imag(catanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4190 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, plus_infty));
4191 check ("real(catanh(+Inf + i Inf)) = 0", __real__ result, 0);
4192 check ("imag(catanh(+Inf + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4193 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_infty));
4194 check ("real(catanh(+Inf - i Inf)) = 0", __real__ result, 0);
4195 check ("imag(catanh(+Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4196 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, plus_infty));
4197 check ("real(catanh(-Inf + i Inf)) = -0", __real__ result, minus_zero);
4198 check ("imag(catanh(-Inf + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4199 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_infty));
4200 check ("real(catanh(-Inf - i Inf)) = -0", __real__ result, minus_zero);
4201 check ("imag(catanh(-Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4203 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, plus_infty));
4204 check ("real(catanh(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
4205 check ("imag(catanh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4206 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, minus_infty));
4207 check ("real(catanh(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
4208 check ("imag(catanh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4209 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4210 check ("real(catanh(-0 + i Inf)) = -0", __real__ result, minus_zero);
4211 check ("imag(catanh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4212 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4213 check ("real(catanh(-0 - i Inf)) = -0", __real__ result, minus_zero);
4214 check ("imag(catanh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4215 result = FUNC(catanh) (BUILD_COMPLEX (0, plus_infty));
4216 check ("real(catanh(0 + i Inf)) = 0", __real__ result, 0);
4217 check ("imag(catanh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4218 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_infty));
4219 check ("real(catanh(0 - i Inf)) = 0", __real__ result, 0);
4220 check ("imag(catanh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4221 result = FUNC(catanh) (BUILD_COMPLEX (0.1, plus_infty));
4222 check ("real(catanh(0.1 + i Inf)) = 0", __real__ result, 0);
4223 check ("imag(catanh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4224 result = FUNC(catanh) (BUILD_COMPLEX (0.1, minus_infty));
4225 check ("real(catanh(0.1 - i Inf)) = 0", __real__ result, 0);
4226 check ("imag(catanh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4228 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 0));
4229 check ("real(catanh(-Inf + i0)) = -0", __real__ result, minus_zero);
4230 check ("imag(catanh(-Inf + i0)) = pi/2", __imag__ result, M_PI_2l);
4231 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4232 check ("real(catanh(-Inf - i0)) = -0", __real__ result, minus_zero);
4233 check ("imag(catanh(-Inf - i0)) = -pi/2", __imag__ result, -M_PI_2l);
4234 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 100));
4235 check ("real(catanh(-Inf + i100)) = -0", __real__ result, minus_zero);
4236 check ("imag(catanh(-Inf + i100)) = pi/2", __imag__ result, M_PI_2l);
4237 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, -100));
4238 check ("real(catanh(-Inf - i100)) = -0", __real__ result, minus_zero);
4239 check ("imag(catanh(-Inf - i100)) = -pi/2", __imag__ result, -M_PI_2l);
4241 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0));
4242 check ("real(catanh(+Inf + i0)) = 0", __real__ result, 0);
4243 check ("imag(catanh(+Inf + i0)) = pi/2", __imag__ result, M_PI_2l);
4244 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4245 check ("real(catanh(+Inf - i0)) = 0", __real__ result, 0);
4246 check ("imag(catanh(+Inf - i0)) = -pi/2", __imag__ result, -M_PI_2l);
4247 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0.5));
4248 check ("real(catanh(+Inf + i0.5)) = 0", __real__ result, 0);
4249 check ("imag(catanh(+Inf + i0.5)) = pi/2", __imag__ result, M_PI_2l);
4250 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, -0.5));
4251 check ("real(catanh(+Inf - i0.5)) = 0", __real__ result, 0);
4252 check ("imag(catanh(+Inf - i0.5)) = -pi/2", __imag__ result, -M_PI_2l);
4254 result = FUNC(catanh) (BUILD_COMPLEX (0, nan_value));
4255 check ("real(catanh(0 + i NaN)) = 0", __real__ result, 0);
4256 check_isnan ("imag(catanh(0 + i NaN)) = NaN", __imag__ result);
4257 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, nan_value));
4258 check ("real(catanh(-0 + i NaN)) = -0", __real__ result, minus_zero);
4259 check_isnan ("imag(catanh(-0 + i NaN)) = NaN", __imag__ result);
4261 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, nan_value));
4262 check ("real(catanh(+Inf + i NaN)) = 0", __real__ result, 0);
4263 check_isnan ("imag(catanh(+Inf + i NaN)) = NaN", __imag__ result);
4264 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, nan_value));
4265 check ("real(catanh(-Inf + i NaN)) = -0", __real__ result, minus_zero);
4266 check_isnan ("imag(catanh(-Inf + i NaN)) = NaN", __imag__ result);
4268 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0));
4269 check_isnan ("real(catanh(NaN + i0)) = NaN", __real__ result);
4270 check_isnan ("imag(catanh(NaN + i0)) = NaN", __imag__ result);
4271 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_zero));
4272 check_isnan ("real(catanh(NaN - i0)) = NaN", __real__ result);
4273 check_isnan ("imag(catanh(NaN - i0)) = NaN", __imag__ result);
4275 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, plus_infty));
4276 check ("real(catanh(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4277 check ("imag(catanh(NaN + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4278 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_infty));
4279 check ("real(catanh(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4280 check ("imag(catanh(NaN - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4282 result = FUNC(catanh) (BUILD_COMPLEX (10.5, nan_value));
4283 check_isnan_maybe_exc ("real(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4284 __real__ result, INVALID_EXCEPTION);
4285 check_isnan ("imag(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4286 __imag__ result);
4287 result = FUNC(catanh) (BUILD_COMPLEX (-10.5, nan_value));
4288 check_isnan_maybe_exc ("real(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4289 __real__ result, INVALID_EXCEPTION);
4290 check_isnan ("imag(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4291 __imag__ result);
4293 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0.75));
4294 check_isnan_maybe_exc ("real(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4295 __real__ result, INVALID_EXCEPTION);
4296 check_isnan ("imag(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4297 __imag__ result);
4298 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, -0.75));
4299 check_isnan_maybe_exc ("real(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4300 __real__ result, INVALID_EXCEPTION);
4301 check_isnan ("imag(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4302 __imag__ result);
4304 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, nan_value));
4305 check_isnan ("real(catanh(NaN + i NaN)) = NaN", __real__ result);
4306 check_isnan ("imag(catanh(NaN + i NaN)) = NaN", __imag__ result);
4308 result = FUNC(catanh) (BUILD_COMPLEX (0.7, 1.2));
4309 check_eps ("real(catanh(0.7 + i 1.2)) == 0.26007...", __real__ result,
4310 0.2600749516525135959L, CHOOSE (2e-18, 6e-17, 0));
4311 check_eps ("imag(catanh(0.7 + i 1.2)) == 0.97024...", __imag__ result,
4312 0.9702403077950989849L, CHOOSE (3e-17, 2e-16, 4e-7));
4314 result = FUNC(catanh) (BUILD_COMPLEX (-2, -3));
4315 check_eps ("real(catanh(-2 - i 3)) == -0.14694...", __real__ result,
4316 -0.1469466662255297520L, CHOOSE (9e-20L, 2e-16, 2e-8));
4317 check_eps ("imag(catanh(-2 - i 3)) == -1.33897...", __imag__ result,
4318 -1.3389725222944935611L, CHOOSE (7e-19L, 0, 5e-7));
4322 static void
4323 ctan_test (void)
4325 __complex__ MATHTYPE result;
4327 result = FUNC(ctan) (BUILD_COMPLEX (0, 0));
4328 check ("real(ctan(0 + i0)) = 0", __real__ result, 0);
4329 check ("imag(ctan(0 + i0)) = 0", __imag__ result, 0);
4330 result = FUNC(ctan) (BUILD_COMPLEX (0, minus_zero));
4331 check ("real(ctan(0 - i0)) = 0", __real__ result, 0);
4332 check ("imag(ctan(0 - i0)) = -0", __imag__ result, minus_zero);
4333 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, 0));
4334 check ("real(ctan(-0 + i0)) = -0", __real__ result, minus_zero);
4335 check ("imag(ctan(-0 + i0)) = 0", __imag__ result, 0);
4336 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_zero));
4337 check ("real(ctan(-0 - i0)) = -0", __real__ result, minus_zero);
4338 check ("imag(ctan(-0 - i0)) = -0", __imag__ result, minus_zero);
4341 result = FUNC(ctan) (BUILD_COMPLEX (0, plus_infty));
4342 check ("real(ctan(0 + i Inf)) = 0", __real__ result, 0);
4343 check ("imag(ctan(0 + i Inf)) = 1", __imag__ result, 1);
4344 result = FUNC(ctan) (BUILD_COMPLEX (1, plus_infty));
4345 check ("real(ctan(1 + i Inf)) = 0", __real__ result, 0);
4346 check ("imag(ctan(1 + i Inf)) = 1", __imag__ result, 1);
4347 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, plus_infty));
4348 check ("real(ctan(-0 + i Inf)) = -0", __real__ result, minus_zero);
4349 check ("imag(ctan(-0 + i Inf)) = 1", __imag__ result, 1);
4350 result = FUNC(ctan) (BUILD_COMPLEX (-1, plus_infty));
4351 check ("real(ctan(-1 + i Inf)) = -0", __real__ result, minus_zero);
4352 check ("imag(ctan(-1 + i Inf)) = 1", __imag__ result, 1);
4354 result = FUNC(ctan) (BUILD_COMPLEX (0, minus_infty));
4355 check ("real(ctan(0 - i Inf)) = 0", __real__ result, 0);
4356 check ("imag(ctan(0 - i Inf)) = -1", __imag__ result, -1);
4357 result = FUNC(ctan) (BUILD_COMPLEX (1, minus_infty));
4358 check ("real(ctan(1 - i Inf)) = 0", __real__ result, 0);
4359 check ("imag(ctan(1 - i Inf)) = -1", __imag__ result, -1);
4360 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_infty));
4361 check ("real(ctan(-0 - i Inf)) = -0", __real__ result, minus_zero);
4362 check ("imag(ctan(-0 - i Inf)) = -1", __imag__ result, -1);
4363 result = FUNC(ctan) (BUILD_COMPLEX (-1, minus_infty));
4364 check ("real(ctan(-1 - i Inf)) = -0", __real__ result, minus_zero);
4365 check ("imag(ctan(-1 - i Inf)) = -1", __imag__ result, -1);
4367 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 0));
4368 check_isnan_exc ("real(ctan(Inf + i 0)) = NaN plus invalid exception",
4369 __real__ result, INVALID_EXCEPTION);
4370 check_isnan ("imag(ctan(Inf + i 0)) = NaN plus invalid exception",
4371 __imag__ result);
4372 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 2));
4373 check_isnan_exc ("real(ctan(Inf + i 2)) = NaN plus invalid exception",
4374 __real__ result, INVALID_EXCEPTION);
4375 check_isnan ("imag(ctan(Inf + i 2)) = NaN plus invalid exception",
4376 __imag__ result);
4377 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 0));
4378 check_isnan_exc ("real(ctan(-Inf + i 0)) = NaN plus invalid exception",
4379 __real__ result, INVALID_EXCEPTION);
4380 check_isnan ("imag(ctan(-Inf + i 0)) = NaN plus invalid exception",
4381 __imag__ result);
4382 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 2));
4383 check_isnan_exc ("real(ctan(- Inf + i 2)) = NaN plus invalid exception",
4384 __real__ result, INVALID_EXCEPTION);
4385 check_isnan ("imag(ctan(- Inf + i 2)) = NaN plus invalid exception",
4386 __imag__ result);
4387 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, minus_zero));
4388 check_isnan_exc ("real(ctan(Inf - i 0)) = NaN plus invalid exception",
4389 __real__ result, INVALID_EXCEPTION);
4390 check_isnan ("imag(ctan(Inf - i 0)) = NaN plus invalid exception",
4391 __imag__ result);
4392 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, -2));
4393 check_isnan_exc ("real(ctan(Inf - i 2)) = NaN plus invalid exception",
4394 __real__ result, INVALID_EXCEPTION);
4395 check_isnan ("imag(ctan(Inf - i 2)) = NaN plus invalid exception",
4396 __imag__ result);
4397 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, minus_zero));
4398 check_isnan_exc ("real(ctan(-Inf - i 0)) = NaN plus invalid exception",
4399 __real__ result, INVALID_EXCEPTION);
4400 check_isnan ("imag(ctan(-Inf - i 0)) = NaN plus invalid exception",
4401 __imag__ result);
4402 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, -2));
4403 check_isnan_exc ("real(ctan(-Inf - i 2)) = NaN plus invalid exception",
4404 __real__ result, INVALID_EXCEPTION);
4405 check_isnan ("imag(ctan(-Inf - i 2)) = NaN plus invalid exception",
4406 __imag__ result);
4408 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, plus_infty));
4409 check ("real(ctan(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4410 check ("imag(ctan(NaN + i Inf)) = 1", __imag__ result, 1);
4411 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_infty));
4412 check ("real(ctan(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4413 check ("imag(ctan(NaN - i Inf)) = -1", __imag__ result, -1);
4415 result = FUNC(ctan) (BUILD_COMPLEX (0, nan_value));
4416 check ("real(ctan(0 + i NaN)) = 0", __real__ result, 0);
4417 check_isnan ("imag(ctan(0 + i NaN)) = NaN", __imag__ result);
4418 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, nan_value));
4419 check ("real(ctan(-0 + i NaN)) = -0", __real__ result, minus_zero);
4420 check_isnan ("imag(ctan(-0 + i NaN)) = NaN", __imag__ result);
4422 result = FUNC(ctan) (BUILD_COMPLEX (0.5, nan_value));
4423 check_isnan_maybe_exc ("real(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4424 __real__ result, INVALID_EXCEPTION);
4425 check_isnan ("imag(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4426 __imag__ result);
4427 result = FUNC(ctan) (BUILD_COMPLEX (-4.5, nan_value));
4428 check_isnan_maybe_exc ("real(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4429 __real__ result, INVALID_EXCEPTION);
4430 check_isnan ("imag(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4431 __imag__ result);
4433 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 0));
4434 check_isnan_maybe_exc ("real(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4435 __real__ result, INVALID_EXCEPTION);
4436 check_isnan ("imag(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4437 __imag__ result);
4438 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 5));
4439 check_isnan_maybe_exc ("real(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4440 __real__ result, INVALID_EXCEPTION);
4441 check_isnan ("imag(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4442 __imag__ result);
4443 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_zero));
4444 check_isnan_maybe_exc ("real(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4445 __real__ result, INVALID_EXCEPTION);
4446 check_isnan ("imag(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4447 __imag__ result);
4448 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, -0.25));
4449 check_isnan_maybe_exc ("real(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4450 __real__ result, INVALID_EXCEPTION);
4451 check_isnan ("imag(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4452 __imag__ result);
4454 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, nan_value));
4455 check_isnan ("real(ctan(NaN + i NaN)) = NaN", __real__ result);
4456 check_isnan ("imag(ctan(NaN + i NaN)) = NaN", __imag__ result);
4458 result = FUNC(ctan) (BUILD_COMPLEX (0.7, 1.2));
4459 check_eps ("real(ctan(0.7 + i 1.2)) == 0.17207...", __real__ result,
4460 0.1720734197630349001L, CHOOSE(1e-17L, 3e-17, 2e-8));
4461 check_eps ("imag(ctan(0.7 + i 1.2)) == 0.95448...", __imag__ result,
4462 0.9544807059989405538L, CHOOSE(2e-17L, 2e-16, 6e-8));
4464 result = FUNC(ctan) (BUILD_COMPLEX (-2, -3));
4465 check_eps ("real(ctan(-2 - i 3)) == -0.00376...", __real__ result,
4466 0.0037640256415042482L, CHOOSE(1e-19L, 5e-19, 0));
4467 check_eps ("imag(ctan(-2 - i 3)) == -1.00323...", __imag__ result,
4468 -1.0032386273536098014L, CHOOSE(2e-19L, 0, 2e-7));
4472 static void
4473 ctanh_test (void)
4475 __complex__ MATHTYPE result;
4477 result = FUNC(ctanh) (BUILD_COMPLEX (0, 0));
4478 check ("real(ctanh(0 + i0)) = 0", __real__ result, 0);
4479 check ("imag(ctanh(0 + i0)) = 0", __imag__ result, 0);
4480 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_zero));
4481 check ("real(ctanh(0 - i0)) = 0", __real__ result, 0);
4482 check ("imag(ctanh(0 - i0)) = -0", __imag__ result, minus_zero);
4483 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, 0));
4484 check ("real(ctanh(-0 + i0)) = -0", __real__ result, minus_zero);
4485 check ("imag(ctanh(-0 + i0)) = 0", __imag__ result, 0);
4486 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4487 check ("real(ctanh(-0 - i0)) = -0", __real__ result, minus_zero);
4488 check ("imag(ctanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4490 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 0));
4491 check ("real(ctanh(+Inf + i0)) = 1", __real__ result, 1);
4492 check ("imag(ctanh(+Inf + i0)) = 0", __imag__ result, 0);
4493 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 1));
4494 check ("real(ctanh(+Inf + i1)) = 1", __real__ result, 1);
4495 check ("imag(ctanh(+Inf + i1)) = 0", __imag__ result, 0);
4496 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4497 check ("real(ctanh(+Inf - i0)) = 1", __real__ result, 1);
4498 check ("imag(ctanh(+Inf - i0)) = -0", __imag__ result, minus_zero);
4499 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, -1));
4500 check ("real(ctanh(+Inf - i1)) = 1", __real__ result, 1);
4501 check ("imag(ctanh(+Inf - i1)) = -0", __imag__ result, minus_zero);
4502 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 0));
4503 check ("real(ctanh(-Inf + i0)) = -1", __real__ result, -1);
4504 check ("imag(ctanh(-Inf + i0)) = 0", __imag__ result, 0);
4505 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 1));
4506 check ("real(ctanh(-Inf + i1)) = -1", __real__ result, -1);
4507 check ("imag(ctanh(-Inf + i1)) = 0", __imag__ result, 0);
4508 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4509 check ("real(ctanh(-Inf - i0)) = -1", __real__ result, -1);
4510 check ("imag(ctanh(-Inf - i0)) = -0", __imag__ result, minus_zero);
4511 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, -1));
4512 check ("real(ctanh(-Inf - i1)) = -1", __real__ result, -1);
4513 check ("imag(ctanh(-Inf - i1)) = -0", __imag__ result, minus_zero);
4515 result = FUNC(ctanh) (BUILD_COMPLEX (0, plus_infty));
4516 check_isnan_exc ("real(ctanh(0 + i Inf)) = NaN plus invalid exception",
4517 __real__ result, INVALID_EXCEPTION);
4518 check_isnan ("imag(ctanh(0 + i Inf)) = NaN plus invalid exception",
4519 __imag__ result);
4520 result = FUNC(ctanh) (BUILD_COMPLEX (2, plus_infty));
4521 check_isnan_exc ("real(ctanh(2 + i Inf)) = NaN plus invalid exception",
4522 __real__ result, INVALID_EXCEPTION);
4523 check_isnan ("imag(ctanh(2 + i Inf)) = NaN plus invalid exception",
4524 __imag__ result);
4525 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_infty));
4526 check_isnan_exc ("real(ctanh(0 - i Inf)) = NaN plus invalid exception",
4527 __real__ result, INVALID_EXCEPTION);
4528 check_isnan ("imag(ctanh(0 - i Inf)) = NaN plus invalid exception",
4529 __imag__ result);
4530 result = FUNC(ctanh) (BUILD_COMPLEX (2, minus_infty));
4531 check_isnan_exc ("real(ctanh(2 - i Inf)) = NaN plus invalid exception",
4532 __real__ result, INVALID_EXCEPTION);
4533 check_isnan ("imag(ctanh(2 - i Inf)) = NaN plus invalid exception",
4534 __imag__ result);
4535 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4536 check_isnan_exc ("real(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4537 __real__ result, INVALID_EXCEPTION);
4538 check_isnan ("imag(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4539 __imag__ result);
4540 result = FUNC(ctanh) (BUILD_COMPLEX (-2, plus_infty));
4541 check_isnan_exc ("real(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4542 __real__ result, INVALID_EXCEPTION);
4543 check_isnan ("imag(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4544 __imag__ result);
4545 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4546 check_isnan_exc ("real(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4547 __real__ result, INVALID_EXCEPTION);
4548 check_isnan ("imag(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4549 __imag__ result);
4550 result = FUNC(ctanh) (BUILD_COMPLEX (-2, minus_infty));
4551 check_isnan_exc ("real(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4552 __real__ result, INVALID_EXCEPTION);
4553 check_isnan ("imag(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4554 __imag__ result);
4556 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, nan_value));
4557 check ("real(ctanh(+Inf + i NaN)) = 1", __real__ result, 1);
4558 check ("imag(ctanh(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4559 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, nan_value));
4560 check ("real(ctanh(-Inf + i NaN)) = -1", __real__ result, -1);
4561 check ("imag(ctanh(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4563 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0));
4564 check_isnan ("real(ctanh(NaN + i0)) = NaN", __real__ result);
4565 check ("imag(ctanh(NaN + i0)) = 0", __imag__ result, 0);
4566 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, minus_zero));
4567 check_isnan ("real(ctanh(NaN - i0)) = NaN", __real__ result);
4568 check ("imag(ctanh(NaN - i0)) = -0", __imag__ result, minus_zero);
4570 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0.5));
4571 check_isnan_maybe_exc ("real(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4572 __real__ result, INVALID_EXCEPTION);
4573 check_isnan ("imag(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4574 __imag__ result);
4575 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, -4.5));
4576 check_isnan_maybe_exc ("real(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4577 __real__ result, INVALID_EXCEPTION);
4578 check_isnan ("imag(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4579 __imag__ result);
4581 result = FUNC(ctanh) (BUILD_COMPLEX (0, nan_value));
4582 check_isnan_maybe_exc ("real(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4583 __real__ result, INVALID_EXCEPTION);
4584 check_isnan ("imag(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4585 __imag__ result);
4586 result = FUNC(ctanh) (BUILD_COMPLEX (5, nan_value));
4587 check_isnan_maybe_exc ("real(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4588 __real__ result, INVALID_EXCEPTION);
4589 check_isnan ("imag(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4590 __imag__ result);
4591 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, nan_value));
4592 check_isnan_maybe_exc ("real(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4593 __real__ result, INVALID_EXCEPTION);
4594 check_isnan ("imag(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4595 __imag__ result);
4596 result = FUNC(ctanh) (BUILD_COMPLEX (-0.25, nan_value));
4597 check_isnan_maybe_exc ("real(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4598 __real__ result, INVALID_EXCEPTION);
4599 check_isnan ("imag(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4600 __imag__ result);
4602 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, nan_value));
4603 check_isnan ("real(ctanh(NaN + i NaN)) = NaN", __real__ result);
4604 check_isnan ("imag(ctanh(NaN + i NaN)) = NaN", __imag__ result);
4606 result = FUNC(ctanh) (BUILD_COMPLEX (0, M_PI_4l));
4607 check ("real(ctanh (0 + i pi/4)) == 0", __real__ result, 0);
4608 check_eps ("imag(ctanh (0 + i pi/4)) == 1", __imag__ result, 1,
4609 CHOOSE (0, 2e-16, 2e-7));
4611 result = FUNC(ctanh) (BUILD_COMPLEX (0.7, 1.2));
4612 check_eps ("real(ctanh(0.7 + i 1.2)) == 1.34721...", __real__ result,
4613 1.3472197399061191630L, CHOOSE(4e-17L, 5e-16, 2e-7));
4614 check_eps ("imag(ctanh(0.7 + i 1.2)) == -0.47786...", __imag__ result,
4615 0.4778641038326365540L, CHOOSE(9e-17L, 2e-16, 9e-8));
4617 result = FUNC(ctanh) (BUILD_COMPLEX (-2, -3));
4618 check_eps ("real(ctanh(-2 - i 3)) == -0.96538...", __real__ result,
4619 -0.9653858790221331242L, CHOOSE(2e-19L, 2e-16, 2e-7));
4620 check_eps ("imag(ctanh(-2 - i 3)) == 0.00988...", __imag__ result,
4621 0.0098843750383224937L, CHOOSE(7e-20L, 2e-16, 1e-9));
4625 static void
4626 clog_test (void)
4628 __complex__ MATHTYPE result;
4630 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, 0));
4631 check_isinfn_exc ("real(clog(-0 + i0)) = -Inf plus divide-by-zero exception",
4632 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4633 check ("imag(clog(-0 + i0)) = pi plus divide-by-zero exception",
4634 __imag__ result, M_PIl);
4635 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_zero));
4636 check_isinfn_exc ("real(clog(-0 - i0)) = -Inf plus divide-by-zero exception",
4637 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4638 check ("imag(clog(-0 - i0)) = -pi plus divide-by-zero exception",
4639 __imag__ result, -M_PIl);
4641 result = FUNC(clog) (BUILD_COMPLEX (0, 0));
4642 check_isinfn_exc ("real(clog(0 + i0)) = -Inf plus divide-by-zero exception",
4643 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4644 check ("imag(clog(0 + i0)) = 0 plus divide-by-zero exception",
4645 __imag__ result, 0);
4646 result = FUNC(clog) (BUILD_COMPLEX (0, minus_zero));
4647 check_isinfn_exc ("real(clog(0 - i0)) = -Inf plus divide-by-zero exception",
4648 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4649 check ("imag(clog(0 - i0)) = -0 plus divide-by-zero exception",
4650 __imag__ result, minus_zero);
4652 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, plus_infty));
4653 check_isinfp ("real(clog(-Inf + i Inf)) = +Inf", __real__ result);
4654 check ("imag(clog(-Inf + i Inf)) = 3*pi/4", __imag__ result,
4655 M_PIl - M_PI_4l);
4656 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_infty));
4657 check_isinfp ("real(clog(-Inf - i Inf)) = +Inf", __real__ result);
4658 check ("imag(clog(-Inf - i Inf)) = -3*pi/4", __imag__ result,
4659 M_PI_4l - M_PIl);
4661 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, plus_infty));
4662 check_isinfp ("real(clog(+Inf + i Inf)) = +Inf", __real__ result);
4663 check ("imag(clog(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
4664 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_infty));
4665 check_isinfp ("real(clog(+Inf - i Inf)) = +Inf", __real__ result);
4666 check ("imag(clog(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
4668 result = FUNC(clog) (BUILD_COMPLEX (0, plus_infty));
4669 check_isinfp ("real(clog(0 + i Inf)) = +Inf", __real__ result);
4670 check ("imag(clog(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4671 result = FUNC(clog) (BUILD_COMPLEX (3, plus_infty));
4672 check_isinfp ("real(clog(3 + i Inf)) = +Inf", __real__ result);
4673 check ("imag(clog(3 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4674 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, plus_infty));
4675 check_isinfp ("real(clog(-0 + i Inf)) = +Inf", __real__ result);
4676 check ("imag(clog(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4677 result = FUNC(clog) (BUILD_COMPLEX (-3, plus_infty));
4678 check_isinfp ("real(clog(-3 + i Inf)) = +Inf", __real__ result);
4679 check ("imag(clog(-3 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4680 result = FUNC(clog) (BUILD_COMPLEX (0, minus_infty));
4681 check_isinfp ("real(clog(0 - i Inf)) = +Inf", __real__ result);
4682 check ("imag(clog(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4683 result = FUNC(clog) (BUILD_COMPLEX (3, minus_infty));
4684 check_isinfp ("real(clog(3 - i Inf)) = +Inf", __real__ result);
4685 check ("imag(clog(3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4686 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_infty));
4687 check_isinfp ("real(clog(-0 - i Inf)) = +Inf", __real__ result);
4688 check ("imag(clog(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4689 result = FUNC(clog) (BUILD_COMPLEX (-3, minus_infty));
4690 check_isinfp ("real(clog(-3 - i Inf)) = +Inf", __real__ result);
4691 check ("imag(clog(-3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4693 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 0));
4694 check_isinfp ("real(clog(-Inf + i0)) = +Inf", __real__ result);
4695 check ("imag(clog(-Inf + i0)) = pi", __imag__ result, M_PIl);
4696 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 1));
4697 check_isinfp ("real(clog(-Inf + i1)) = +Inf", __real__ result);
4698 check ("imag(clog(-Inf + i1)) = pi", __imag__ result, M_PIl);
4699 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_zero));
4700 check_isinfp ("real(clog(-Inf - i0)) = +Inf", __real__ result);
4701 check ("imag(clog(-Inf - i0)) = -pi", __imag__ result, -M_PIl);
4702 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, -1));
4703 check_isinfp ("real(clog(-Inf - i1)) = +Inf", __real__ result);
4704 check ("imag(clog(-Inf - i1)) = -pi", __imag__ result, -M_PIl);
4706 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 0));
4707 check_isinfp ("real(clog(+Inf + i0)) = +Inf", __real__ result);
4708 check ("imag(clog(+Inf + i0)) = 0", __imag__ result, 0);
4709 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 1));
4710 check_isinfp ("real(clog(+Inf + i1)) = +Inf", __real__ result);
4711 check ("imag(clog(+Inf + i1)) = 0", __imag__ result, 0);
4712 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_zero));
4713 check_isinfp ("real(clog(+Inf - i0)) = +Inf", __real__ result);
4714 check ("imag(clog(+Inf - i0)) = -0", __imag__ result, minus_zero);
4715 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, -1));
4716 check_isinfp ("real(clog(+Inf - i1)) = +Inf", __real__ result);
4717 check ("imag(clog(+Inf - i1)) = -0", __imag__ result, minus_zero);
4719 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, nan_value));
4720 check_isinfp ("real(clog(+Inf + i NaN)) = +Inf", __real__ result);
4721 check_isnan ("imag(clog(+Inf + i NaN)) = NaN", __imag__ result);
4722 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, nan_value));
4723 check_isinfp ("real(clog(-Inf + i NaN)) = +Inf", __real__ result);
4724 check_isnan ("imag(clog(-Inf + i NaN)) = NaN", __imag__ result);
4726 result = FUNC(clog) (BUILD_COMPLEX (nan_value, plus_infty));
4727 check_isinfp ("real(clog(NaN + i Inf)) = +Inf", __real__ result);
4728 check_isnan ("imag(clog(NaN + i Inf)) = NaN", __imag__ result);
4729 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_infty));
4730 check_isinfp ("real(clog(NaN - i Inf)) = +Inf", __real__ result);
4731 check_isnan ("imag(clog(NaN - i Inf)) = NaN", __imag__ result);
4733 result = FUNC(clog) (BUILD_COMPLEX (0, nan_value));
4734 check_isnan_maybe_exc ("real(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4735 __real__ result, INVALID_EXCEPTION);
4736 check_isnan ("imag(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4737 __imag__ result);
4738 result = FUNC(clog) (BUILD_COMPLEX (3, nan_value));
4739 check_isnan_maybe_exc ("real(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4740 __real__ result, INVALID_EXCEPTION);
4741 check_isnan ("imag(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4742 __imag__ result);
4743 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, nan_value));
4744 check_isnan_maybe_exc ("real(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4745 __real__ result, INVALID_EXCEPTION);
4746 check_isnan ("imag(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4747 __imag__ result);
4748 result = FUNC(clog) (BUILD_COMPLEX (-3, nan_value));
4749 check_isnan_maybe_exc ("real(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4750 __real__ result, INVALID_EXCEPTION);
4751 check_isnan ("imag(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4752 __imag__ result);
4754 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 0));
4755 check_isnan_maybe_exc ("real(clog(NaN + i0)) = NaN plus maybe invalid exception",
4756 __real__ result, INVALID_EXCEPTION);
4757 check_isnan ("imag(clog(NaN + i0)) = NaN plus maybe invalid exception",
4758 __imag__ result);
4759 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 5));
4760 check_isnan_maybe_exc ("real(clog(NaN + i5)) = NaN plus maybe invalid exception",
4761 __real__ result, INVALID_EXCEPTION);
4762 check_isnan ("imag(clog(NaN + i5)) = NaN plus maybe invalid exception",
4763 __imag__ result);
4764 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_zero));
4765 check_isnan_maybe_exc ("real(clog(NaN - i0)) = NaN plus maybe invalid exception",
4766 __real__ result, INVALID_EXCEPTION);
4767 check_isnan ("imag(clog(NaN - i0)) = NaN plus maybe invalid exception",
4768 __imag__ result);
4769 result = FUNC(clog) (BUILD_COMPLEX (nan_value, -5));
4770 check_isnan_maybe_exc ("real(clog(NaN - i5)) = NaN plus maybe invalid exception",
4771 __real__ result, INVALID_EXCEPTION);
4772 check_isnan ("imag(clog(NaN - i5)) = NaN plus maybe invalid exception",
4773 __imag__ result);
4775 result = FUNC(clog) (BUILD_COMPLEX (nan_value, nan_value));
4776 check_isnan ("real(clog(NaN + i NaN)) = NaN", __real__ result);
4777 check_isnan ("imag(clog(NaN + i NaN)) = NaN", __imag__ result);
4779 result = FUNC(clog) (BUILD_COMPLEX (0.7, 1.2));
4780 check_eps ("real(clog(0.7 + i 1.2)) == 0.32876...", __real__ result,
4781 0.3287600014583970919L, CHOOSE(5e-17L, 6e-17, 3e-8));
4782 check_eps ("imag(clog(0.7 + i 1.2)) == 1.04272...", __imag__ result,
4783 1.0427218783685369524L, CHOOSE(2e-17L, 0, 0));
4785 result = FUNC(clog) (BUILD_COMPLEX (-2, -3));
4786 check_eps ("real(clog(-2 - i 3)) == 1.28247...", __real__ result,
4787 1.2824746787307683680L, CHOOSE(3e-19L, 0, 0));
4788 check_eps ("imag(clog(-2 - i 3)) == -2.15879...", __imag__ result,
4789 -2.1587989303424641704L, CHOOSE(2e-18L, 5e-16, 8e-7));
4793 static void
4794 clog10_test (void)
4796 __complex__ MATHTYPE result;
4798 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, 0));
4799 check_isinfn_exc ("real(clog10(-0 + i0)) = -Inf plus divide-by-zero exception",
4800 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4801 check ("imag(clog10(-0 + i0)) = pi plus divide-by-zero exception",
4802 __imag__ result, M_PIl);
4803 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_zero));
4804 check_isinfn_exc ("real(clog10(-0 - i0)) = -Inf plus divide-by-zero exception",
4805 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4806 check ("imag(clog10(-0 - i0)) = -pi plus divide-by-zero exception",
4807 __imag__ result, -M_PIl);
4809 result = FUNC(clog10) (BUILD_COMPLEX (0, 0));
4810 check_isinfn_exc ("real(clog10(0 + i0)) = -Inf plus divide-by-zero exception",
4811 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4812 check ("imag(clog10(0 + i0)) = 0 plus divide-by-zero exception",
4813 __imag__ result, 0);
4814 result = FUNC(clog10) (BUILD_COMPLEX (0, minus_zero));
4815 check_isinfn_exc ("real(clog10(0 - i0)) = -Inf plus divide-by-zero exception",
4816 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4817 check ("imag(clog10(0 - i0)) = -0 plus divide-by-zero exception",
4818 __imag__ result, minus_zero);
4820 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, plus_infty));
4821 check_isinfp ("real(clog10(-Inf + i Inf)) = +Inf", __real__ result);
4822 check_eps ("imag(clog10(-Inf + i Inf)) = 3*pi/4*M_LOG10E", __imag__ result,
4823 (M_PIl - M_PI_4l) * M_LOG10El, CHOOSE (0, 3e-16, 0));
4824 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_infty));
4825 check_isinfp ("real(clog10(-Inf - i Inf)) = +Inf", __real__ result);
4826 check_eps ("imag(clog10(-Inf - i Inf)) = -3*pi/4*M_LOG10E", __imag__ result,
4827 (M_PI_4l - M_PIl) * M_LOG10El, CHOOSE (0, 3e-16, 0));
4829 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, plus_infty));
4830 check_isinfp ("real(clog10(+Inf + i Inf)) = +Inf", __real__ result);
4831 check_eps ("imag(clog10(+Inf + i Inf)) = pi/4*M_LOG10E", __imag__ result,
4832 M_PI_4l * M_LOG10El, CHOOSE (0, 6e-17, 3e-8));
4833 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_infty));
4834 check_isinfp ("real(clog10(+Inf - i Inf)) = +Inf", __real__ result);
4835 check_eps ("imag(clog10(+Inf - i Inf)) = -pi/4*M_LOG10E", __imag__ result,
4836 -M_PI_4l * M_LOG10El, CHOOSE (0, 6e-17, 3e-8));
4838 result = FUNC(clog10) (BUILD_COMPLEX (0, plus_infty));
4839 check_isinfp ("real(clog10(0 + i Inf)) = +Inf", __real__ result);
4840 check_eps ("imag(clog10(0 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4841 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4842 result = FUNC(clog10) (BUILD_COMPLEX (3, plus_infty));
4843 check_isinfp ("real(clog10(3 + i Inf)) = +Inf", __real__ result);
4844 check_eps ("imag(clog10(3 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4845 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4846 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, plus_infty));
4847 check_isinfp ("real(clog10(-0 + i Inf)) = +Inf", __real__ result);
4848 check_eps ("imag(clog10(-0 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4849 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4850 result = FUNC(clog10) (BUILD_COMPLEX (-3, plus_infty));
4851 check_isinfp ("real(clog10(-3 + i Inf)) = +Inf", __real__ result);
4852 check_eps ("imag(clog10(-3 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4853 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4854 result = FUNC(clog10) (BUILD_COMPLEX (0, minus_infty));
4855 check_isinfp ("real(clog10(0 - i Inf)) = +Inf", __real__ result);
4856 check_eps ("imag(clog10(0 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4857 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4858 result = FUNC(clog10) (BUILD_COMPLEX (3, minus_infty));
4859 check_isinfp ("real(clog10(3 - i Inf)) = +Inf", __real__ result);
4860 check_eps ("imag(clog10(3 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4861 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4862 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_infty));
4863 check_isinfp ("real(clog10(-0 - i Inf)) = +Inf", __real__ result);
4864 check_eps ("imag(clog10(-0 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4865 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4866 result = FUNC(clog10) (BUILD_COMPLEX (-3, minus_infty));
4867 check_isinfp ("real(clog10(-3 - i Inf)) = +Inf", __real__ result);
4868 check_eps ("imag(clog10(-3 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4869 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4871 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 0));
4872 check_isinfp ("real(clog10(-Inf + i0)) = +Inf", __real__ result);
4873 check_eps ("imag(clog10(-Inf + i0)) = pi*M_LOG10E", __imag__ result,
4874 M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4875 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 1));
4876 check_isinfp ("real(clog10(-Inf + i1)) = +Inf", __real__ result);
4877 check_eps ("imag(clog10(-Inf + i1)) = pi*M_LOG10E", __imag__ result,
4878 M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4879 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_zero));
4880 check_isinfp ("real(clog10(-Inf - i0)) = +Inf", __real__ result);
4881 check_eps ("imag(clog10(-Inf - i0)) = -pi*M_LOG10E", __imag__ result,
4882 -M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4883 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, -1));
4884 check_isinfp ("real(clog10(-Inf - i1)) = +Inf", __real__ result);
4885 check_eps ("imag(clog10(-Inf - i1)) = -pi*M_LOG10E", __imag__ result,
4886 -M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4888 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 0));
4889 check_isinfp ("real(clog10(+Inf + i0)) = +Inf", __real__ result);
4890 check ("imag(clog10(+Inf + i0)) = 0", __imag__ result, 0);
4891 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 1));
4892 check_isinfp ("real(clog10(+Inf + i1)) = +Inf", __real__ result);
4893 check ("imag(clog10(+Inf + i1)) = 0", __imag__ result, 0);
4894 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_zero));
4895 check_isinfp ("real(clog10(+Inf - i0)) = +Inf", __real__ result);
4896 check ("imag(clog10(+Inf - i0)) = -0", __imag__ result, minus_zero);
4897 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, -1));
4898 check_isinfp ("real(clog10(+Inf - i1)) = +Inf", __real__ result);
4899 check ("imag(clog10(+Inf - i1)) = -0", __imag__ result, minus_zero);
4901 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, nan_value));
4902 check_isinfp ("real(clog10(+Inf + i NaN)) = +Inf", __real__ result);
4903 check_isnan ("imag(clog10(+Inf + i NaN)) = NaN", __imag__ result);
4904 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, nan_value));
4905 check_isinfp ("real(clog10(-Inf + i NaN)) = +Inf", __real__ result);
4906 check_isnan ("imag(clog10(-Inf + i NaN)) = NaN", __imag__ result);
4908 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, plus_infty));
4909 check_isinfp ("real(clog10(NaN + i Inf)) = +Inf", __real__ result);
4910 check_isnan ("imag(clog10(NaN + i Inf)) = NaN", __imag__ result);
4911 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_infty));
4912 check_isinfp ("real(clog10(NaN - i Inf)) = +Inf", __real__ result);
4913 check_isnan ("imag(clog10(NaN - i Inf)) = NaN", __imag__ result);
4915 result = FUNC(clog10) (BUILD_COMPLEX (0, nan_value));
4916 check_isnan_maybe_exc ("real(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4917 __real__ result, INVALID_EXCEPTION);
4918 check_isnan ("imag(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4919 __imag__ result);
4920 result = FUNC(clog10) (BUILD_COMPLEX (3, nan_value));
4921 check_isnan_maybe_exc ("real(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4922 __real__ result, INVALID_EXCEPTION);
4923 check_isnan ("imag(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4924 __imag__ result);
4925 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, nan_value));
4926 check_isnan_maybe_exc ("real(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4927 __real__ result, INVALID_EXCEPTION);
4928 check_isnan ("imag(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4929 __imag__ result);
4930 result = FUNC(clog10) (BUILD_COMPLEX (-3, nan_value));
4931 check_isnan_maybe_exc ("real(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4932 __real__ result, INVALID_EXCEPTION);
4933 check_isnan ("imag(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4934 __imag__ result);
4936 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 0));
4937 check_isnan_maybe_exc ("real(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4938 __real__ result, INVALID_EXCEPTION);
4939 check_isnan ("imag(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4940 __imag__ result);
4941 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 5));
4942 check_isnan_maybe_exc ("real(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4943 __real__ result, INVALID_EXCEPTION);
4944 check_isnan ("imag(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4945 __imag__ result);
4946 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_zero));
4947 check_isnan_maybe_exc ("real(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4948 __real__ result, INVALID_EXCEPTION);
4949 check_isnan ("imag(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4950 __imag__ result);
4951 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, -5));
4952 check_isnan_maybe_exc ("real(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4953 __real__ result, INVALID_EXCEPTION);
4954 check_isnan ("imag(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4955 __imag__ result);
4957 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, nan_value));
4958 check_isnan ("real(clog10(NaN + i NaN)) = NaN", __real__ result);
4959 check_isnan ("imag(clog10(NaN + i NaN)) = NaN", __imag__ result);
4961 result = FUNC(clog10) (BUILD_COMPLEX (0.7, 1.2));
4962 check_eps ("real(clog10(0.7 + i 1.2)) == 0.14277...", __real__ result,
4963 0.1427786545038868803L, CHOOSE(2e-17L, 6e-17, 2e-8));
4964 check_eps ("imag(clog10(0.7 + i 1.2)) == 0.45284...", __imag__ result,
4965 0.4528483579352493248L, CHOOSE(6e-18, 6e-17, 3e-8));
4967 result = FUNC(clog10) (BUILD_COMPLEX (-2, -3));
4968 check_eps ("real(clog10(-2 - i 3)) == 0.55697...", __real__ result,
4969 0.5569716761534183846L, CHOOSE(6e-20L, 0, 0));
4970 check_eps ("imag(clog10(-2 - i 3)) == -0.93755...", __imag__ result,
4971 -0.9375544629863747085L, CHOOSE (7e-19L, 2e-16, 3e-7));
4975 static void
4976 csqrt_test (void)
4978 __complex__ MATHTYPE result;
4980 result = FUNC(csqrt) (BUILD_COMPLEX (0, 0));
4981 check ("real(csqrt(0 + i0)) = 0", __real__ result, 0);
4982 check ("imag(csqrt(0 + i0)) = 0", __imag__ result, 0);
4983 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_zero));
4984 check ("real(csqrt(0 - i0)) = 0", __real__ result, 0);
4985 check ("imag(csqrt(0 - i0)) = -0", __imag__ result, minus_zero);
4986 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, 0));
4987 check ("real(csqrt(-0 + i0)) = 0", __real__ result, 0);
4988 check ("imag(csqrt(-0 + i0)) = 0", __imag__ result, 0);
4989 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_zero));
4990 check ("real(csqrt(-0 - i0)) = 0", __real__ result, 0);
4991 check ("imag(csqrt(-0 - i0)) = -0", __imag__ result, minus_zero);
4993 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 0));
4994 check ("real(csqrt(-Inf + i0)) = 0", __real__ result, 0);
4995 check_isinfp ("imag(csqrt(-Inf + i0)) = +Inf", __imag__ result);
4996 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 6));
4997 check ("real(csqrt(-Inf + i6)) = 0", __real__ result, 0);
4998 check_isinfp ("imag(csqrt(-Inf + i6)) = +Inf", __imag__ result);
4999 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_zero));
5000 check ("real(csqrt(-Inf - i0)) = 0", __real__ result, 0);
5001 check_isinfn ("imag(csqrt(-Inf - i0)) = -Inf", __imag__ result);
5002 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, -6));
5003 check ("real(csqrt(-Inf - i6)) = 0", __real__ result, 0);
5004 check_isinfn ("imag(csqrt(-Inf - i6)) = -Inf", __imag__ result);
5006 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 0));
5007 check_isinfp ("real(csqrt(+Inf + i0)) = +Inf", __real__ result);
5008 check ("imag(csqrt(+Inf + i0)) = 0", __imag__ result, 0);
5009 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 6));
5010 check_isinfp ("real(csqrt(+Inf + i6)) = +Inf", __real__ result);
5011 check ("imag(csqrt(+Inf + i6)) = 0", __imag__ result, 0);
5012 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_zero));
5013 check_isinfp ("real(csqrt(+Inf - i0)) = +Inf", __real__ result);
5014 check ("imag(csqrt(+Inf - i0)) = -0", __imag__ result, minus_zero);
5015 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, -6));
5016 check_isinfp ("real(csqrt(+Inf - i6)) = +Inf", __real__ result);
5017 check ("imag(csqrt(+Inf - i6)) = -0", __imag__ result, minus_zero);
5019 result = FUNC(csqrt) (BUILD_COMPLEX (0, plus_infty));
5020 check_isinfp ("real(csqrt(0 + i Inf)) = +Inf", __real__ result);
5021 check_isinfp ("imag(csqrt(0 + i Inf)) = +Inf", __imag__ result);
5022 result = FUNC(csqrt) (BUILD_COMPLEX (4, plus_infty));
5023 check_isinfp ("real(csqrt(4 + i Inf)) = +Inf", __real__ result);
5024 check_isinfp ("imag(csqrt(4 + i Inf)) = +Inf", __imag__ result);
5025 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, plus_infty));
5026 check_isinfp ("real(csqrt(+Inf + i Inf)) = +Inf", __real__ result);
5027 check_isinfp ("imag(csqrt(+Inf + i Inf)) = +Inf", __imag__ result);
5028 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, plus_infty));
5029 check_isinfp ("real(csqrt(-0 + i Inf)) = +Inf", __real__ result);
5030 check_isinfp ("imag(csqrt(-0 + i Inf)) = +Inf", __imag__ result);
5031 result = FUNC(csqrt) (BUILD_COMPLEX (-4, plus_infty));
5032 check_isinfp ("real(csqrt(-4 + i Inf)) = +Inf", __real__ result);
5033 check_isinfp ("imag(csqrt(-4 + i Inf)) = +Inf", __imag__ result);
5034 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, plus_infty));
5035 check_isinfp ("real(csqrt(-Inf + i Inf)) = +Inf", __real__ result);
5036 check_isinfp ("imag(csqrt(-Inf + i Inf)) = +Inf", __imag__ result);
5037 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_infty));
5038 check_isinfp ("real(csqrt(0 - i Inf)) = +Inf", __real__ result);
5039 check_isinfn ("imag(csqrt(0 - i Inf)) = -Inf", __imag__ result);
5040 result = FUNC(csqrt) (BUILD_COMPLEX (4, minus_infty));
5041 check_isinfp ("real(csqrt(4 - i Inf)) = +Inf", __real__ result);
5042 check_isinfn ("imag(csqrt(4 - i Inf)) = -Inf", __imag__ result);
5043 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_infty));
5044 check_isinfp ("real(csqrt(+Inf - i Inf)) = +Inf", __real__ result);
5045 check_isinfn ("imag(csqrt(+Inf - i Inf)) = -Inf", __imag__ result);
5046 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_infty));
5047 check_isinfp ("real(csqrt(-0 - i Inf)) = +Inf", __real__ result);
5048 check_isinfn ("imag(csqrt(-0 - i Inf)) = -Inf", __imag__ result);
5049 result = FUNC(csqrt) (BUILD_COMPLEX (-4, minus_infty));
5050 check_isinfp ("real(csqrt(-4 - i Inf)) = +Inf", __real__ result);
5051 check_isinfn ("imag(csqrt(-4 - i Inf)) = -Inf", __imag__ result);
5052 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_infty));
5053 check_isinfp ("real(csqrt(-Inf - i Inf)) = +Inf", __real__ result);
5054 check_isinfn ("imag(csqrt(-Inf - i Inf)) = -Inf", __imag__ result);
5056 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, nan_value));
5057 check_isnan ("real(csqrt(-Inf + i NaN)) = NaN", __real__ result);
5058 check_isinfp ("imag(csqrt(-Inf + i NaN)) = +-Inf",
5059 FUNC(fabs) (__imag__ result));
5061 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, nan_value));
5062 check_isinfp ("real(csqrt(+Inf + i NaN)) = +Inf", __real__ result);
5063 check_isnan ("imag(csqrt(+Inf + i NaN)) = NaN", __imag__ result);
5065 result = FUNC(csqrt) (BUILD_COMPLEX (0, nan_value));
5066 check_isnan_maybe_exc ("real(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
5067 __real__ result, INVALID_EXCEPTION);
5068 check_isnan ("imag(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
5069 __imag__ result);
5070 result = FUNC(csqrt) (BUILD_COMPLEX (1, nan_value));
5071 check_isnan_maybe_exc ("real(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
5072 __real__ result, INVALID_EXCEPTION);
5073 check_isnan ("imag(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
5074 __imag__ result);
5075 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, nan_value));
5076 check_isnan_maybe_exc ("real(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
5077 __real__ result, INVALID_EXCEPTION);
5078 check_isnan ("imag(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
5079 __imag__ result);
5080 result = FUNC(csqrt) (BUILD_COMPLEX (-1, nan_value));
5081 check_isnan_maybe_exc ("real(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
5082 __real__ result, INVALID_EXCEPTION);
5083 check_isnan ("imag(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
5084 __imag__ result);
5086 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 0));
5087 check_isnan_maybe_exc ("real(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
5088 __real__ result, INVALID_EXCEPTION);
5089 check_isnan ("imag(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
5090 __imag__ result);
5091 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 8));
5092 check_isnan_maybe_exc ("real(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
5093 __real__ result, INVALID_EXCEPTION);
5094 check_isnan ("imag(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
5095 __imag__ result);
5096 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, minus_zero));
5097 check_isnan_maybe_exc ("real(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
5098 __real__ result, INVALID_EXCEPTION);
5099 check_isnan ("imag(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
5100 __imag__ result);
5101 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, -8));
5102 check_isnan_maybe_exc ("real(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
5103 __real__ result, INVALID_EXCEPTION);
5104 check_isnan ("imag(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
5105 __imag__ result);
5107 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, nan_value));
5108 check_isnan ("real(csqrt(NaN + i NaN)) = NaN", __real__ result);
5109 check_isnan ("imag(csqrt(NaN + i NaN)) = NaN", __imag__ result);
5111 result = FUNC(csqrt) (BUILD_COMPLEX (16.0, -30.0));
5112 check ("real(csqrt(16 - 30i)) = 5", __real__ result, 5.0);
5113 check ("imag(csqrt(16 - 30i)) = -3", __imag__ result, -3.0);
5115 result = FUNC(csqrt) (BUILD_COMPLEX (-1, 0));
5116 check ("real(csqrt(1 + i0) = 0", __real__ result, 0);
5117 check ("imag(csqrt(1 + i0) = 1", __imag__ result, 1);
5119 result = FUNC(csqrt) (BUILD_COMPLEX (0, 2));
5120 check ("real(csqrt(0 + i 2) = 1", __real__ result, 1);
5121 check ("imag(csqrt(0 + i 2) = 1", __imag__ result, 1);
5123 result = FUNC(csqrt) (BUILD_COMPLEX (119, 120));
5124 check ("real(csqrt(119 + i 120) = 12", __real__ result, 12);
5125 check ("imag(csqrt(119 + i 120) = 5", __imag__ result, 5);
5127 result = FUNC(csqrt) (BUILD_COMPLEX (0.7, 1.2));
5128 check_eps ("real(csqrt(0.7 + i 1.2)) == 1.02206...", __real__ result,
5129 1.0220676100300264507L, CHOOSE(3e-17L, 3e-16, 2e-7));
5130 check_eps ("imag(csqrt(0.7 + i 1.2)) == 0.58704...", __imag__ result,
5131 0.5870453129635652115L, CHOOSE(7e-18L, 0, 0));
5133 result = FUNC(csqrt) (BUILD_COMPLEX (-2, -3));
5134 check_eps ("real(csqrt(-2 - i 3)) == -0.89597...", __real__ result,
5135 0.8959774761298381247L, CHOOSE(6e-20L, 2e-16, 6e-8));
5136 check_eps ("imag(csqrt(-2 - i 3)) == -1.67414...", __imag__ result,
5137 -1.6741492280355400404L, CHOOSE(0, 5e-16, 0));
5141 static void
5142 cpow_test (void)
5144 __complex__ MATHTYPE result;
5146 result = FUNC (cpow) (BUILD_COMPLEX (1, 0), BUILD_COMPLEX (0, 0));
5147 check ("real(cpow (1 + i0), (0 + i0)) == 0", __real__ result, 1);
5148 check ("imag(cpow (1 + i0), (0 + i0)) == 0", __imag__ result, 0);
5150 result = FUNC (cpow) (BUILD_COMPLEX (2, 0), BUILD_COMPLEX (10, 0));
5151 check_eps ("real(cpow (2 + i0), (10 + i0)) == 1024", __real__ result, 1024,
5152 CHOOSE (2e-16L, 0, 0));
5153 check ("imag(cpow (2 + i0), (10 + i0)) == 0", __imag__ result, 0);
5155 result = FUNC (cpow) (BUILD_COMPLEX (M_El, 0), BUILD_COMPLEX (0, 2 * M_PIl));
5156 check_eps ("real(cpow (e + i0), (0 + i 2*PI)) == 1", __real__ result, 1,
5157 CHOOSE (0, 0, 6e-8));
5158 check_eps ("imag(cpow (e + i0), (0 + i 2*PI)) == 0", __imag__ result, 0,
5159 CHOOSE (3e-18L, 3e-16, 4e-7));
5161 result = FUNC (cpow) (BUILD_COMPLEX (2, 3), BUILD_COMPLEX (4, 0));
5162 check_eps ("real(cpow (2 + i3), (4 + i0)) == -119", __real__ result, -119,
5163 CHOOSE (9e-16L, 2e-14, 4e-5));
5164 check_eps ("imag(cpow (2 + i3), (4 + i0)) == -120", __imag__ result, -120,
5165 CHOOSE (1e-15L, 0, 5e-5));
5169 static void
5170 cabs_test (void)
5172 /* cabs (x + iy) is specified as hypot (x,y) */
5173 MATHTYPE a;
5174 a = random_greater (0);
5175 check_isinfp_ext ("cabs (+inf + i x) == +inf",
5176 FUNC(cabs) (BUILD_COMPLEX (plus_infty, a)), a);
5177 check_isinfp_ext ("cabs (-inf + i x) == +inf",
5178 FUNC(cabs) (BUILD_COMPLEX (minus_infty, a)), a);
5180 check_isinfp ("cabs (+inf+ iNaN) == +inf",
5181 FUNC(cabs) (BUILD_COMPLEX(minus_infty, nan_value)));
5182 check_isinfp ("cabs (-inf+ iNaN) == +inf",
5183 FUNC(cabs) (BUILD_COMPLEX(minus_infty, nan_value)));
5185 check_isnan ("cabs (NaN+ iNaN) == NaN",
5186 FUNC(cabs) (BUILD_COMPLEX(nan_value, nan_value)));
5188 a = FUNC(cabs) (BUILD_COMPLEX (12.4L, 0.7L));
5189 check ("cabs (x,y) == cabs (y,x)",
5190 FUNC(cabs) (BUILD_COMPLEX(0.7L, 12.4L)), a);
5191 check ("cabs (x,y) == cabs (-x,y)",
5192 FUNC(cabs) (BUILD_COMPLEX(-12.4L, 0.7L)), a);
5193 check ("cabs (x,y) == cabs (-y,x)",
5194 FUNC(cabs) (BUILD_COMPLEX(-0.7L, 12.4L)), a);
5195 check ("cabs (x,y) == cabs (-x,-y)",
5196 FUNC(cabs) (BUILD_COMPLEX(-12.4L, -0.7L)), a);
5197 check ("cabs (x,y) == cabs (-y,-x)",
5198 FUNC(cabs) (BUILD_COMPLEX(-0.7L, -12.4L)), a);
5199 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-0.7L, 0)), 0.7L);
5200 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(0.7L, 0)), 0.7L);
5201 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-1.0L, 0)), 1.0L);
5202 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(1.0L, 0)), 1.0L);
5203 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(-5.7e7L, 0)),
5204 5.7e7L);
5205 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX(5.7e7L, 0)),
5206 5.7e7L);
5208 check_eps ("cabs (0.7 + i 1.2) == 1.38924...", FUNC(cabs) (BUILD_COMPLEX(0.7, 1.2)),
5209 1.3892443989449804508L, CHOOSE(7e-17L, 3e-16, 0));
5213 static void
5214 carg_test (void)
5216 /* carg (x + iy) is specified as atan2 (y, x) */
5217 MATHTYPE x;
5219 x = random_greater (0);
5220 check ("carg (x + i 0) == 0 for x > 0",
5221 FUNC(carg) (BUILD_COMPLEX(x, 0)), 0);
5222 x = random_greater (0);
5223 check ("carg (x - i 0) == -0 for x > 0",
5224 FUNC(carg) (BUILD_COMPLEX(x, minus_zero)), minus_zero);
5226 check ("carg (+0 + i 0) == +0", FUNC(carg) (BUILD_COMPLEX(0, 0)), 0);
5227 check ("carg (+0 - i 0) == -0", FUNC(carg) (BUILD_COMPLEX(0, minus_zero)),
5228 minus_zero);
5230 x = -random_greater (0);
5231 check ("carg (x + i 0) == +pi for x < 0", FUNC(carg) (BUILD_COMPLEX(x, 0)),
5232 M_PIl);
5234 x = -random_greater (0);
5235 check ("carg (x - i 0) == -pi for x < 0",
5236 FUNC(carg) (BUILD_COMPLEX(x, minus_zero)), -M_PIl);
5238 check ("carg (-0 + i 0) == +pi", FUNC(carg) (BUILD_COMPLEX(minus_zero, 0)),
5239 M_PIl);
5240 check ("carg (-0 - i 0) == -pi",
5241 FUNC(carg) (BUILD_COMPLEX(minus_zero, minus_zero)), -M_PIl);
5243 x = random_greater (0);
5244 check ("carg (+0 + i y) == pi/2 for y > 0", FUNC(carg) (BUILD_COMPLEX(0, x)),
5245 M_PI_2l);
5247 x = random_greater (0);
5248 check ("carg (-0 + i y) == pi/2 for y > 0",
5249 FUNC(carg) (BUILD_COMPLEX(minus_zero, x)), M_PI_2l);
5251 x = random_less (0);
5252 check ("carg (+0 + i y) == -pi/2 for y < 0", FUNC(carg) (BUILD_COMPLEX(0, x)),
5253 -M_PI_2l);
5255 x = random_less (0);
5256 check ("carg (-0 + i y) == -pi/2 for y < 0",
5257 FUNC(carg) (BUILD_COMPLEX(minus_zero, x)), -M_PI_2l);
5259 x = random_greater (0);
5260 check ("carg (inf + i y) == +0 for finite y > 0",
5261 FUNC(carg) (BUILD_COMPLEX(plus_infty, x)), 0);
5263 x = -random_greater (0);
5264 check ("carg (inf + i y) == -0 for finite y < 0",
5265 FUNC(carg) (BUILD_COMPLEX(plus_infty, x)), minus_zero);
5267 x = random_value (-1e4, 1e4);
5268 check ("carg(x + i inf) == pi/2 for finite x",
5269 FUNC(carg) (BUILD_COMPLEX(x, plus_infty)), M_PI_2l);
5271 x = random_value (-1e4, 1e4);
5272 check ("carg(x - i inf) == -pi/2 for finite x",
5273 FUNC(carg) (BUILD_COMPLEX(x, minus_infty)), -M_PI_2l);
5275 x = random_greater (0);
5276 check ("carg (-inf + i y) == +pi for finite y > 0",
5277 FUNC(carg) (BUILD_COMPLEX(minus_infty, x)), M_PIl);
5279 x = -random_greater (0);
5280 check ("carg (-inf + i y) == -pi for finite y < 0",
5281 FUNC(carg) (BUILD_COMPLEX(minus_infty, x)), -M_PIl);
5283 check ("carg (+inf + i inf) == +pi/4",
5284 FUNC(carg) (BUILD_COMPLEX(plus_infty, plus_infty)), M_PI_4l);
5286 check ("carg (+inf -i inf) == -pi/4",
5287 FUNC(carg) (BUILD_COMPLEX(plus_infty, minus_infty)), -M_PI_4l);
5289 check ("carg (-inf +i inf) == +3*pi/4",
5290 FUNC(carg) (BUILD_COMPLEX(minus_infty, plus_infty)), 3 * M_PI_4l);
5292 check ("carg (-inf -i inf) == -3*pi/4",
5293 FUNC(carg) (BUILD_COMPLEX(minus_infty, minus_infty)), -3 * M_PI_4l);
5298 static void
5299 nearbyint_test (void)
5301 check ("nearbyint(+0) = 0", FUNC(nearbyint) (0.0), 0.0);
5302 check ("nearbyint(-0) = -0", FUNC(nearbyint) (minus_zero), minus_zero);
5303 check_isinfp ("nearbyint(+Inf) = +Inf", FUNC(nearbyint) (plus_infty));
5304 check_isinfn ("nearbyint(-Inf) = -Inf", FUNC(nearbyint) (minus_infty));
5308 static void
5309 rint_test (void)
5311 check ("rint(0) = 0", FUNC(rint) (0.0), 0.0);
5312 check ("rint(-0) = -0", FUNC(rint) (minus_zero), minus_zero);
5313 check_isinfp ("rint(+Inf) = +Inf", FUNC(rint) (plus_infty));
5314 check_isinfn ("rint(-Inf) = -Inf", FUNC(rint) (minus_infty));
5318 static void
5319 lrint_test (void)
5321 /* XXX this test is incomplete. We need to have a way to specifiy
5322 the rounding method and test the critical cases. So far, only
5323 unproblematic numbers are tested. */
5325 check_long ("lrint(0) = 0", FUNC(lrint) (0.0), 0);
5326 check_long ("lrint(-0) = 0", FUNC(lrint) (minus_zero), 0);
5327 check_long ("lrint(0.2) = 0", FUNC(lrint) (0.2), 0);
5328 check_long ("lrint(-0.2) = 0", FUNC(lrint) (-0.2), 0);
5330 check_long ("lrint(1.4) = 1", FUNC(lrint) (1.4), 1);
5331 check_long ("lrint(-1.4) = -1", FUNC(lrint) (-1.4), -1);
5333 check_long ("lrint(8388600.3) = 8388600", FUNC(lrint) (8388600.3), 8388600);
5334 check_long ("lrint(-8388600.3) = -8388600", FUNC(lrint) (-8388600.3),
5335 -8388600);
5339 static void
5340 llrint_test (void)
5342 /* XXX this test is incomplete. We need to have a way to specifiy
5343 the rounding method and test the critical cases. So far, only
5344 unproblematic numbers are tested. */
5346 check_longlong ("llrint(0) = 0", FUNC(llrint) (0.0), 0);
5347 check_longlong ("llrint(-0) = 0", FUNC(llrint) (minus_zero), 0);
5348 check_longlong ("llrint(0.2) = 0", FUNC(llrint) (0.2), 0);
5349 check_longlong ("llrint(-0.2) = 0", FUNC(llrint) (-0.2), 0);
5351 check_longlong ("llrint(1.4) = 1", FUNC(llrint) (1.4), 1);
5352 check_longlong ("llrint(-1.4) = -1", FUNC(llrint) (-1.4), -1);
5354 check_longlong ("llrint(8388600.3) = 8388600", FUNC(llrint) (8388600.3),
5355 8388600);
5356 check_longlong ("llrint(-8388600.3) = -8388600", FUNC(llrint) (-8388600.3),
5357 -8388600);
5359 /* Test boundary conditions. */
5360 /* 0x1FFFFF */
5361 check_longlong ("llrint(2097151.0) = 2097151", FUNC(llrint) (2097151.0),
5362 2097151LL);
5363 /* 0x800000 */
5364 check_longlong ("llrint(8388608.0) = 8388608", FUNC(llrint) (8388608.0),
5365 8388608LL);
5366 /* 0x1000000 */
5367 check_longlong ("llrint(16777216.0) = 16777216",
5368 FUNC(llrint) (16777216.0), 16777216LL);
5369 /* 0x20000000000 */
5370 check_longlong ("llrint(2199023255552.0) = 2199023255552",
5371 FUNC(llrint) (2199023255552.0), 2199023255552LL);
5372 /* 0x40000000000 */
5373 check_longlong ("llrint(4398046511104.0) = 4398046511104",
5374 FUNC(llrint) (4398046511104.0), 4398046511104LL);
5375 /* 0x10000000000000 */
5376 check_longlong ("llrint(4503599627370496.0) = 4503599627370496",
5377 FUNC(llrint) (4503599627370496.0), 4503599627370496LL);
5378 /* 0x10000080000000 */
5379 check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5380 FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5381 /* 0x20000000000000 */
5382 check_longlong ("llrint(9007199254740992.0) = 9007199254740992",
5383 FUNC(llrint) (9007199254740992.0), 9007199254740992LL);
5384 /* 0x80000000000000 */
5385 check_longlong ("llrint(36028797018963968.0) = 36028797018963968",
5386 FUNC(llrint) (36028797018963968.0), 36028797018963968LL);
5387 /* 0x100000000000000 */
5388 check_longlong ("llrint(72057594037927936.0) = 72057594037927936",
5389 FUNC(llrint) (72057594037927936.0), 72057594037927936LL);
5393 static void
5394 round_test (void)
5396 check ("round(0) = 0", FUNC(round) (0), 0);
5397 check ("round(-0) = -0", FUNC(round) (minus_zero), minus_zero);
5398 check ("round(0.2) = 0", FUNC(round) (0.2), 0.0);
5399 check ("round(-0.2) = -0", FUNC(round) (-0.2), minus_zero);
5400 check ("round(0.5) = 1", FUNC(round) (0.5), 1.0);
5401 check ("round(-0.5) = -1", FUNC(round) (-0.5), -1.0);
5402 check ("round(0.8) = 1", FUNC(round) (0.8), 1.0);
5403 check ("round(-0.8) = -1", FUNC(round) (-0.8), -1.0);
5404 check ("round(1.5) = 2", FUNC(round) (1.5), 2.0);
5405 check ("round(-1.5) = -2", FUNC(round) (-1.5), -2.0);
5406 check ("round(2097152.5) = 2097153", FUNC(round) (2097152.5), 2097153);
5407 check ("round(-2097152.5) = -2097153", FUNC(round) (-2097152.5), -2097153);
5411 static void
5412 lround_test (void)
5414 check_long ("lround(0) = 0", FUNC(lround) (0), 0);
5415 check_long ("lround(-0) = 0", FUNC(lround) (minus_zero), 0);
5416 check_long ("lround(0.2) = 0", FUNC(lround) (0.2), 0.0);
5417 check_long ("lround(-0.2) = 0", FUNC(lround) (-0.2), 0);
5418 check_long ("lround(0.5) = 1", FUNC(lround) (0.5), 1);
5419 check_long ("lround(-0.5) = -1", FUNC(lround) (-0.5), -1);
5420 check_long ("lround(0.8) = 1", FUNC(lround) (0.8), 1);
5421 check_long ("lround(-0.8) = -1", FUNC(lround) (-0.8), -1);
5422 check_long ("lround(1.5) = 2", FUNC(lround) (1.5), 2);
5423 check_long ("lround(-1.5) = -2", FUNC(lround) (-1.5), -2);
5424 check_long ("lround(22514.5) = 22515", FUNC(lround) (22514.5), 22515);
5425 check_long ("lround(-22514.5) = -22515", FUNC(lround) (-22514.5), -22515);
5426 #ifndef TEST_FLOAT
5427 check_long ("lround(2097152.5) = 2097153", FUNC(lround) (2097152.5),
5428 2097153);
5429 check_long ("lround(-2097152.5) = -2097153", FUNC(lround) (-2097152.5),
5430 -2097153);
5431 #endif
5435 static void
5436 llround_test (void)
5438 check_longlong ("llround(0) = 0", FUNC(llround) (0), 0);
5439 check_longlong ("llround(-0) = 0", FUNC(llround) (minus_zero), 0);
5440 check_longlong ("llround(0.2) = 0", FUNC(llround) (0.2), 0.0);
5441 check_longlong ("llround(-0.2) = 0", FUNC(llround) (-0.2), 0);
5442 check_longlong ("llround(0.5) = 1", FUNC(llround) (0.5), 1);
5443 check_longlong ("llround(-0.5) = -1", FUNC(llround) (-0.5), -1);
5444 check_longlong ("llround(0.8) = 1", FUNC(llround) (0.8), 1);
5445 check_longlong ("llround(-0.8) = -1", FUNC(llround) (-0.8), -1);
5446 check_longlong ("llround(1.5) = 2", FUNC(llround) (1.5), 2);
5447 check_longlong ("llround(-1.5) = -2", FUNC(llround) (-1.5), -2);
5448 check_longlong ("llround(22514.5) = 22515", FUNC(llround) (22514.5), 22515);
5449 check_longlong ("llround(-22514.5) = -22515", FUNC(llround) (-22514.5),
5450 -22515);
5451 #ifndef TEST_FLOAT
5452 check_longlong ("llround(2097152.5) = 2097153",
5453 FUNC(llround) (2097152.5), 2097153);
5454 check_longlong ("llround(-2097152.5) = -2097153",
5455 FUNC(llround) (-2097152.5), -2097153);
5456 check_longlong ("llround(34359738368.5) = 34359738369",
5457 FUNC(llround) (34359738368.5), 34359738369ll);
5458 check_longlong ("llround(-34359738368.5) = -34359738369",
5459 FUNC(llround) (-34359738368.5), -34359738369ll);
5460 #endif
5462 /* Test boundary conditions. */
5463 /* 0x1FFFFF */
5464 check_longlong ("llround(2097151.0) = 2097151", FUNC(llround) (2097151.0),
5465 2097151LL);
5466 /* 0x800000 */
5467 check_longlong ("llround(8388608.0) = 8388608", FUNC(llround) (8388608.0),
5468 8388608LL);
5469 /* 0x1000000 */
5470 check_longlong ("llround(16777216.0) = 16777216",
5471 FUNC(llround) (16777216.0), 16777216LL);
5472 /* 0x20000000000 */
5473 check_longlong ("llround(2199023255552.0) = 2199023255552",
5474 FUNC(llround) (2199023255552.0), 2199023255552LL);
5475 /* 0x40000000000 */
5476 check_longlong ("llround(4398046511104.0) = 4398046511104",
5477 FUNC(llround) (4398046511104.0), 4398046511104LL);
5478 /* 0x10000000000000 */
5479 check_longlong ("llround(4503599627370496.0) = 4503599627370496",
5480 FUNC(llround) (4503599627370496.0), 4503599627370496LL);
5481 /* 0x10000080000000 */
5482 check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5483 FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5484 /* 0x20000000000000 */
5485 check_longlong ("llround(9007199254740992.0) = 9007199254740992",
5486 FUNC(llround) (9007199254740992.0), 9007199254740992LL);
5487 /* 0x80000000000000 */
5488 check_longlong ("llround(36028797018963968.0) = 36028797018963968",
5489 FUNC(llround) (36028797018963968.0), 36028797018963968LL);
5490 /* 0x100000000000000 */
5491 check_longlong ("llround(72057594037927936.0) = 72057594037927936",
5492 FUNC(llround) (72057594037927936.0), 72057594037927936LL);
5496 static void
5497 fma_test (void)
5499 check ("fma(1.0, 2.0, 3.0) = 5.0", FUNC(fma) (1.0, 2.0, 3.0), 5.0);
5500 check_isnan ("fma(NaN, 2.0, 3.0) = NaN", FUNC(fma) (nan_value, 2.0, 3.0));
5501 check_isnan ("fma(1.0, NaN, 3.0) = NaN", FUNC(fma) (1.0, nan_value, 3.0));
5502 check_isnan_maybe_exc ("fma(1.0, 2.0, NaN) = NaN",
5503 FUNC(fma) (1.0, 2.0, nan_value), INVALID_EXCEPTION);
5504 check_isnan_maybe_exc ("fma(+Inf, 0.0, NaN) = NaN",
5505 FUNC(fma) (plus_infty, 0.0, nan_value),
5506 INVALID_EXCEPTION);
5507 check_isnan_maybe_exc ("fma(-Inf, 0.0, NaN) = NaN",
5508 FUNC(fma) (minus_infty, 0.0, nan_value),
5509 INVALID_EXCEPTION);
5510 check_isnan_maybe_exc ("fma(0.0, +Inf, NaN) = NaN",
5511 FUNC(fma) (0.0, plus_infty, nan_value),
5512 INVALID_EXCEPTION);
5513 check_isnan_maybe_exc ("fma(0.0, -Inf, NaN) = NaN",
5514 FUNC(fma) (0.0, minus_infty, nan_value),
5515 INVALID_EXCEPTION);
5516 check_isnan_exc ("fma(+Inf, 0.0, 1.0) = NaN",
5517 FUNC(fma) (plus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5518 check_isnan_exc ("fma(-Inf, 0.0, 1.0) = NaN",
5519 FUNC(fma) (minus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5520 check_isnan_exc ("fma(0.0, +Inf, 1.0) = NaN",
5521 FUNC(fma) (0.0, plus_infty, 1.0), INVALID_EXCEPTION);
5522 check_isnan_exc ("fma(0.0, -Inf, 1.0) = NaN",
5523 FUNC(fma) (0.0, minus_infty, 1.0), INVALID_EXCEPTION);
5525 check_isnan_exc ("fma(+Inf, +Inf, -Inf) = NaN",
5526 FUNC(fma) (plus_infty, plus_infty, minus_infty),
5527 INVALID_EXCEPTION);
5528 check_isnan_exc ("fma(-Inf, +Inf, +Inf) = NaN",
5529 FUNC(fma) (minus_infty, plus_infty, plus_infty),
5530 INVALID_EXCEPTION);
5531 check_isnan_exc ("fma(+Inf, -Inf, +Inf) = NaN",
5532 FUNC(fma) (plus_infty, minus_infty, plus_infty),
5533 INVALID_EXCEPTION);
5534 check_isnan_exc ("fma(-Inf, -Inf, -Inf) = NaN",
5535 FUNC(fma) (minus_infty, minus_infty, minus_infty),
5536 INVALID_EXCEPTION);
5541 Tests for the comparison macros
5543 typedef enum {is_less, is_equal, is_greater, is_unordered} comp_result;
5546 static void
5547 comparison2_test (MATHTYPE x, MATHTYPE y, comp_result comp)
5549 char buf[255];
5550 int result;
5551 int expected;
5553 expected = (comp == is_greater);
5554 sprintf (buf, "isgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5555 expected);
5556 result = (isgreater (x, y) == expected);
5557 check_bool (buf, result);
5559 expected = (comp == is_greater || comp == is_equal);
5560 sprintf (buf, "isgreaterequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5561 expected);
5562 result = (isgreaterequal (x, y) == expected);
5563 check_bool (buf, result);
5565 expected = (comp == is_less);
5566 sprintf (buf, "isless (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5567 expected);
5568 result = (isless (x, y) == expected);
5569 check_bool (buf, result);
5571 expected = (comp == is_less || comp == is_equal);
5572 sprintf (buf, "islessequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5573 expected);
5574 result = (islessequal (x, y) == expected);
5575 check_bool (buf, result);
5577 expected = (comp == is_greater || comp == is_less);
5578 sprintf (buf, "islessgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5579 expected);
5580 result = (islessgreater (x, y) == expected);
5581 check_bool (buf, result);
5583 expected = (comp == is_unordered);
5584 sprintf (buf, "isunordered (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5585 expected);
5586 result = (isunordered (x, y) == expected);
5587 check_bool (buf, result);
5592 static void
5593 comparison1_test (MATHTYPE x, MATHTYPE y, comp_result comp)
5595 comp_result comp_swap;
5596 switch (comp)
5598 case is_less:
5599 comp_swap = is_greater;
5600 break;
5601 case is_greater:
5602 comp_swap = is_less;
5603 break;
5604 default:
5605 comp_swap = comp;
5606 break;
5608 comparison2_test (x, y, comp);
5609 comparison2_test (y, x, comp_swap);
5613 static void
5614 comparisons_test (void)
5616 comparison1_test (1, 2, is_less);
5617 comparison1_test (-30, 30, is_less);
5618 comparison1_test (42, 42, is_equal);
5619 comparison1_test (1, plus_infty, is_less);
5620 comparison1_test (35, minus_infty, is_greater);
5621 comparison1_test (1, nan_value, is_unordered);
5622 comparison1_test (nan_value, nan_value, is_unordered);
5623 comparison1_test (plus_infty, nan_value, is_unordered);
5624 comparison1_test (minus_infty, nan_value, is_unordered);
5625 comparison1_test (plus_infty, minus_infty, is_greater);
5629 static void
5630 inverse_func_pair_test (const char *test_name,
5631 mathfunc f1, mathfunc inverse,
5632 MATHTYPE x, MATHTYPE epsilon)
5634 MATHTYPE a, b, difference;
5635 int result;
5637 a = f1 (x);
5638 (void) &a;
5639 b = inverse (a);
5640 (void) &b;
5642 output_new_test (test_name);
5643 result = check_equal (b, x, epsilon, &difference);
5644 output_result (test_name, result,
5645 b, x, difference, PRINT, PRINT);
5649 static void
5650 inverse_functions (void)
5652 inverse_func_pair_test ("asin(sin(x)) == x",
5653 FUNC(sin), FUNC(asin), 1.0,
5654 CHOOSE (2e-18L, 0, 3e-7L));
5655 inverse_func_pair_test ("sin(asin(x)) == x",
5656 FUNC(asin), FUNC(sin), 1.0, 0.0);
5658 inverse_func_pair_test ("acos(cos(x)) == x",
5659 FUNC(cos), FUNC(acos), 1.0,
5660 CHOOSE (4e-18L, 1e-15L, 0));
5661 inverse_func_pair_test ("cos(acos(x)) == x",
5662 FUNC(acos), FUNC(cos), 1.0, 0.0);
5663 inverse_func_pair_test ("atan(tan(x)) == x",
5664 FUNC(tan), FUNC(atan), 1.0, CHOOSE (2e-18L, 0, 0));
5665 inverse_func_pair_test ("tan(atan(x)) == x",
5666 FUNC(atan), FUNC(tan), 1.0,
5667 CHOOSE (2e-18L, 1e-15L, 2e-7));
5669 inverse_func_pair_test ("asinh(sinh(x)) == x",
5670 FUNC(sinh), FUNC(asinh), 1.0, CHOOSE (1e-18L, 0, 1e-7));
5671 inverse_func_pair_test ("sinh(asinh(x)) == x",
5672 FUNC(asinh), FUNC(sinh), 1.0,
5673 CHOOSE (2e-18L, 2e-16L, 2e-7));
5675 inverse_func_pair_test ("acosh(cosh(x)) == x",
5676 FUNC(cosh), FUNC(acosh), 1.0,
5677 CHOOSE (1e-18L, 1e-15L, 6e-8));
5678 inverse_func_pair_test ("cosh(acosh(x)) == x",
5679 FUNC(acosh), FUNC(cosh), 1.0, 0.0);
5681 inverse_func_pair_test ("atanh(tanh(x)) == x",
5682 FUNC(tanh), FUNC(atanh), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
5683 inverse_func_pair_test ("tanh(atanh(x)) == x",
5684 FUNC(atanh), FUNC(tanh), 1.0, 0.0);
5688 /* Test sin and cos with the identity: sin(x)^2 + cos(x)^2 = 1. */
5689 static void
5690 identities1_test (MATHTYPE x, MATHTYPE epsilon)
5692 MATHTYPE res1, res2, res3, diff;
5693 int result;
5695 res1 = FUNC(sin) (x);
5696 (void) &res1;
5697 res2 = FUNC(cos) (x);
5698 (void) &res2;
5699 res3 = res1 * res1 + res2 * res2;
5700 (void) &res3;
5702 output_new_test ("sin^2 + cos^2 == 1");
5703 result = check_equal (res3, 1.0, epsilon, &diff);
5704 output_result_ext ("sin^2 + cos^2 == 1", result,
5705 res3, 1.0, diff, x, PRINT, PRINT);
5709 /* Test sin, cos, tan with the following relation: tan = sin/cos. */
5710 static void
5711 identities2_test (MATHTYPE x, MATHTYPE epsilon)
5713 #ifndef TEST_INLINE
5714 MATHTYPE res1, res2, res3, res4, diff;
5715 int result;
5717 res1 = FUNC(sin) (x);
5718 (void) &res1;
5719 res2 = FUNC(cos) (x);
5720 (void) &res2;
5721 res3 = FUNC(tan) (x);
5722 (void) &res3;
5723 res4 = res1 / res2;
5724 (void) &res4;
5726 output_new_test ("sin/cos == tan");
5727 result = check_equal (res4, res3, epsilon, &diff);
5728 output_result_ext ("sin/cos == tan", result,
5729 res4, res3, diff, x, PRINT, PRINT);
5730 #endif
5734 /* Test cosh and sinh with the identity cosh^2 - sinh^2 = 1. */
5735 static void
5736 identities3_test (MATHTYPE x, MATHTYPE epsilon)
5738 MATHTYPE res1, res2, res3, diff;
5739 int result;
5741 res1 = FUNC(sinh) (x);
5742 (void) &res1;
5743 res2 = FUNC(cosh) (x);
5744 (void) &res2;
5745 res3 = res2 * res2 - res1 * res1;
5746 (void) &res3;
5748 output_new_test ("cosh^2 - sinh^2 == 1");
5749 result = check_equal (res3, 1.0, epsilon, &diff);
5750 output_result_ext ("cosh^2 - sinh^2 == 1", result,
5751 res3, 1.0, diff, x, PRINT, PRINT);
5755 static void
5756 identities (void)
5758 identities1_test (0.2L, CHOOSE (1e-18L, 0, 2e-7));
5759 identities1_test (0.9L, CHOOSE (1e-18L, 0, 1e-7));
5760 identities1_test (0, 0);
5761 identities1_test (-1, CHOOSE (1e-18L, 0, 1e-7));
5763 identities2_test (0.2L, CHOOSE (1e-19L, 1e-16, 0));
5764 identities2_test (0.9L, CHOOSE (3e-19L, 1e-15, 2e-7));
5765 identities2_test (0, 0);
5766 identities2_test (-1, CHOOSE (1e-18L, 1e-15, 2e-7));
5768 identities3_test (0.2L, CHOOSE (1e-18L, 0, 1e-7));
5769 identities3_test (0.9L, CHOOSE (1e-18L, 1e-15, 1e-6));
5770 identities3_test (0, CHOOSE (0, 0, 1e-6));
5771 identities3_test (-1, CHOOSE (1e-18L, 7e-16, 1e-6));
5776 Let's test that basic arithmetic is working
5777 tests: Infinity and NaN
5779 static void
5780 basic_tests (void)
5782 /* variables are declared volatile to forbid some compiler
5783 optimizations */
5784 volatile MATHTYPE Inf_var, NaN_var, zero_var, one_var;
5785 MATHTYPE x1, x2;
5787 zero_var = 0.0;
5788 one_var = 1.0;
5789 NaN_var = nan_value;
5790 Inf_var = one_var / zero_var;
5792 (void) &zero_var;
5793 (void) &one_var;
5794 (void) &NaN_var;
5795 (void) &Inf_var;
5797 /* Clear all exceptions. The previous computations raised exceptions. */
5798 feclearexcept (FE_ALL_EXCEPT);
5800 check_isinfp ("isinf (inf) == +1", Inf_var);
5801 check_isinfn ("isinf (-inf) == -1", -Inf_var);
5802 check_bool ("!isinf (1)", !(FUNC(isinf) (one_var)));
5803 check_bool ("!isinf (NaN)", !(FUNC(isinf) (NaN_var)));
5805 check_isnan ("isnan (NaN)", NaN_var);
5806 check_isnan ("isnan (-NaN)", -NaN_var);
5807 check_bool ("!isnan (1)", !(FUNC(isnan) (one_var)));
5808 check_bool ("!isnan (inf)", !(FUNC(isnan) (Inf_var)));
5810 check_bool ("inf == inf", Inf_var == Inf_var);
5811 check_bool ("-inf == -inf", -Inf_var == -Inf_var);
5812 check_bool ("inf != -inf", Inf_var != -Inf_var);
5813 check_bool ("NaN != NaN", NaN_var != NaN_var);
5816 the same tests but this time with NAN from <bits/nan.h>
5817 NAN is a double const
5819 check_bool ("isnan (NAN)", isnan (NAN));
5820 check_bool ("isnan (-NAN)", isnan (-NAN));
5821 check_bool ("!isinf (NAN)", !(isinf (NAN)));
5822 check_bool ("!isinf (-NAN)", !(isinf (-NAN)));
5823 check_bool ("NAN != NAN", NAN != NAN);
5826 And again with the value returned by the `nan' function.
5828 check_bool ("isnan (NAN)", FUNC(isnan) (FUNC(nan) ("")));
5829 check_bool ("isnan (-NAN)", FUNC(isnan) (-FUNC(nan) ("")));
5830 check_bool ("!isinf (NAN)", !(FUNC(isinf) (FUNC(nan) (""))));
5831 check_bool ("!isinf (-NAN)", !(FUNC(isinf) (-FUNC(nan) (""))));
5832 check_bool ("NAN != NAN", FUNC(nan) ("") != FUNC(nan) (""));
5834 /* test if EPSILON is ok */
5835 x1 = MATHCONST (1.0);
5836 x2 = x1 + CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
5837 check_bool ("1 != 1+EPSILON", x1 != x2);
5839 x1 = MATHCONST (1.0);
5840 x2 = x1 - CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
5841 check_bool ("1 != 1-EPSILON", x1 != x2);
5843 /* test if HUGE_VALx is ok */
5844 x1 = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5845 check_bool ("isinf (HUGE_VALx) == +1", ISINF (x1) == +1);
5846 x1 = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5847 check_bool ("isinf (-HUGE_VALx) == -1", ISINF (x1) == -1);
5852 static void
5853 initialize (void)
5855 fpstack_test ("start *init*");
5856 plus_zero = 0.0;
5857 nan_value = plus_zero / plus_zero; /* Suppress GCC warning */
5859 minus_zero = FUNC (copysign) (0.0, -1.0);
5860 plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5861 minus_infty = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
5863 (void) &plus_zero;
5864 (void) &nan_value;
5865 (void) &minus_zero;
5866 (void) &plus_infty;
5867 (void) &minus_infty;
5869 /* Clear all exceptions. From now on we must not get random exceptions. */
5870 feclearexcept (FE_ALL_EXCEPT);
5872 /* Test to make sure we start correctly. */
5873 fpstack_test ("end *init*");
5877 static struct option long_options[] =
5879 {"verbose", optional_argument, NULL, 'v'},
5880 {"silent", no_argument, NULL, 's'},
5881 {0, 0, 0, 0}
5885 static void
5886 parse_options (int argc, char *argv[])
5888 int c;
5889 int option_index;
5891 verbose = 1;
5893 while (1)
5895 c = getopt_long (argc, argv, "v::s",
5896 long_options, &option_index);
5898 /* Detect the end of the options. */
5899 if (c == -1)
5900 break;
5902 switch (c)
5904 case 'v':
5905 if (optarg)
5906 verbose = (unsigned int) strtoul (optarg, NULL, 0);
5907 else
5908 verbose = 4;
5909 break;
5910 case 's':
5911 verbose = 0;
5912 default:
5913 break;
5920 main (int argc, char *argv[])
5923 parse_options (argc, argv);
5925 initialize ();
5926 printf (TEST_MSG);
5928 basic_tests ();
5930 /* keep the tests a wee bit ordered (according to ISO 9X) */
5931 /* classification functions */
5932 fpclassify_test ();
5933 isfinite_test ();
5934 isnormal_test ();
5935 signbit_test ();
5937 comparisons_test ();
5939 /* trigonometric functions */
5940 acos_test ();
5941 asin_test ();
5942 atan_test ();
5943 atan2_test ();
5944 cos_test ();
5945 sin_test ();
5946 sincos_test ();
5947 tan_test ();
5949 /* hyperbolic functions */
5950 acosh_test ();
5951 asinh_test ();
5952 atanh_test ();
5953 cosh_test ();
5954 sinh_test ();
5955 tanh_test ();
5957 /* exponential and logarithmic functions */
5958 exp_test ();
5959 exp2_test ();
5960 expm1_test ();
5961 frexp_test ();
5962 ldexp_test ();
5963 log_test ();
5964 log10_test ();
5965 log1p_test ();
5966 log2_test ();
5967 logb_test ();
5968 modf_test ();
5969 ilogb_test ();
5970 scalb_test ();
5971 scalbn_test ();
5973 /* power and absolute value functions */
5974 cbrt_test ();
5975 fabs_test ();
5976 hypot_test ();
5977 pow_test ();
5978 sqrt_test ();
5980 /* error and gamma functions */
5981 erf_test ();
5982 erfc_test ();
5983 gamma_test ();
5984 lgamma_test ();
5986 /* nearest integer functions */
5987 ceil_test ();
5988 floor_test ();
5989 nearbyint_test ();
5990 rint_test ();
5991 lrint_test ();
5992 llrint_test ();
5993 round_test ();
5994 lround_test ();
5995 llround_test ();
5996 trunc_test ();
5998 /* remainder functions */
5999 fmod_test ();
6000 remainder_test ();
6001 remquo_test ();
6003 /* manipulation functions */
6004 copysign_test ();
6005 nextafter_test ();
6007 /* maximum, minimum and positive difference functions */
6008 fdim_test ();
6009 fmin_test ();
6010 fmax_test ();
6012 /* complex functions */
6013 cabs_test ();
6014 carg_test ();
6015 cexp_test ();
6016 csin_test ();
6017 csinh_test ();
6018 ccos_test ();
6019 ccosh_test ();
6020 clog_test ();
6021 clog10_test ();
6022 cacos_test ();
6023 cacosh_test ();
6024 casin_test ();
6025 casinh_test ();
6026 catan_test ();
6027 catanh_test ();
6028 ctan_test ();
6029 ctanh_test ();
6030 csqrt_test ();
6031 cpow_test ();
6033 /* multiply and add */
6034 fma_test ();
6036 /* special tests */
6037 identities ();
6038 inverse_functions ();
6040 printf ("\nTest suite completed:\n");
6041 printf (" %d test cases plus %d tests for exception flags executed.\n",
6042 noTests, noExcTests);
6043 if (noErrors)
6045 printf (" %d errors occured.\n", noErrors);
6046 exit (1);
6048 printf (" All tests passed successfully.\n");
6049 exit (0);