Update.
[glibc.git] / math / libm-test.c
blob4c7fe8b7ae39da81bf6b096571a1103511fe0f33
1 /* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* Part of testsuite for libm.
22 This file has to be included by a master file that defines:
24 Makros:
25 FUNC(function): converts general function name (like cos) to
26 name with correct suffix (e.g. cosl or cosf)
27 MATHCONST(x): like FUNC but for constants (e.g convert 0.0 to 0.0L)
28 MATHTYPE: floating point type to test
29 TEST_MSG: informal message to be displayed
30 CHOOSE(Clongdouble,Cdouble,Cfloat):
31 chooses one of the parameters as epsilon for testing
32 equality
33 PRINTF_EXPR Floating point conversion specification to print a variable
34 of type MATHTYPE with printf. PRINTF_EXPR just contains
35 the specifier, not the percent and width arguments,
36 e.g. "f".
37 PRINTF_XEXPR Like PRINTF_EXPR, but print in hexadecimal format.
40 /* This program isn't finished yet.
41 It has tests for:
42 acos, acosh, asin, asinh, atan, atan2, atanh,
43 cbrt, ceil, copysign, cos, cosh, erf, erfc, exp, exp10, exp2, expm1,
44 fabs, fdim, floor, fma, fmax, fmin, fmod, fpclassify,
45 frexp, gamma, hypot,
46 ilogb, isfinite, isinf, isnan, isnormal,
47 isless, islessequal, isgreater, isgreaterequal, islessgreater, isunordered,
48 j0, j1, jn,
49 ldexp, lgamma, log, log10, log1p, log2, logb,
50 modf, nearbyint, nextafter,
51 pow, remainder, remquo, rint, lrint, llrint,
52 round, lround, llround,
53 scalb, scalbn, signbit, sin, sincos, sinh, sqrt, tan, tanh, tgamma, trunc,
54 y0, y1, yn
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 significand,
63 nan
65 The routines using random variables are still under construction. I don't
66 like it the way it's working now and will change it.
68 Parameter handling is primitive in the moment:
69 --verbose=[0..4] for different levels of output:
70 0: only error count
71 1: basic report on failed tests (default)
72 2: full report on failed tests
73 3: full report on failed and passed tests
74 4: additional report on exceptions
75 -v for full output (equals --verbose=4)
76 -s,--silent outputs only the error count (equals --verbose=0)
79 /* "Philosophy":
81 This suite tests some aspects of the correct implementation of
82 mathematical functions in libm. Some simple, specific parameters
83 are tested for correctness but there's no exhaustive
84 testing. Handling of specific inputs (e.g. infinity, not-a-number)
85 is also tested. Correct handling of exceptions is checked
86 against. These implemented tests should check all cases that are
87 specified in ISO C 9X.
89 Exception testing: At the moment only divide-by-zero and invalid
90 exceptions are tested. Overflow/underflow and inexact exceptions
91 aren't checked at the moment.
93 NaN values: There exist signalling and quiet NaNs. This implementation
94 only uses signalling NaN as parameter but does not differenciate
95 between the two kinds of NaNs as result.
97 Inline functions: Inlining functions should give an improvement in
98 speed - but not in precission. The inlined functions return
99 reasonable values for a reasonable range of input values. The
100 result is not necessarily correct for all values and exceptions are
101 not correctly raised in all cases. Problematic input and return
102 values are infinity, not-a-number and minus zero. This suite
103 therefore does not check these specific inputs and the exception
104 handling for inlined mathematical functions - just the "reasonable"
105 values are checked.
107 Beware: The tests might fail for any of the following reasons:
108 - Tests are wrong
109 - Functions are wrong
110 - Floating Point Unit not working properly
111 - Compiler has errors
113 With e.g. gcc 2.7.2.2 the test for cexp fails because of a compiler error.
116 #ifndef _GNU_SOURCE
117 # define _GNU_SOURCE
118 #endif
120 #include <complex.h>
121 #include <math.h>
122 #include <float.h>
123 #include <fenv.h>
125 #include <errno.h>
126 #include <stdlib.h>
127 #include <stdio.h>
128 #include <getopt.h>
130 /* Possible exceptions */
131 #define NO_EXCEPTION 0x0
132 #define INVALID_EXCEPTION 0x1
133 #define DIVIDE_BY_ZERO_EXCEPTION 0x2
135 #define PRINT 1
136 #define NO_PRINT 0
138 /* Various constants (we must supply them precalculated for accuracy). */
139 #define M_PI_6l .52359877559829887308L
140 #define M_E2l 7.389056098930650227230L
141 #define M_E3l 20.08553692318766774093L
143 static int noErrors; /* number of errors */
144 static int noTests; /* number of tests (without testing exceptions) */
145 static int noExcTests; /* number of tests for exception flags */
147 static int verbose = 3;
148 static MATHTYPE minus_zero, plus_zero;
149 static MATHTYPE plus_infty, minus_infty, nan_value;
151 typedef MATHTYPE (*mathfunc) (MATHTYPE);
153 #define BUILD_COMPLEX(real, imag) \
154 ({ __complex__ MATHTYPE __retval; \
155 __real__ __retval = (real); \
156 __imag__ __retval = (imag); \
157 __retval; })
159 /* Test if Floating-Point stack hasn't changed */
160 static void
161 fpstack_test (const char *test_name)
163 #ifdef i386
164 static int old_stack;
165 int sw;
167 asm ("fnstsw" : "=a" (sw));
168 sw >>= 11;
169 sw &= 7;
171 if (sw != old_stack)
173 printf ("FP-Stack wrong after test %s (%d, should be %d)\n",
174 test_name, sw, old_stack);
175 ++noErrors;
176 old_stack = sw;
178 #endif
182 /* Get a random value x with min_value < x < max_value
183 and min_value, max_value finite,
184 max_value and min_value shouldn't be too close together */
185 static MATHTYPE
186 random_value (MATHTYPE min_value, MATHTYPE max_value)
188 int r;
189 MATHTYPE x;
191 r = rand ();
193 x = (max_value - min_value) / RAND_MAX * (MATHTYPE) r + min_value;
195 if ((x <= min_value) || (x >= max_value) || !isfinite (x))
196 x = (max_value - min_value) / 2 + min_value;
198 /* Make sure the RNG has no influence on the exceptions. */
199 feclearexcept (FE_ALL_EXCEPT);
201 return x;
205 /* Get a random value x with x > min_value. */
206 static MATHTYPE
207 random_greater (MATHTYPE min_value)
209 return random_value (min_value, 1e6); /* CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX) */
213 /* Get a random value x with x < max_value. */
214 static MATHTYPE
215 random_less (MATHTYPE max_value)
217 return random_value (-1e6, max_value);
221 static void
222 output_new_test (const char *test_name)
224 if (verbose > 2)
225 printf ("\nTesting: %s\n", test_name);
229 static void
230 output_pass_value (void)
232 if (verbose > 2)
233 printf ("Pass: Value Ok.\n");
237 static void
238 output_fail_value (const char *test_name)
240 if (verbose > 0 && verbose < 3)
241 printf ("Fail: %s\n", test_name);
242 if (verbose >= 3)
243 printf ("Fail:\n");
247 /* Test whether a given exception was raised. */
248 static void
249 test_single_exception (const char *test_name,
250 short int exception,
251 short int exc_flag,
252 int fe_flag,
253 const char *flag_name)
255 #ifndef TEST_INLINE
256 if (exception & exc_flag)
258 if (fetestexcept (fe_flag))
260 if (verbose > 3)
261 printf ("Pass: Exception \"%s\" set\n", flag_name);
263 else
265 if (verbose && verbose < 3)
266 printf ("Fail: %s: Exception \"%s\" not set\n",
267 test_name, flag_name);
268 if (verbose >= 3)
269 printf ("Fail: Exception \"%s\" not set\n",
270 flag_name);
271 ++noErrors;
274 else
276 if (fetestexcept (fe_flag))
278 if (verbose && verbose < 3)
279 printf ("Fail: %s: Exception \"%s\" set\n",
280 test_name, flag_name);
281 if (verbose >= 3)
282 printf ("Fail: Exception \"%s\" set\n",
283 flag_name);
284 ++noErrors;
286 else
288 if (verbose > 3)
289 printf ("Pass: Exception \"%s\" not set\n",
290 flag_name);
293 #endif
297 /* Test whether exception given by EXCEPTION are raised. */
298 static void
299 test_not_exception (const char *test_name, short int exception)
301 ++noExcTests;
302 #ifdef FE_DIVBYZERO
303 if ((exception & DIVIDE_BY_ZERO_EXCEPTION) == 0)
304 test_single_exception (test_name, exception,
305 DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
306 "Divide by zero");
307 #endif
308 #ifdef FE_INVALID
309 if ((exception & INVALID_EXCEPTION) == 0)
310 test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
311 "Invalid operation");
312 #endif
313 feclearexcept (FE_ALL_EXCEPT);
317 /* Test whether exceptions given by EXCEPTION are raised. */
318 static void
319 test_exceptions (const char *test_name, short int exception)
321 ++noExcTests;
322 #ifdef FE_DIVBYZERO
323 test_single_exception (test_name, exception,
324 DIVIDE_BY_ZERO_EXCEPTION, FE_DIVBYZERO,
325 "Divide by zero");
326 #endif
327 #ifdef FE_INVALID
328 test_single_exception (test_name, exception, INVALID_EXCEPTION, FE_INVALID,
329 "Invalid operation");
330 #endif
331 feclearexcept (FE_ALL_EXCEPT);
335 /* Test if two floating point numbers are equal. */
336 static int
337 check_equal (MATHTYPE computed, MATHTYPE supplied, MATHTYPE eps, MATHTYPE * diff)
339 int ret_value;
341 /* Both plus Infinity or both minus infinity. */
342 if (isinf (computed) && (isinf (computed) == isinf (supplied)))
343 return 1;
345 if (isnan (computed) && isnan (supplied)) /* isnan works for all types */
346 return 1;
348 *diff = FUNC(fabs) (computed - supplied);
351 ret_value = (*diff <= eps &&
352 (signbit (computed) == signbit (supplied) || eps != 0.0));
354 /* Make sure the subtraction/comparison
355 have no influence on the exceptions. */
356 feclearexcept (FE_ALL_EXCEPT);
358 return ret_value;
362 static void
363 output_result_bool (const char *test_name, int result)
365 ++noTests;
366 if (result)
368 output_pass_value ();
370 else
372 output_fail_value (test_name);
373 if (verbose > 1)
374 printf (" Value: %d\n", result);
375 ++noErrors;
378 fpstack_test (test_name);
382 static void
383 output_isvalue (const char *test_name, int result,
384 MATHTYPE value)
386 ++noTests;
387 if (result)
389 output_pass_value ();
391 else
393 output_fail_value (test_name);
394 if (verbose > 1)
395 printf (" Value: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
396 value, value);
397 ++noErrors;
400 fpstack_test (test_name);
404 static void
405 output_isvalue_ext (const char *test_name, int result,
406 MATHTYPE value, MATHTYPE parameter)
408 ++noTests;
409 if (result)
411 output_pass_value ();
413 else
415 output_fail_value (test_name);
416 if (verbose > 1)
418 printf (" Value: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
419 value, value);
420 printf (" Parameter: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
421 parameter, parameter);
423 noErrors++;
426 fpstack_test (test_name);
430 static void
431 output_result (const char *test_name, int result,
432 MATHTYPE computed, MATHTYPE expected,
433 MATHTYPE difference,
434 int print_values, int print_diff)
436 ++noTests;
437 if (result)
439 output_pass_value ();
441 else
443 output_fail_value (test_name);
444 if (verbose > 1 && print_values)
446 printf ("Result:\n");
447 printf (" is: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
448 computed, computed);
449 printf (" should be: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
450 expected, expected);
451 if (print_diff)
452 printf (" difference: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR
453 "\n", difference, difference);
455 ++noErrors;
458 fpstack_test (test_name);
462 static void
463 output_result_ext (const char *test_name, int result,
464 MATHTYPE computed, MATHTYPE expected,
465 MATHTYPE difference,
466 MATHTYPE parameter,
467 int print_values, int print_diff)
469 ++noTests;
470 if (result)
472 output_pass_value ();
474 else
476 output_fail_value (test_name);
477 if (verbose > 1 && print_values)
479 printf ("Result:\n");
480 printf (" is: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
481 computed, computed);
482 printf (" should be: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
483 expected, expected);
484 if (print_diff)
485 printf (" difference: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR
486 "\n", difference, difference);
487 printf ("Parameter: % .20" PRINTF_EXPR " % .20" PRINTF_XEXPR "\n",
488 parameter, parameter);
490 ++noErrors;
493 fpstack_test (test_name);
497 /* check that computed and expected values are the same */
498 static void
499 check (const char *test_name, MATHTYPE computed, MATHTYPE expected)
501 MATHTYPE diff;
502 int result;
504 output_new_test (test_name);
505 test_exceptions (test_name, NO_EXCEPTION);
506 result = check_equal (computed, expected, 0, &diff);
507 output_result (test_name, result,
508 computed, expected, diff, PRINT, PRINT);
512 /* check that computed and expected values are the same,
513 outputs the parameter to the function */
514 static void
515 check_ext (const char *test_name, MATHTYPE computed, MATHTYPE expected,
516 MATHTYPE parameter)
518 MATHTYPE diff;
519 int result;
521 output_new_test (test_name);
522 test_exceptions (test_name, NO_EXCEPTION);
523 result = check_equal (computed, expected, 0, &diff);
524 output_result_ext (test_name, result,
525 computed, expected, diff, parameter, PRINT, PRINT);
529 /* check that computed and expected values are the same and
530 checks also for exception flags */
531 static void
532 check_exc (const char *test_name, MATHTYPE computed, MATHTYPE expected,
533 short exception)
535 MATHTYPE diff;
536 int result;
538 output_new_test (test_name);
539 test_exceptions (test_name, exception);
540 result = check_equal (computed, expected, 0, &diff);
541 output_result (test_name, result,
542 computed, expected, diff, PRINT, PRINT);
546 /* check that computed and expected values are close enough */
547 static void
548 check_eps (const char *test_name, MATHTYPE computed, MATHTYPE expected,
549 MATHTYPE epsilon)
551 MATHTYPE diff;
552 int result;
554 output_new_test (test_name);
555 test_exceptions (test_name, NO_EXCEPTION);
556 result = check_equal (computed, expected, epsilon, &diff);
557 output_result (test_name, result,
558 computed, expected, diff, PRINT, PRINT);
562 /* check a boolean condition */
563 static void
564 check_bool (const char *test_name, int computed)
566 output_new_test (test_name);
567 test_exceptions (test_name, NO_EXCEPTION);
568 output_result_bool (test_name, computed);
572 /* check that computed and expected values are equal (int values) */
573 static void
574 check_int (const char *test_name, int computed, int expected)
576 int diff = computed - expected;
577 int result = diff == 0;
579 output_new_test (test_name);
580 test_exceptions (test_name, NO_EXCEPTION);
582 if (result)
584 output_pass_value ();
586 else
588 output_fail_value (test_name);
589 if (verbose > 1)
591 printf ("Result:\n");
592 printf (" is: %d\n", computed);
593 printf (" should be: %d\n", expected);
595 noErrors++;
598 fpstack_test (test_name);
602 /* check that computed and expected values are equal (long int values) */
603 static void
604 check_long (const char *test_name, long int computed, long int expected)
606 long int diff = computed - expected;
607 int result = diff == 0;
609 ++noTests;
610 output_new_test (test_name);
611 test_exceptions (test_name, NO_EXCEPTION);
613 if (result)
615 output_pass_value ();
617 else
619 output_fail_value (test_name);
620 if (verbose > 1)
622 printf ("Result:\n");
623 printf (" is: %ld\n", computed);
624 printf (" should be: %ld\n", expected);
626 noErrors++;
629 fpstack_test (test_name);
633 /* check that computed and expected values are equal (long long int values) */
634 static void
635 check_longlong (const char *test_name, long long int computed,
636 long long int expected)
638 long long int diff = computed - expected;
639 int result = diff == 0;
641 ++noTests;
642 output_new_test (test_name);
643 test_exceptions (test_name, NO_EXCEPTION);
645 if (result)
647 output_pass_value ();
649 else
651 output_fail_value (test_name);
652 if (verbose > 1)
654 printf ("Result:\n");
655 printf (" is: %lld\n", computed);
656 printf (" should be: %lld\n", expected);
658 noErrors++;
661 fpstack_test (test_name);
665 /* check that computed value is not-a-number */
666 static void
667 check_isnan (const char *test_name, MATHTYPE computed)
669 output_new_test (test_name);
670 test_exceptions (test_name, NO_EXCEPTION);
671 output_isvalue (test_name, isnan (computed), computed);
675 /* check that computed value is not-a-number and test for exceptions */
676 static void
677 check_isnan_exc (const char *test_name, MATHTYPE computed,
678 short exception)
680 output_new_test (test_name);
681 test_exceptions (test_name, exception);
682 output_isvalue (test_name, isnan (computed), computed);
686 /* check that computed value is not-a-number and test for exceptions */
687 static void
688 check_isnan_maybe_exc (const char *test_name, MATHTYPE computed,
689 short exception)
691 output_new_test (test_name);
692 test_not_exception (test_name, exception);
693 output_isvalue (test_name, isnan (computed), computed);
697 /* check that computed value is not-a-number and supply parameter */
698 #ifndef TEST_INLINE
699 static void
700 check_isnan_ext (const char *test_name, MATHTYPE computed,
701 MATHTYPE parameter)
703 output_new_test (test_name);
704 test_exceptions (test_name, NO_EXCEPTION);
705 output_isvalue_ext (test_name, isnan (computed), computed, parameter);
707 #endif
709 /* check that computed value is not-a-number, test for exceptions
710 and supply parameter */
711 static void
712 check_isnan_exc_ext (const char *test_name, MATHTYPE computed,
713 short exception, MATHTYPE parameter)
715 output_new_test (test_name);
716 test_exceptions (test_name, exception);
717 output_isvalue_ext (test_name, isnan (computed), computed, parameter);
721 /* Tests if computed is +Inf */
722 static void
723 check_isinfp (const char *test_name, MATHTYPE computed)
725 output_new_test (test_name);
726 test_exceptions (test_name, NO_EXCEPTION);
727 output_isvalue (test_name, (isinf (computed) == +1), computed);
731 /* Tests if computed is +Inf and supply parameter */
732 static void
733 check_isinfp_ext (const char *test_name, MATHTYPE computed,
734 MATHTYPE parameter)
736 output_new_test (test_name);
737 test_exceptions (test_name, NO_EXCEPTION);
738 output_isvalue_ext (test_name, (isinf (computed) == +1), computed, parameter);
742 /* Tests if computed is +Inf and check exceptions */
743 static void
744 check_isinfp_exc (const char *test_name, MATHTYPE computed,
745 int exception)
747 output_new_test (test_name);
748 test_exceptions (test_name, exception);
749 output_isvalue (test_name, (isinf (computed) == +1), computed);
753 /* Tests if computed is -Inf */
754 static void
755 check_isinfn (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 /* Tests if computed is -Inf and supply parameter */
764 #ifndef TEST_INLINE
765 static void
766 check_isinfn_ext (const char *test_name, MATHTYPE computed,
767 MATHTYPE parameter)
769 output_new_test (test_name);
770 test_exceptions (test_name, NO_EXCEPTION);
771 output_isvalue_ext (test_name, (isinf (computed) == -1), computed, parameter);
773 #endif
775 /* Tests if computed is -Inf and check exceptions */
776 static void
777 check_isinfn_exc (const char *test_name, MATHTYPE computed,
778 int exception)
780 output_new_test (test_name);
781 test_exceptions (test_name, exception);
782 output_isvalue (test_name, (isinf (computed) == -1), computed);
786 /* This is to prevent messages from the SVID libm emulation. */
788 matherr (struct exception *x __attribute__ ((unused)))
790 return 1;
794 /****************************************************************************
795 Test for single functions of libm
796 ****************************************************************************/
798 static void
799 acos_test (void)
801 #ifndef TEST_INLINE
802 MATHTYPE x;
804 x = random_greater (1);
805 check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
806 FUNC(acos) (x),
807 INVALID_EXCEPTION);
809 x = random_less (1);
810 check_isnan_exc ("acos (x) == NaN plus invalid exception for |x| > 1",
811 FUNC(acos) (x),
812 INVALID_EXCEPTION);
813 #endif
814 check ("acos (0) == pi/2", FUNC(acos) (0), M_PI_2l);
815 check ("acos (-0) == pi/2", FUNC(acos) (minus_zero), M_PI_2l);
817 check ("acos (1) == 0", FUNC(acos) (1), 0);
818 check ("acos (-1) == pi", FUNC(acos) (-1), M_PIl);
820 check_eps ("acos (0.5) == pi/3", FUNC(acos) (0.5), M_PI_6l * 2.0,
821 CHOOSE (1e-18, 0, 0));
822 check_eps ("acos (-0.5) == 2*pi/3", FUNC(acos) (-0.5), M_PI_6l * 4.0,
823 CHOOSE (1e-17, 0, 0));
825 check_eps ("acos (0.7) == 0.795398830...", FUNC(acos) (0.7),
826 0.7953988301841435554L, CHOOSE (7e-17L, 0, 0));
830 static void
831 acosh_test (void)
833 #ifndef TEST_INLINE
834 MATHTYPE x;
836 check_isinfp ("acosh(+inf) == +inf", FUNC(acosh) (plus_infty));
838 x = random_less (1);
839 check_isnan_exc ("acosh(x) == NaN plus invalid exception if x < 1",
840 FUNC(acosh) (x), INVALID_EXCEPTION);
841 #endif
843 check ("acosh(1) == 0", FUNC(acosh) (1), 0);
844 check_eps ("acosh(7) == 2.633915793...", FUNC(acosh) (7),
845 2.6339157938496334172L, CHOOSE (3e-19, 0, 0));
849 static void
850 asin_test (void)
852 #ifndef TEST_INLINE
853 MATHTYPE x;
855 x = random_greater (1);
856 check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
857 FUNC(asin) (x),
858 INVALID_EXCEPTION);
860 x = random_less (1);
861 check_isnan_exc ("asin x == NaN plus invalid exception for |x| > 1",
862 FUNC(asin) (x),
863 INVALID_EXCEPTION);
864 #endif
866 check ("asin (0) == 0", FUNC(asin) (0), 0);
867 check ("asin (-0) == -0", FUNC(asin) (minus_zero), minus_zero);
868 check_eps ("asin (0.5) == pi/6", FUNC(asin) (0.5), M_PI_6l,
869 CHOOSE (3.5e-18, 0, 2e-7));
870 check_eps ("asin (-0.5) == -pi/6", FUNC(asin) (-0.5), -M_PI_6l,
871 CHOOSE (3.5e-18, 0, 2e-7));
872 check ("asin (1.0) == pi/2", FUNC(asin) (1.0), M_PI_2l);
873 check ("asin (-1.0) == -pi/2", FUNC(asin) (-1.0), -M_PI_2l);
874 check_eps ("asin (0.7) == 0.775397496...", FUNC(asin) (0.7),
875 0.7753974966107530637L, CHOOSE (7e-17L, 2e-16, 2e-7));
879 static void
880 asinh_test (void)
882 check ("asinh(+0) == +0", FUNC(asinh) (0), 0);
883 #ifndef TEST_INLINE
884 check ("asinh(-0) == -0", FUNC(asinh) (minus_zero), minus_zero);
885 check_isinfp ("asinh(+inf) == +inf", FUNC(asinh) (plus_infty));
886 check_isinfn ("asinh(-inf) == -inf", FUNC(asinh) (minus_infty));
887 #endif
888 check_eps ("asinh(0.7) == 0.652666566...", FUNC(asinh) (0.7),
889 0.652666566082355786L, CHOOSE (4e-17L, 0, 6e-8));
893 static void
894 atan_test (void)
896 check ("atan (0) == 0", FUNC(atan) (0), 0);
897 check ("atan (-0) == -0", FUNC(atan) (minus_zero), minus_zero);
899 check ("atan (+inf) == pi/2", FUNC(atan) (plus_infty), M_PI_2l);
900 check ("atan (-inf) == -pi/2", FUNC(atan) (minus_infty), -M_PI_2l);
902 check_eps ("atan (1) == pi/4", FUNC(atan) (1), M_PI_4l,
903 CHOOSE (1e-18, 0, 0));
904 check_eps ("atan (-1) == -pi/4", FUNC(atan) (1), M_PI_4l,
905 CHOOSE (1e-18, 0, 0));
907 check_eps ("atan (0.7) == 0.610725964...", FUNC(atan) (0.7),
908 0.6107259643892086165L, CHOOSE (3e-17L, 0, 0));
912 static void
913 atan2_test (void)
915 MATHTYPE x;
917 x = random_greater (0);
918 check ("atan2 (0,x) == 0 for x > 0",
919 FUNC(atan2) (0, x), 0);
920 x = random_greater (0);
921 check ("atan2 (-0,x) == -0 for x > 0",
922 FUNC(atan2) (minus_zero, x), minus_zero);
924 check ("atan2 (+0,+0) == +0", FUNC(atan2) (0, 0), 0);
925 check ("atan2 (-0,+0) == -0", FUNC(atan2) (minus_zero, 0), minus_zero);
927 x = -random_greater (0);
928 check ("atan2 (+0,x) == +pi for x < 0", FUNC(atan2) (0, x), M_PIl);
930 x = -random_greater (0);
931 check ("atan2 (-0,x) == -pi for x < 0", FUNC(atan2) (minus_zero, x), -M_PIl);
933 check ("atan2 (+0,-0) == +pi", FUNC(atan2) (0, minus_zero), M_PIl);
934 check ("atan2 (-0,-0) == -pi", FUNC(atan2) (minus_zero, minus_zero), -M_PIl);
936 x = random_greater (0);
937 check ("atan2 (y,+0) == pi/2 for y > 0", FUNC(atan2) (x, 0), M_PI_2l);
939 x = random_greater (0);
940 check ("atan2 (y,-0) == pi/2 for y > 0", FUNC(atan2) (x, minus_zero),
941 M_PI_2l);
943 x = random_less (0);
944 check ("atan2 (y,+0) == -pi/2 for y < 0", FUNC(atan2) (x, 0), -M_PI_2l);
946 x = random_less (0);
947 check ("atan2 (y,-0) == -pi/2 for y < 0", FUNC(atan2) (x, minus_zero),
948 -M_PI_2l);
950 x = random_greater (0);
951 check ("atan2 (y,inf) == +0 for finite y > 0",
952 FUNC(atan2) (x, plus_infty), 0);
954 x = -random_greater (0);
955 check ("atan2 (y,inf) == -0 for finite y < 0",
956 FUNC(atan2) (x, plus_infty), minus_zero);
958 x = random_value (-1e4, 1e4);
959 check ("atan2(+inf, x) == pi/2 for finite x",
960 FUNC(atan2) (plus_infty, x), M_PI_2l);
962 x = random_value (-1e4, 1e4);
963 check ("atan2(-inf, x) == -pi/2 for finite x",
964 FUNC(atan2) (minus_infty, x), -M_PI_2l);
966 x = random_greater (0);
967 check ("atan2 (y,-inf) == +pi for finite y > 0",
968 FUNC(atan2) (x, minus_infty), M_PIl);
970 x = -random_greater (0);
971 check ("atan2 (y,-inf) == -pi for finite y < 0",
972 FUNC(atan2) (x, minus_infty), -M_PIl);
974 check ("atan2 (+inf,+inf) == +pi/4",
975 FUNC(atan2) (plus_infty, plus_infty), M_PI_4l);
977 check ("atan2 (-inf,+inf) == -pi/4",
978 FUNC(atan2) (minus_infty, plus_infty), -M_PI_4l);
980 check ("atan2 (+inf,-inf) == +3*pi/4",
981 FUNC(atan2) (plus_infty, minus_infty), 3 * M_PI_4l);
983 check ("atan2 (-inf,-inf) == -3*pi/4",
984 FUNC(atan2) (minus_infty, minus_infty), -3 * M_PI_4l);
986 /* FIXME: Add some specific tests */
987 check_eps ("atan2 (0.7,1) == 0.61072...", FUNC(atan2) (0.7, 1),
988 0.6107259643892086165L, CHOOSE (3e-17L, 0, 0));
989 check_eps ("atan2 (0.4,0.0003) == 1.57004...", FUNC(atan2) (0.4, 0.0003),
990 1.5700463269355215718L, CHOOSE (2e-19L, 0, 1.2e-7));
994 static void
995 atanh_test (void)
997 #ifndef TEST_INLINE
998 MATHTYPE x;
999 #endif
1001 check ("atanh(+0) == +0", FUNC(atanh) (0), 0);
1002 #ifndef TEST_INLINE
1003 check ("atanh(-0) == -0", FUNC(atanh) (minus_zero), minus_zero);
1005 check_isinfp_exc ("atanh(+1) == +inf plus divide-by-zero exception",
1006 FUNC(atanh) (1), DIVIDE_BY_ZERO_EXCEPTION);
1007 check_isinfn_exc ("atanh(-1) == -inf plus divide-by-zero exception",
1008 FUNC(atanh) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1010 x = random_greater (1.0);
1011 check_isnan_exc_ext ("atanh (x) == NaN plus invalid exception if |x| > 1",
1012 FUNC(atanh) (x), INVALID_EXCEPTION, x);
1014 x = random_less (1.0);
1015 check_isnan_exc_ext ("atanh (x) == NaN plus invalid exception if |x| > 1",
1016 FUNC(atanh) (x), INVALID_EXCEPTION, x);
1018 #endif
1019 check_eps ("atanh(0.7) == 0.867300527...", FUNC(atanh) (0.7),
1020 0.8673005276940531944L, CHOOSE (9e-17L, 2e-16, 0));
1024 static void
1025 cbrt_test (void)
1027 check ("cbrt (+0) == +0", FUNC(cbrt) (0.0), 0.0);
1028 check ("cbrt (-0) == -0", FUNC(cbrt) (minus_zero), minus_zero);
1030 #ifndef TEST_INLINE
1031 check_isinfp ("cbrt (+inf) == +inf", FUNC(cbrt) (plus_infty));
1032 check_isinfn ("cbrt (-inf) == -inf", FUNC(cbrt) (minus_infty));
1033 check_isnan ("cbrt (NaN) == NaN", FUNC(cbrt) (nan_value));
1034 #endif
1035 check_eps ("cbrt (-0.001) == -0.1", FUNC(cbrt) (-0.001), -0.1,
1036 CHOOSE (5e-18L, 0, 0));
1037 check_eps ("cbrt (8) == 2", FUNC(cbrt) (8), 2, CHOOSE (5e-17L, 0, 0));
1038 check_eps ("cbrt (-27) == -3", FUNC(cbrt) (-27.0), -3.0,
1039 CHOOSE (3e-16L, 5e-16, 0));
1040 check_eps ("cbrt (0.970299) == 0.99", FUNC(cbrt) (0.970299), 0.99,
1041 CHOOSE (2e-17L, 2e-16, 0));
1042 check_eps ("cbrt (0.7) == .8879040017...", FUNC(cbrt) (0.7),
1043 0.8879040017426007084L, CHOOSE (2e-17L, 6e-16, 0));
1047 static void
1048 ceil_test (void)
1050 check ("ceil (+0) == +0", FUNC(ceil) (0.0), 0.0);
1051 check ("ceil (-0) == -0", FUNC(ceil) (minus_zero), minus_zero);
1052 check_isinfp ("ceil (+inf) == +inf", FUNC(ceil) (plus_infty));
1053 check_isinfn ("ceil (-inf) == -inf", FUNC(ceil) (minus_infty));
1055 check ("ceil (pi) == 4", FUNC(ceil) (M_PIl), 4.0);
1056 check ("ceil (-pi) == -3", FUNC(ceil) (-M_PIl), -3.0);
1060 static void
1061 cos_test (void)
1063 check ("cos (+0) == 1", FUNC(cos) (0), 1);
1064 check ("cos (-0) == 1", FUNC(cos) (minus_zero), 1);
1065 check_isnan_exc ("cos (+inf) == NaN plus invalid exception",
1066 FUNC(cos) (plus_infty),
1067 INVALID_EXCEPTION);
1068 check_isnan_exc ("cos (-inf) == NaN plus invalid exception",
1069 FUNC(cos) (minus_infty),
1070 INVALID_EXCEPTION);
1072 check_eps ("cos (pi/3) == 0.5", FUNC(cos) (M_PI_6l * 2.0),
1073 0.5, CHOOSE (4e-18L, 1e-15L, 1e-7L));
1074 check_eps ("cos (2*pi/3) == -0.5", FUNC(cos) (M_PI_6l * 4.0),
1075 -0.5, CHOOSE (4e-18L, 1e-15L, 1e-7L));
1076 check_eps ("cos (pi/2) == 0", FUNC(cos) (M_PI_2l),
1077 0, CHOOSE (1e-19L, 1e-16L, 1e-7L));
1079 check_eps ("cos (0.7) == 0.7648421872...", FUNC(cos) (0.7),
1080 0.7648421872844884262L, CHOOSE (3e-17, 2e-16, 6e-8));
1084 static void
1085 cosh_test (void)
1087 check ("cosh (+0) == 1", FUNC(cosh) (0), 1);
1088 check ("cosh (-0) == 1", FUNC(cosh) (minus_zero), 1);
1090 #ifndef TEST_INLINE
1091 check_isinfp ("cosh (+inf) == +inf", FUNC(cosh) (plus_infty));
1092 check_isinfp ("cosh (-inf) == +inf", FUNC(cosh) (minus_infty));
1093 #endif
1095 check_eps ("cosh (0.7) == 1.2551690056...", FUNC(cosh) (0.7),
1096 1.255169005630943018L, CHOOSE (4e-17L, 2.3e-16, 0));
1100 static void
1101 erf_test (void)
1103 errno = 0;
1104 FUNC(erf) (0);
1105 if (errno == ENOSYS)
1106 /* Function not implemented. */
1107 return;
1109 check ("erf (+0) == +0", FUNC(erf) (0), 0);
1110 check ("erf (-0) == -0", FUNC(erf) (minus_zero), minus_zero);
1111 check ("erf (+inf) == +1", FUNC(erf) (plus_infty), 1);
1112 check ("erf (-inf) == -1", FUNC(erf) (minus_infty), -1);
1114 check_eps ("erf (0.7) == 0.6778011938...", FUNC(erf) (0.7),
1115 0.67780119383741847297L, CHOOSE (0, 2e-16, 0));
1117 check ("erf (1.2) == 0.9103139782...", FUNC(erf) (1.2),
1118 0.91031397822963538024L);
1119 check ("erf (2.0) == 0.99532...", FUNC(erf) (2.0),
1120 0.99532226501895273416L);
1121 check ("erf (4.1) == 0.99999...", FUNC(erf) (4.1),
1122 0.99999999329997234592L);
1123 check ("erf (27) == 1.0", FUNC(erf) (27),
1124 1.0L);
1128 static void
1129 erfc_test (void)
1131 errno = 0;
1132 FUNC(erfc) (0);
1133 if (errno == ENOSYS)
1134 /* Function not implemented. */
1135 return;
1137 check ("erfc (+inf) == 0", FUNC(erfc) (plus_infty), 0.0);
1138 check ("erfc (-inf) == 2", FUNC(erfc) (minus_infty), 2.0);
1139 check ("erfc (+0) == 1", FUNC(erfc) (0.0), 1.0);
1140 check ("erfc (-0) == 1", FUNC(erfc) (minus_zero), 1.0);
1142 check_eps ("erfc (0.7) == 0.3221988061...", FUNC(erfc) (0.7),
1143 0.32219880616258152702L, CHOOSE (0, 6e-17, 0));
1145 check_eps ("erfc (1.2) == 0.0896860218...", FUNC(erfc) (1.2),
1146 0.089686021770364619762L, CHOOSE (0, 0, 8e-9));
1147 check_eps ("erfc (2.0) == 0.0046777349...", FUNC(erfc) (2.0),
1148 0.0046777349810472658379L, CHOOSE (0, 9e-19, 0));
1149 check_eps ("erfc (4.1) == 6.70002...*10^-9", FUNC(erfc) (4.1),
1150 0.67000276540848983727e-8L, CHOOSE (0, 2e-23, 6e-15));
1151 check ("erfc (9) == 4.13703...*10^-37", FUNC(erfc) (9),
1152 0.41370317465138102381e-36L);
1156 static void
1157 exp_test (void)
1159 check ("exp (+0) == 1", FUNC(exp) (0), 1);
1160 check ("exp (-0) == 1", FUNC(exp) (minus_zero), 1);
1162 #ifndef TEST_INLINE
1163 check_isinfp ("exp (+inf) == +inf", FUNC(exp) (plus_infty));
1164 check ("exp (-inf) == 0", FUNC(exp) (minus_infty), 0);
1165 #endif
1166 check_eps ("exp (1) == e", FUNC(exp) (1), M_El, CHOOSE (4e-18L, 0, 0));
1168 check_eps ("exp (2) == e^2", FUNC(exp) (2), M_E2l,
1169 CHOOSE (1e-18, 8.9e-16, 0));
1170 check_eps ("exp (3) == e^3", FUNC(exp) (3), M_E3l,
1171 CHOOSE (1.5e-17, 3.6e-15, 0));
1172 check_eps ("exp (0.7) == 2.0137527074...", FUNC(exp) (0.7),
1173 2.0137527074704765216L, CHOOSE (9e-17L, 4.5e-16, 0));
1177 static void
1178 exp10_test (void)
1180 errno = 0;
1181 FUNC(exp10) (0);
1182 if (errno == ENOSYS)
1183 /* Function not implemented. */
1184 return;
1186 check ("exp10 (+0) == 1", FUNC(exp10) (0), 1);
1187 check ("exp10 (-0) == 1", FUNC(exp10) (minus_zero), 1);
1189 check_isinfp ("exp10 (+inf) == +inf", FUNC(exp10) (plus_infty));
1190 check ("exp10 (-inf) == 0", FUNC(exp10) (minus_infty), 0);
1191 check_eps ("exp10 (3) == 1000", FUNC(exp10) (3), 1000,
1192 CHOOSE (5e-16, 7e-13, 2e-4));
1193 check_eps ("exp10 (-1) == 0.1", FUNC(exp10) (-1), 0.1,
1194 CHOOSE (6e-18, 3e-17, 8e-09));
1195 check_isinfp ("exp10 (1e6) == +inf", FUNC(exp10) (1e6));
1196 check ("exp10 (-1e6) == 0", FUNC(exp10) (-1e6), 0);
1197 check_eps ("exp10 (0.7) == 5.0118723...", FUNC(exp10) (0.7),
1198 5.0118723362727228500L, CHOOSE (6e-16, 9e-16, 5e-7));
1202 static void
1203 exp2_test (void)
1205 errno = 0;
1206 FUNC(exp2) (0);
1207 if (errno == ENOSYS)
1208 /* Function not implemented. */
1209 return;
1211 check ("exp2 (+0) == 1", FUNC(exp2) (0), 1);
1212 check ("exp2 (-0) == 1", FUNC(exp2) (minus_zero), 1);
1214 check_isinfp ("exp2 (+inf) == +inf", FUNC(exp2) (plus_infty));
1215 check ("exp2 (-inf) == 0", FUNC(exp2) (minus_infty), 0);
1216 check ("exp2 (10) == 1024", FUNC(exp2) (10), 1024);
1217 check ("exp2 (-1) == 0.5", FUNC(exp2) (-1), 0.5);
1218 check_isinfp ("exp2 (1e6) == +inf", FUNC(exp2) (1e6));
1219 check ("exp2 (-1e6) == 0", FUNC(exp2) (-1e6), 0);
1220 check_eps ("exp2 (0.7) == 1.6245047927...", FUNC(exp2) (0.7),
1221 1.6245047927124710452L, CHOOSE (6e-17L, 0, 1.2e-7));
1225 static void
1226 expm1_test (void)
1228 check ("expm1 (+0) == 0", FUNC(expm1) (0), 0);
1229 #ifndef TEST_INLINE
1230 check ("expm1 (-0) == -0", FUNC(expm1) (minus_zero), minus_zero);
1232 check_isinfp ("expm1 (+inf) == +inf", FUNC(expm1) (plus_infty));
1233 check ("expm1 (-inf) == -1", FUNC(expm1) (minus_infty), -1);
1234 #endif
1236 check_eps ("expm1 (1) == e-1", FUNC(expm1) (1), M_El - 1.0,
1237 CHOOSE (4e-18L, 0, 2e-7));
1239 check_eps ("expm1 (0.7) == 1.01375...", FUNC(expm1) (0.7),
1240 1.0137527074704765216L, CHOOSE (9e-17L, 0, 0));
1244 static void
1245 check_frexp (const char *test_name, MATHTYPE computed, MATHTYPE expected,
1246 int comp_int, int exp_int)
1248 MATHTYPE diff;
1249 int result;
1251 result = (check_equal (computed, expected, 0, &diff)
1252 && (comp_int == exp_int));
1254 if (result)
1256 if (verbose > 2)
1257 printf ("Pass: %s\n", test_name);
1259 else
1261 if (verbose)
1262 printf ("Fail: %s\n", test_name);
1263 if (verbose > 1)
1265 printf ("Result:\n");
1266 printf (" is: %.20" PRINTF_EXPR " *2^%d %.20"
1267 PRINTF_XEXPR "*2^%d\n",
1268 computed, comp_int, computed, comp_int);
1269 printf (" should be: %.20" PRINTF_EXPR " *2^%d %.20"
1270 PRINTF_XEXPR "*2^%d\n",
1271 expected, exp_int, expected, exp_int);
1272 printf (" difference: %.20" PRINTF_EXPR " %.20" PRINTF_XEXPR "\n",
1273 diff, diff);
1275 noErrors++;
1277 fpstack_test (test_name);
1278 output_result (test_name, result,
1279 computed, expected, diff, PRINT, PRINT);
1283 static void
1284 frexp_test (void)
1286 int x_int;
1287 MATHTYPE result;
1289 result = FUNC(frexp) (plus_infty, &x_int);
1290 check_isinfp ("frexp (+inf, expr) == +inf", result);
1292 result = FUNC(frexp) (minus_infty, &x_int);
1293 check_isinfn ("frexp (-inf, expr) == -inf", result);
1295 result = FUNC(frexp) (nan_value, &x_int);
1296 check_isnan ("frexp (Nan, expr) == NaN", result);
1298 result = FUNC(frexp) (0, &x_int);
1299 check_frexp ("frexp: +0 == 0 * 2^0", result, 0, x_int, 0);
1301 result = FUNC(frexp) (minus_zero, &x_int);
1302 check_frexp ("frexp: -0 == -0 * 2^0", result, minus_zero, x_int, 0);
1304 result = FUNC(frexp) (12.8L, &x_int);
1305 check_frexp ("frexp: 12.8 == 0.8 * 2^4", result, 0.8L, x_int, 4);
1307 result = FUNC(frexp) (-27.34L, &x_int);
1308 check_frexp ("frexp: -27.34 == -0.854375 * 2^5",
1309 result, -0.854375L, x_int, 5);
1313 static void
1314 fpclassify_test (void)
1316 MATHTYPE x;
1318 /* fpclassify is a macro, don't give it constants as parameter */
1319 check_bool ("fpclassify (NaN) == FP_NAN", fpclassify (nan_value) == FP_NAN);
1320 check_bool ("fpclassify (+inf) == FP_INFINITE",
1321 fpclassify (plus_infty) == FP_INFINITE);
1322 check_bool ("fpclassify (-inf) == FP_INFINITE",
1323 fpclassify (minus_infty) == FP_INFINITE);
1324 check_bool ("fpclassify (+0) == FP_ZERO",
1325 fpclassify (plus_zero) == FP_ZERO);
1326 check_bool ("fpclassify (-0) == FP_ZERO",
1327 fpclassify (minus_zero) == FP_ZERO);
1329 x = 1000.0;
1330 check_bool ("fpclassify (1000) == FP_NORMAL",
1331 fpclassify (x) == FP_NORMAL);
1335 static void
1336 isfinite_test (void)
1338 check_bool ("isfinite (0) != 0", isfinite (0));
1339 check_bool ("isfinite (-0) != 0", isfinite (minus_zero));
1340 check_bool ("isfinite (10) != 0", isfinite (10));
1341 check_bool ("isfinite (+inf) == 0", isfinite (plus_infty) == 0);
1342 check_bool ("isfinite (-inf) == 0", isfinite (minus_infty) == 0);
1343 check_bool ("isfinite (NaN) == 0", isfinite (nan_value) == 0);
1347 static void
1348 isnormal_test (void)
1350 check_bool ("isnormal (0) == 0", isnormal (0) == 0);
1351 check_bool ("isnormal (-0) == 0", isnormal (minus_zero) == 0);
1352 check_bool ("isnormal (10) != 0", isnormal (10));
1353 check_bool ("isnormal (+inf) == 0", isnormal (plus_infty) == 0);
1354 check_bool ("isnormal (-inf) == 0", isnormal (minus_infty) == 0);
1355 check_bool ("isnormal (NaN) == 0", isnormal (nan_value) == 0);
1359 static void
1360 signbit_test (void)
1362 MATHTYPE x;
1364 check_bool ("signbit (+0) == 0", signbit (0) == 0);
1365 check_bool ("signbit (-0) != 0", signbit (minus_zero));
1366 check_bool ("signbit (+inf) == 0", signbit (plus_infty) == 0);
1367 check_bool ("signbit (-inf) != 0", signbit (minus_infty));
1369 x = random_less (0);
1370 check_bool ("signbit (x) != 0 for x < 0", signbit (x));
1372 x = random_greater (0);
1373 check_bool ("signbit (x) == 0 for x > 0", signbit (x) == 0);
1377 static void
1378 gamma_test (void)
1380 errno = 0;
1381 FUNC(gamma) (1);
1382 if (errno == ENOSYS)
1383 /* Function not implemented. */
1384 return;
1385 feclearexcept (FE_ALL_EXCEPT);
1388 check_isinfp ("gamma (+inf) == +inf", FUNC(gamma) (plus_infty));
1389 check_isinfp_exc ("gamma (0) == +inf plus divide by zero exception",
1390 FUNC(gamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1392 check_isinfp_exc ("gamma (x) == +inf plus divide by zero exception for integer x <= 0",
1393 FUNC(gamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1394 check_isnan_exc ("gamma (-inf) == NaN plus invalid exception",
1395 FUNC(gamma) (minus_infty), INVALID_EXCEPTION);
1397 signgam = 0;
1398 check ("gamma (1) == 0", FUNC(gamma) (1), 0);
1399 check_int ("gamma (1) sets signgam to 1", signgam, 1);
1401 signgam = 0;
1402 check ("gamma (3) == M_LN2", FUNC(gamma) (3), M_LN2l);
1403 check_int ("gamma (3) sets signgam to 1", signgam, 1);
1405 signgam = 0;
1406 check_eps ("gamma (0.5) == log(sqrt(pi))", FUNC(gamma) (0.5),
1407 FUNC(log) (FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 1e-7));
1408 check_int ("gamma (0.5) sets signgam to 1", signgam, 1);
1410 signgam = 0;
1411 check_eps ("gamma (-0.5) == log(2*sqrt(pi))", FUNC(gamma) (-0.5),
1412 FUNC(log) (2*FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 0));
1414 check_int ("gamma (-0.5) sets signgam to -1", signgam, -1);
1418 static void
1419 tgamma_test (void)
1421 errno = 0;
1422 FUNC(tgamma) (1);
1423 if (errno == ENOSYS)
1424 /* Function not implemented. */
1425 return;
1426 feclearexcept (FE_ALL_EXCEPT);
1428 check_isinfp ("tgamma (+inf) == +inf", FUNC(tgamma) (plus_infty));
1429 check_isnan_exc ("tgamma (0) == NaN plus invalid exception",
1430 FUNC(tgamma) (0), INVALID_EXCEPTION);
1432 check_isnan_exc_ext ("tgamma (x) == NaN plus invalid exception for integer x <= 0",
1433 FUNC(tgamma) (-2), INVALID_EXCEPTION, -2);
1434 check_isnan_exc ("tgamma (-inf) == NaN plus invalid exception",
1435 FUNC(tgamma) (minus_infty), INVALID_EXCEPTION);
1437 check_eps ("tgamma (0.5) == sqrt(pi)", FUNC(tgamma) (0.5),
1438 FUNC(sqrt) (M_PIl), CHOOSE (0, 5e-16, 2e-7));
1439 check_eps ("tgamma (-0.5) == -2*sqrt(pi)", FUNC(tgamma) (-0.5),
1440 -2*FUNC(sqrt) (M_PIl), CHOOSE (0, 5e-16, 3e-7));
1442 check ("tgamma (1) == 1", FUNC(tgamma) (1), 1);
1443 check_eps ("tgamma (4) == 6", FUNC(tgamma) (4), 6, CHOOSE (0, 8.9e-16, 0));
1445 check_eps ("tgamma (0.7) == 1.29805...", FUNC(tgamma) (0.7),
1446 1.29805533264755778568L, CHOOSE (0, 3e-16, 2e-7));
1447 check_eps ("tgamma (1.2) == 0.91816...", FUNC(tgamma) (1.2),
1448 0.91816874239976061064L, CHOOSE (0, 1.2e-16, 0));
1452 static void
1453 lgamma_test (void)
1455 errno = 0;
1456 FUNC(lgamma) (0);
1457 if (errno == ENOSYS)
1458 /* Function not implemented. */
1459 return;
1460 feclearexcept (FE_ALL_EXCEPT);
1462 check_isinfp ("lgamma (+inf) == +inf", FUNC(lgamma) (plus_infty));
1463 check_isinfp_exc ("lgamma (0) == +inf plus divide by zero exception",
1464 FUNC(lgamma) (0), DIVIDE_BY_ZERO_EXCEPTION);
1466 check_isinfp_exc ("lgamma (x) == +inf plus divide by zero exception for integer x <= 0",
1467 FUNC(lgamma) (-3), DIVIDE_BY_ZERO_EXCEPTION);
1468 check_isnan_exc ("lgamma (-inf) == NaN plus invalid exception",
1469 FUNC(lgamma) (minus_infty), INVALID_EXCEPTION);
1471 signgam = 0;
1472 check ("lgamma (1) == 0", FUNC(lgamma) (1), 0);
1473 check_int ("lgamma (0) sets signgam to 1", signgam, 1);
1475 signgam = 0;
1476 check ("lgamma (3) == M_LN2", FUNC(lgamma) (3), M_LN2l);
1477 check_int ("lgamma (3) sets signgam to 1", signgam, 1);
1479 signgam = 0;
1480 check_eps ("lgamma (0.5) == log(sqrt(pi))", FUNC(lgamma) (0.5),
1481 FUNC(log) (FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 1e-7));
1482 check_int ("lgamma (0.5) sets signgam to 1", signgam, 1);
1484 signgam = 0;
1485 check_eps ("lgamma (-0.5) == log(2*sqrt(pi))", FUNC(lgamma) (-0.5),
1486 FUNC(log) (2*FUNC(sqrt) (M_PIl)), CHOOSE (0, 1e-15, 0));
1488 check_int ("lgamma (-0.5) sets signgam to -1", signgam, -1);
1490 signgam = 0;
1491 check_eps ("lgamma (0.7) == 0.26086...", FUNC(lgamma) (0.7),
1492 0.26086724653166651439L, CHOOSE (0, 6e-17, 3e-8));
1493 check_int ("lgamma (0.7) sets signgam to 1", signgam, 1);
1495 signgam = 0;
1496 check_eps ("lgamma (1.2) == -0.08537...", FUNC(lgamma) (1.2),
1497 -0.853740900033158497197e-1L, CHOOSE (0, 2e-17, 2e-8));
1498 check_int ("lgamma (1.2) sets signgam to 1", signgam, 1);
1502 static void
1503 ilogb_test (void)
1505 int i;
1507 check_int ("ilogb (1) == 0", FUNC(ilogb) (1), 0);
1508 check_int ("ilogb (e) == 1", FUNC(ilogb) (M_El), 1);
1509 check_int ("ilogb (1024) == 10", FUNC(ilogb) (1024), 10);
1510 check_int ("ilogb (-2000) == 10", FUNC(ilogb) (-2000), 10);
1512 /* XXX We have a problem here: the standard does not tell us whether
1513 exceptions are allowed/required. ignore them for now. */
1514 i = FUNC(ilogb) (0.0);
1515 feclearexcept (FE_ALL_EXCEPT);
1516 check_int ("ilogb (0) == FP_ILOGB0", i, FP_ILOGB0);
1517 i = FUNC(ilogb) (nan_value);
1518 feclearexcept (FE_ALL_EXCEPT);
1519 check_int ("ilogb (NaN) == FP_ILOGBNAN", i, FP_ILOGBNAN);
1523 static void
1524 ldexp_test (void)
1526 MATHTYPE x;
1528 check ("ldexp (0, 0) == 0", FUNC(ldexp) (0, 0), 0);
1530 check_isinfp ("ldexp (+inf, 1) == +inf", FUNC(ldexp) (plus_infty, 1));
1531 check_isinfn ("ldexp (-inf, 1) == -inf", FUNC(ldexp) (minus_infty, 1));
1532 check_isnan ("ldexp (NaN, 1) == NaN", FUNC(ldexp) (nan_value, 1));
1534 check ("ldexp (0.8, 4) == 12.8", FUNC(ldexp) (0.8L, 4), 12.8L);
1535 check ("ldexp (-0.854375, 5) == -27.34", FUNC(ldexp) (-0.854375L, 5), -27.34L);
1537 x = random_greater (0.0);
1538 check_ext ("ldexp (x, 0) == x", FUNC(ldexp) (x, 0L), x, x);
1542 static void
1543 log_test (void)
1545 check_isinfn_exc ("log (+0) == -inf plus divide-by-zero exception",
1546 FUNC(log) (0), DIVIDE_BY_ZERO_EXCEPTION);
1547 check_isinfn_exc ("log (-0) == -inf plus divide-by-zero exception",
1548 FUNC(log) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1550 check ("log (1) == 0", FUNC(log) (1), 0);
1552 check_isnan_exc ("log (x) == NaN plus invalid exception if x < 0",
1553 FUNC(log) (-1), INVALID_EXCEPTION);
1554 check_isinfp ("log (+inf) == +inf", FUNC(log) (plus_infty));
1556 check_eps ("log (e) == 1", FUNC(log) (M_El), 1, CHOOSE (1e-18L, 0, 9e-8L));
1557 check_eps ("log (1/e) == -1", FUNC(log) (1.0 / M_El), -1,
1558 CHOOSE (2e-18L, 0, 0));
1559 check_eps ("log (2) == M_LN2", FUNC(log) (2), M_LN2l,
1560 CHOOSE (6e-20L, 0, 0));
1561 check_eps ("log (10) == M_LN10", FUNC(log) (10), M_LN10l,
1562 CHOOSE (1e-18L, 0, 0));
1563 check_eps ("log (0.7) == -0.3566749439...", FUNC(log) (0.7),
1564 -0.35667494393873237891L, CHOOSE (7e-17L, 6e-17, 3e-8));
1568 static void
1569 log10_test (void)
1571 check_isinfn_exc ("log10 (+0) == -inf plus divide-by-zero exception",
1572 FUNC(log10) (0), DIVIDE_BY_ZERO_EXCEPTION);
1573 check_isinfn_exc ("log10 (-0) == -inf plus divide-by-zero exception",
1574 FUNC(log10) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1576 check ("log10 (1) == +0", FUNC(log10) (1), 0);
1578 check_isnan_exc ("log10 (x) == NaN plus invalid exception if x < 0",
1579 FUNC(log10) (-1), INVALID_EXCEPTION);
1581 check_isinfp ("log10 (+inf) == +inf", FUNC(log10) (plus_infty));
1583 check_eps ("log10 (0.1) == -1", FUNC(log10) (0.1L), -1,
1584 CHOOSE (1e-18L, 0, 0));
1585 check_eps ("log10 (10) == 1", FUNC(log10) (10.0), 1,
1586 CHOOSE (1e-18L, 0, 0));
1587 check_eps ("log10 (100) == 2", FUNC(log10) (100.0), 2,
1588 CHOOSE (1e-18L, 0, 0));
1589 check ("log10 (10000) == 4", FUNC(log10) (10000.0), 4);
1590 check_eps ("log10 (e) == M_LOG10E", FUNC(log10) (M_El), M_LOG10El,
1591 CHOOSE (1e-18, 0, 9e-8));
1592 check_eps ("log10 (0.7) == -0.1549019599...", FUNC(log10) (0.7),
1593 -0.15490195998574316929L, CHOOSE (3e-17L, 3e-17, 2e-8));
1597 static void
1598 log1p_test (void)
1600 check ("log1p (+0) == +0", FUNC(log1p) (0), 0);
1601 check ("log1p (-0) == -0", FUNC(log1p) (minus_zero), minus_zero);
1603 check_isinfn_exc ("log1p (-1) == -inf plus divide-by-zero exception",
1604 FUNC(log1p) (-1), DIVIDE_BY_ZERO_EXCEPTION);
1605 check_isnan_exc ("log1p (x) == NaN plus invalid exception if x < -1",
1606 FUNC(log1p) (-2), INVALID_EXCEPTION);
1608 check_isinfp ("log1p (+inf) == +inf", FUNC(log1p) (plus_infty));
1610 check_eps ("log1p (e-1) == 1", FUNC(log1p) (M_El - 1.0), 1,
1611 CHOOSE (1e-18L, 0, 6e-8));
1613 check_eps ("log1p (-0.3) == -0.35667...", FUNC(log1p) (-0.3),
1614 -0.35667494393873237891L, CHOOSE (2e-17L, 6e-17, 3e-8));
1618 static void
1619 log2_test (void)
1621 check_isinfn_exc ("log2 (+0) == -inf plus divide-by-zero exception",
1622 FUNC(log2) (0), DIVIDE_BY_ZERO_EXCEPTION);
1623 check_isinfn_exc ("log2 (-0) == -inf plus divide-by-zero exception",
1624 FUNC(log2) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1626 check ("log2 (1) == +0", FUNC(log2) (1), 0);
1628 check_isnan_exc ("log2 (x) == NaN plus invalid exception if x < 0",
1629 FUNC(log2) (-1), INVALID_EXCEPTION);
1631 check_isinfp ("log2 (+inf) == +inf", FUNC(log2) (plus_infty));
1633 check_eps ("log2 (e) == M_LOG2E", FUNC(log2) (M_El), M_LOG2El,
1634 CHOOSE (1e-18L, 0, 0));
1635 check ("log2 (2) == 1", FUNC(log2) (2.0), 1);
1636 check_eps ("log2 (16) == 4", FUNC(log2) (16.0), 4, CHOOSE (1e-18L, 0, 0));
1637 check ("log2 (256) == 8", FUNC(log2) (256.0), 8);
1638 check_eps ("log2 (0.7) == -0.5145731728...", FUNC(log2) (0.7),
1639 -0.51457317282975824043L, CHOOSE (1e-16L, 2e-16, 6e-8));
1643 static void
1644 logb_test (void)
1646 check_isinfp ("logb (+inf) == +inf", FUNC(logb) (plus_infty));
1647 check_isinfp ("logb (-inf) == +inf", FUNC(logb) (minus_infty));
1649 check_isinfn_exc ("logb (+0) == -inf plus divide-by-zero exception",
1650 FUNC(logb) (0), DIVIDE_BY_ZERO_EXCEPTION);
1652 check_isinfn_exc ("logb (-0) == -inf plus divide-by-zero exception",
1653 FUNC(logb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
1655 check ("logb (1) == 0", FUNC(logb) (1), 0);
1656 check ("logb (e) == 1", FUNC(logb) (M_El), 1);
1657 check ("logb (1024) == 10", FUNC(logb) (1024), 10);
1658 check ("logb (-2000) == 10", FUNC(logb) (-2000), 10);
1662 static void
1663 modf_test (void)
1665 MATHTYPE result, intpart;
1667 result = FUNC(modf) (plus_infty, &intpart);
1668 check ("modf (+inf, &x) returns +0", result, 0);
1669 check_isinfp ("modf (+inf, &x) set x to +inf", intpart);
1671 result = FUNC(modf) (minus_infty, &intpart);
1672 check ("modf (-inf, &x) returns -0", result, minus_zero);
1673 check_isinfn ("modf (-inf, &x) sets x to -inf", intpart);
1675 result = FUNC(modf) (nan_value, &intpart);
1676 check_isnan ("modf (NaN, &x) returns NaN", result);
1677 check_isnan ("modf (NaN, &x) sets x to NaN", intpart);
1679 result = FUNC(modf) (0, &intpart);
1680 check ("modf (0, &x) returns 0", result, 0);
1681 check ("modf (0, &x) sets x to 0", intpart, 0);
1683 result = FUNC(modf) (minus_zero, &intpart);
1684 check ("modf (-0, &x) returns -0", result, minus_zero);
1685 check ("modf (-0, &x) sets x to -0", intpart, minus_zero);
1687 result = FUNC(modf) (1.5, &intpart);
1688 check ("modf (1.5, &x) returns 0.5", result, 0.5);
1689 check ("modf (1.5, &x) sets x to 1", intpart, 1);
1691 result = FUNC(modf) (2.5, &intpart);
1692 check ("modf (2.5, &x) returns 0.5", result, 0.5);
1693 check ("modf (2.5, &x) sets x to 2", intpart, 2);
1695 result = FUNC(modf) (-2.5, &intpart);
1696 check ("modf (-2.5, &x) returns -0.5", result, -0.5);
1697 check ("modf (-2.5, &x) sets x to -2", intpart, -2);
1699 result = FUNC(modf) (20, &intpart);
1700 check ("modf (20, &x) returns 0", result, 0);
1701 check ("modf (20, &x) sets x to 20", intpart, 20);
1703 result = FUNC(modf) (21, &intpart);
1704 check ("modf (21, &x) returns 0", result, 0);
1705 check ("modf (21, &x) sets x to 21", intpart, 21);
1707 result = FUNC(modf) (89.6, &intpart);
1708 check_eps ("modf (89.6, &x) returns 0.6", result, 0.6,
1709 CHOOSE (6e-15L, 6e-15, 2e-6));
1710 check ("modf (89.6, &x) sets x to 89", intpart, 89);
1714 static void
1715 scalb_test (void)
1717 MATHTYPE x;
1719 check_isnan ("scalb (2, 0.5) == NaN", FUNC(scalb) (2, 0.5));
1720 check_isnan ("scalb (3, -2.5) == NaN", FUNC(scalb) (3, -2.5));
1722 check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1723 check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1725 x = random_greater (0.0);
1726 check ("scalb (x, 0) == 0", FUNC(scalb) (x, 0), x);
1727 x = random_greater (0.0);
1728 check ("scalb (-x, 0) == 0", FUNC(scalb) (-x, 0), -x);
1730 check_isnan_exc ("scalb (+0, +inf) == NaN plus invalid exception",
1731 FUNC(scalb) (0, plus_infty), INVALID_EXCEPTION);
1732 check_isnan_exc ("scalb (-0, +inf) == NaN plus invalid exception",
1733 FUNC(scalb) (minus_zero, plus_infty), INVALID_EXCEPTION);
1735 check ("scalb (+0, 2) == +0", FUNC(scalb) (0, 2), 0);
1736 check ("scalb (-0, 4) == -0", FUNC(scalb) (minus_zero, -4), minus_zero);
1737 check ("scalb (+0, 0) == +0", FUNC(scalb) (0, 0), 0);
1738 check ("scalb (-0, 0) == -0", FUNC(scalb) (minus_zero, 0), minus_zero);
1739 check ("scalb (+0, -1) == +0", FUNC(scalb) (0, -1), 0);
1740 check ("scalb (-0, -10) == -0", FUNC(scalb) (minus_zero, -10), minus_zero);
1741 check ("scalb (+0, -inf) == +0", FUNC(scalb) (0, minus_infty), 0);
1742 check ("scalb (-0, -inf) == -0", FUNC(scalb) (minus_zero, minus_infty),
1743 minus_zero);
1745 check_isinfp ("scalb (+inf, -1) == +inf", FUNC(scalb) (plus_infty, -1));
1746 check_isinfn ("scalb (-inf, -10) == -inf", FUNC(scalb) (minus_infty, -10));
1747 check_isinfp ("scalb (+inf, 0) == +inf", FUNC(scalb) (plus_infty, 0));
1748 check_isinfn ("scalb (-inf, 0) == -inf", FUNC(scalb) (minus_infty, 0));
1749 check_isinfp ("scalb (+inf, 2) == +inf", FUNC(scalb) (plus_infty, 2));
1750 check_isinfn ("scalb (-inf, 100) == -inf", FUNC(scalb) (minus_infty, 100));
1752 x = random_greater (0.0);
1753 check ("scalb (x, -inf) == 0", FUNC(scalb) (x, minus_infty), 0.0);
1754 check ("scalb (-x, -inf) == -0", FUNC(scalb) (-x, minus_infty), minus_zero);
1756 x = random_greater (0.0);
1757 check_isinfp ("scalb (x, +inf) == +inf", FUNC(scalb) (x, plus_infty));
1758 x = random_greater (0.0);
1759 check_isinfn ("scalb (-x, +inf) == -inf", FUNC(scalb) (-x, plus_infty));
1760 check_isinfp ("scalb (+inf, +inf) == +inf",
1761 FUNC(scalb) (plus_infty, plus_infty));
1762 check_isinfn ("scalb (-inf, +inf) == -inf",
1763 FUNC(scalb) (minus_infty, plus_infty));
1765 check_isnan ("scalb (+inf, -inf) == NaN",
1766 FUNC(scalb) (plus_infty, minus_infty));
1767 check_isnan ("scalb (-inf, -inf) == NaN",
1768 FUNC(scalb) (minus_infty, minus_infty));
1770 check_isnan ("scalb (NaN, 1) == NaN", FUNC(scalb) (nan_value, 1));
1771 check_isnan ("scalb (1, NaN) == NaN", FUNC(scalb) (1, nan_value));
1772 check_isnan ("scalb (NaN, 0) == NaN", FUNC(scalb) (nan_value, 0));
1773 check_isnan ("scalb (0, NaN) == NaN", FUNC(scalb) (0, nan_value));
1774 check_isnan ("scalb (NaN, +inf) == NaN",
1775 FUNC(scalb) (nan_value, plus_infty));
1776 check_isnan ("scalb (+inf, NaN) == NaN",
1777 FUNC(scalb) (plus_infty, nan_value));
1778 check_isnan ("scalb (NaN, NaN) == NaN", FUNC(scalb) (nan_value, nan_value));
1780 check ("scalb (0.8, 4) == 12.8", FUNC(scalb) (0.8L, 4), 12.8L);
1781 check ("scalb (-0.854375, 5) == -27.34", FUNC(scalb) (-0.854375L, 5), -27.34L);
1785 static void
1786 scalbn_test (void)
1788 MATHTYPE x;
1790 check ("scalbn (0, 0) == 0", FUNC(scalbn) (0, 0), 0);
1792 check_isinfp ("scalbn (+inf, 1) == +inf", FUNC(scalbn) (plus_infty, 1));
1793 check_isinfn ("scalbn (-inf, 1) == -inf", FUNC(scalbn) (minus_infty, 1));
1794 check_isnan ("scalbn (NaN, 1) == NaN", FUNC(scalbn) (nan_value, 1));
1796 check ("scalbn (0.8, 4) == 12.8", FUNC(scalbn) (0.8L, 4), 12.8L);
1797 check ("scalbn (-0.854375, 5) == -27.34", FUNC(scalbn) (-0.854375L, 5), -27.34L);
1799 x = random_greater (0.0);
1800 check_ext ("scalbn (x, 0) == x", FUNC(scalbn) (x, 0L), x, x);
1804 static void
1805 sin_test (void)
1807 check ("sin (+0) == +0", FUNC(sin) (0), 0);
1808 check ("sin (-0) == -0", FUNC(sin) (minus_zero), minus_zero);
1809 check_isnan_exc ("sin (+inf) == NaN plus invalid exception",
1810 FUNC(sin) (plus_infty),
1811 INVALID_EXCEPTION);
1812 check_isnan_exc ("sin (-inf) == NaN plus invalid exception",
1813 FUNC(sin) (minus_infty),
1814 INVALID_EXCEPTION);
1816 check_eps ("sin (pi/6) == 0.5", FUNC(sin) (M_PI_6l),
1817 0.5, CHOOSE (4e-18L, 0, 0));
1818 check_eps ("sin (-pi/6) == -0.5", FUNC(sin) (-M_PI_6l),
1819 -0.5, CHOOSE (4e-18L, 0, 0));
1820 check ("sin (pi/2) == 1", FUNC(sin) (M_PI_2l), 1);
1821 check ("sin (-pi/2) == -1", FUNC(sin) (-M_PI_2l), -1);
1822 check_eps ("sin (0.7) == 0.6442176872...", FUNC(sin) (0.7),
1823 0.64421768723769105367L, CHOOSE (4e-17L, 0, 0));
1827 static void
1828 sinh_test (void)
1830 check ("sinh (+0) == +0", FUNC(sinh) (0), 0);
1832 #ifndef TEST_INLINE
1833 check ("sinh (-0) == -0", FUNC(sinh) (minus_zero), minus_zero);
1835 check_isinfp ("sinh (+inf) == +inf", FUNC(sinh) (plus_infty));
1836 check_isinfn ("sinh (-inf) == -inf", FUNC(sinh) (minus_infty));
1837 #endif
1839 check_eps ("sinh (0.7) == 0.7585837018...", FUNC(sinh) (0.7),
1840 0.75858370183953350346L, CHOOSE (6e-17L, 2e-16, 6e-8));
1844 static void
1845 sincos_test (void)
1847 MATHTYPE sin_res, cos_res;
1848 fenv_t fenv;
1850 FUNC(sincos) (0, &sin_res, &cos_res);
1851 fegetenv (&fenv);
1852 check ("sincos (+0, &sin, &cos) puts +0 in sin", sin_res, 0);
1853 fesetenv (&fenv);
1854 check ("sincos (+0, &sin, &cos) puts 1 in cos", cos_res, 1);
1856 FUNC(sincos) (minus_zero, &sin_res, &cos_res);
1857 fegetenv (&fenv);
1858 check ("sincos (-0, &sin, &cos) puts -0 in sin", sin_res, minus_zero);
1859 fesetenv (&fenv);
1860 check ("sincos (-0, &sin, &cos) puts 1 in cos", cos_res, 1);
1862 FUNC(sincos) (plus_infty, &sin_res, &cos_res);
1863 fegetenv (&fenv);
1864 check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in sin plus invalid exception",
1865 sin_res, INVALID_EXCEPTION);
1866 fesetenv (&fenv);
1867 check_isnan_exc ("sincos (+inf, &sin, &cos) puts NaN in cos plus invalid exception",
1868 cos_res, INVALID_EXCEPTION);
1870 FUNC(sincos) (minus_infty, &sin_res, &cos_res);
1871 fegetenv (&fenv);
1872 check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in sin plus invalid exception",
1873 sin_res, INVALID_EXCEPTION);
1874 fesetenv (&fenv);
1875 check_isnan_exc ("sincos (-inf,&sin, &cos) puts NaN in cos plus invalid exception",
1876 cos_res, INVALID_EXCEPTION);
1878 FUNC(sincos) (M_PI_2l, &sin_res, &cos_res);
1879 fegetenv (&fenv);
1880 check ("sincos (pi/2, &sin, &cos) puts 1 in sin", sin_res, 1);
1881 fesetenv (&fenv);
1882 check_eps ("sincos (pi/2, &sin, &cos) puts 0 in cos", cos_res, 0,
1883 CHOOSE (1e-18L, 1e-16, 1e-7));
1885 FUNC(sincos) (M_PI_6l, &sin_res, &cos_res);
1886 check_eps ("sincos (pi/6, &sin, &cos) puts 0.5 in sin", sin_res, 0.5,
1887 CHOOSE (5e-18L, 0, 0));
1889 FUNC(sincos) (M_PI_6l*2.0, &sin_res, &cos_res);
1890 check_eps ("sincos (pi/3, &sin, &cos) puts 0.5 in cos", cos_res, 0.5,
1891 CHOOSE (5e-18L, 1e-15, 1e-7));
1893 FUNC(sincos) (0.7, &sin_res, &cos_res);
1894 check_eps ("sincos (0.7, &sin, &cos) puts 0.6442176872... in sin", sin_res,
1895 0.64421768723769105367L, CHOOSE (4e-17L, 0, 0));
1896 check_eps ("sincos (0.7, &sin, &cos) puts 0.7648421872... in cos", cos_res,
1897 0.76484218728448842626L, CHOOSE (3e-17L, 2e-16, 6e-8));
1901 static void
1902 tan_test (void)
1904 check ("tan (+0) == +0", FUNC(tan) (0), 0);
1905 check ("tan (-0) == -0", FUNC(tan) (minus_zero), minus_zero);
1906 check_isnan_exc ("tan (+inf) == NaN plus invalid exception",
1907 FUNC(tan) (plus_infty), INVALID_EXCEPTION);
1908 check_isnan_exc ("tan (-inf) == NaN plus invalid exception",
1909 FUNC(tan) (minus_infty), INVALID_EXCEPTION);
1911 check_eps ("tan (pi/4) == 1", FUNC(tan) (M_PI_4l), 1,
1912 CHOOSE (2e-18L, 1e-15L, 2e-7));
1913 check_eps ("tan (0.7) == 0.8422883804...", FUNC(tan) (0.7),
1914 0.84228838046307944813L, CHOOSE (8e-17L, 0, 0));
1918 static void
1919 tanh_test (void)
1921 check ("tanh (+0) == +0", FUNC(tanh) (0), 0);
1922 #ifndef TEST_INLINE
1923 check ("tanh (-0) == -0", FUNC(tanh) (minus_zero), minus_zero);
1925 check ("tanh (+inf) == +1", FUNC(tanh) (plus_infty), 1);
1926 check ("tanh (-inf) == -1", FUNC(tanh) (minus_infty), -1);
1927 #endif
1928 check_eps ("tanh (0.7) == 0.6043677771...", FUNC(tanh) (0.7),
1929 0.60436777711716349631L, CHOOSE (3e-17L, 2e-16, 6e-8));
1933 static void
1934 fabs_test (void)
1936 check ("fabs (+0) == +0", FUNC(fabs) (0), 0);
1937 check ("fabs (-0) == +0", FUNC(fabs) (minus_zero), 0);
1939 check_isinfp ("fabs (+inf) == +inf", FUNC(fabs) (plus_infty));
1940 check_isinfp ("fabs (-inf) == +inf", FUNC(fabs) (minus_infty));
1942 check ("fabs (+38) == 38", FUNC(fabs) (38.0), 38.0);
1943 check ("fabs (-e) == e", FUNC(fabs) (-M_El), M_El);
1947 static void
1948 floor_test (void)
1950 check ("floor (+0) == +0", FUNC(floor) (0.0), 0.0);
1951 check ("floor (-0) == -0", FUNC(floor) (minus_zero), minus_zero);
1952 check_isinfp ("floor (+inf) == +inf", FUNC(floor) (plus_infty));
1953 check_isinfn ("floor (-inf) == -inf", FUNC(floor) (minus_infty));
1955 check ("floor (pi) == 3", FUNC(floor) (M_PIl), 3.0);
1956 check ("floor (-pi) == -4", FUNC(floor) (-M_PIl), -4.0);
1960 static void
1961 hypot_test (void)
1963 MATHTYPE a;
1965 a = random_greater (0);
1966 check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot) (plus_infty, a), a);
1967 check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot) (minus_infty, a), a);
1969 #ifndef TEST_INLINE
1970 check_isinfp ("hypot (+inf, NaN) == +inf", FUNC(hypot) (plus_infty, nan_value));
1971 check_isinfp ("hypot (-inf, NaN) == +inf", FUNC(hypot) (minus_infty, nan_value));
1972 #endif
1974 check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot) (nan_value, nan_value));
1976 a = FUNC(hypot) (12.4L, 0.7L);
1977 check ("hypot (x,y) == hypot (y,x)", FUNC(hypot) (0.7L, 12.4L), a);
1978 check ("hypot (x,y) == hypot (-x,y)", FUNC(hypot) (-12.4L, 0.7L), a);
1979 check ("hypot (x,y) == hypot (-y,x)", FUNC(hypot) (-0.7L, 12.4L), a);
1980 check ("hypot (x,y) == hypot (-x,-y)", FUNC(hypot) (-12.4L, -0.7L), a);
1981 check ("hypot (x,y) == hypot (-y,-x)", FUNC(hypot) (-0.7L, -12.4L), a);
1982 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-0.7L, 0), 0.7L);
1983 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (0.7L, 0), 0.7L);
1984 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-1.0L, 0), 1.0L);
1985 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (1.0L, 0), 1.0L);
1986 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-5.7e7L, 0), 5.7e7L);
1987 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (5.7e7L, 0), 5.7e7L);
1989 check_eps ("hypot (0.7,1.2) == 1.38924...", FUNC(hypot) (0.7, 1.2),
1990 1.3892443989449804508L, CHOOSE (7e-17L, 3e-16, 0));
1994 static void
1995 pow_test (void)
1997 MATHTYPE x;
1999 check ("pow (+0, +0) == 1", FUNC(pow) (0, 0), 1);
2000 check ("pow (+0, -0) == 1", FUNC(pow) (0, minus_zero), 1);
2001 check ("pow (-0, +0) == 1", FUNC(pow) (minus_zero, 0), 1);
2002 check ("pow (-0, -0) == 1", FUNC(pow) (minus_zero, minus_zero), 1);
2004 check ("pow (+10, +0) == 1", FUNC(pow) (10, 0), 1);
2005 check ("pow (+10, -0) == 1", FUNC(pow) (10, minus_zero), 1);
2006 check ("pow (-10, +0) == 1", FUNC(pow) (-10, 0), 1);
2007 check ("pow (-10, -0) == 1", FUNC(pow) (-10, minus_zero), 1);
2009 check ("pow (NaN, +0) == 1", FUNC(pow) (nan_value, 0), 1);
2010 check ("pow (NaN, -0) == 1", FUNC(pow) (nan_value, minus_zero), 1);
2012 #ifndef TEST_INLINE
2013 check_isinfp ("pow (+1.1, +inf) == +inf", FUNC(pow) (1.1, plus_infty));
2014 check_isinfp ("pow (+inf, +inf) == +inf", FUNC(pow) (plus_infty, plus_infty));
2015 check_isinfp ("pow (-1.1, +inf) == +inf", FUNC(pow) (-1.1, plus_infty));
2016 check_isinfp ("pow (-inf, +inf) == +inf", FUNC(pow) (minus_infty, plus_infty));
2018 check ("pow (0.9, +inf) == +0", FUNC(pow) (0.9L, plus_infty), 0);
2019 check ("pow (1e-7, +inf) == +0", FUNC(pow) (1e-7L, plus_infty), 0);
2020 check ("pow (-0.9, +inf) == +0", FUNC(pow) (-0.9L, plus_infty), 0);
2021 check ("pow (-1e-7, +inf) == +0", FUNC(pow) (-1e-7L, plus_infty), 0);
2023 check ("pow (+1.1, -inf) == 0", FUNC(pow) (1.1, minus_infty), 0);
2024 check ("pow (+inf, -inf) == 0", FUNC(pow) (plus_infty, minus_infty), 0);
2025 check ("pow (-1.1, -inf) == 0", FUNC(pow) (-1.1, minus_infty), 0);
2026 check ("pow (-inf, -inf) == 0", FUNC(pow) (minus_infty, minus_infty), 0);
2028 check_isinfp ("pow (0.9, -inf) == +inf", FUNC(pow) (0.9L, minus_infty));
2029 check_isinfp ("pow (1e-7, -inf) == +inf", FUNC(pow) (1e-7L, minus_infty));
2030 check_isinfp ("pow (-0.9, -inf) == +inf", FUNC(pow) (-0.9L, minus_infty));
2031 check_isinfp ("pow (-1e-7, -inf) == +inf", FUNC(pow) (-1e-7L, minus_infty));
2033 check_isinfp ("pow (+inf, 1e-7) == +inf", FUNC(pow) (plus_infty, 1e-7L));
2034 check_isinfp ("pow (+inf, 1) == +inf", FUNC(pow) (plus_infty, 1));
2035 check_isinfp ("pow (+inf, 1e7) == +inf", FUNC(pow) (plus_infty, 1e7L));
2037 check ("pow (+inf, -1e-7) == 0", FUNC(pow) (plus_infty, -1e-7L), 0);
2038 check ("pow (+inf, -1) == 0", FUNC(pow) (plus_infty, -1), 0);
2039 check ("pow (+inf, -1e7) == 0", FUNC(pow) (plus_infty, -1e7L), 0);
2041 check_isinfn ("pow (-inf, 1) == -inf", FUNC(pow) (minus_infty, 1));
2042 check_isinfn ("pow (-inf, 11) == -inf", FUNC(pow) (minus_infty, 11));
2043 check_isinfn ("pow (-inf, 1001) == -inf", FUNC(pow) (minus_infty, 1001));
2045 check_isinfp ("pow (-inf, 2) == +inf", FUNC(pow) (minus_infty, 2));
2046 check_isinfp ("pow (-inf, 12) == +inf", FUNC(pow) (minus_infty, 12));
2047 check_isinfp ("pow (-inf, 1002) == +inf", FUNC(pow) (minus_infty, 1002));
2048 check_isinfp ("pow (-inf, 0.1) == +inf", FUNC(pow) (minus_infty, 0.1));
2049 check_isinfp ("pow (-inf, 1.1) == +inf", FUNC(pow) (minus_infty, 1.1));
2050 check_isinfp ("pow (-inf, 11.1) == +inf", FUNC(pow) (minus_infty, 11.1));
2051 check_isinfp ("pow (-inf, 1001.1) == +inf", FUNC(pow) (minus_infty, 1001.1));
2053 check ("pow (-inf, -1) == -0", FUNC(pow) (minus_infty, -1), minus_zero);
2054 check ("pow (-inf, -11) == -0", FUNC(pow) (minus_infty, -11), minus_zero);
2055 check ("pow (-inf, -1001) == -0", FUNC(pow) (minus_infty, -1001), minus_zero);
2057 check ("pow (-inf, -2) == +0", FUNC(pow) (minus_infty, -2), 0);
2058 check ("pow (-inf, -12) == +0", FUNC(pow) (minus_infty, -12), 0);
2059 check ("pow (-inf, -1002) == +0", FUNC(pow) (minus_infty, -1002), 0);
2060 check ("pow (-inf, -0.1) == +0", FUNC(pow) (minus_infty, -0.1), 0);
2061 check ("pow (-inf, -1.1) == +0", FUNC(pow) (minus_infty, -1.1), 0);
2062 check ("pow (-inf, -11.1) == +0", FUNC(pow) (minus_infty, -11.1), 0);
2063 check ("pow (-inf, -1001.1) == +0", FUNC(pow) (minus_infty, -1001.1), 0);
2065 check_isnan ("pow (NaN, NaN) == NaN", FUNC(pow) (nan_value, nan_value));
2066 check_isnan ("pow (0, NaN) == NaN", FUNC(pow) (0, nan_value));
2067 check_isnan ("pow (1, NaN) == NaN", FUNC(pow) (1, nan_value));
2068 check_isnan ("pow (-1, NaN) == NaN", FUNC(pow) (-1, nan_value));
2069 check_isnan ("pow (NaN, 1) == NaN", FUNC(pow) (nan_value, 1));
2070 check_isnan ("pow (NaN, -1) == NaN", FUNC(pow) (nan_value, -1));
2072 x = random_greater (0.0);
2073 check_isnan_ext ("pow (x, NaN) == NaN", FUNC(pow) (x, nan_value), x);
2075 check_isnan_exc ("pow (+1, +inf) == NaN plus invalid exception",
2076 FUNC(pow) (1, plus_infty), INVALID_EXCEPTION);
2077 check_isnan_exc ("pow (-1, +inf) == NaN plus invalid exception",
2078 FUNC(pow) (-1, plus_infty), INVALID_EXCEPTION);
2079 check_isnan_exc ("pow (+1, -inf) == NaN plus invalid exception",
2080 FUNC(pow) (1, minus_infty), INVALID_EXCEPTION);
2081 check_isnan_exc ("pow (-1, -inf) == NaN plus invalid exception",
2082 FUNC(pow) (-1, minus_infty), INVALID_EXCEPTION);
2084 check_isnan_exc ("pow (-0.1, 1.1) == NaN plus invalid exception",
2085 FUNC(pow) (-0.1, 1.1), INVALID_EXCEPTION);
2086 check_isnan_exc ("pow (-0.1, -1.1) == NaN plus invalid exception",
2087 FUNC(pow) (-0.1, -1.1), INVALID_EXCEPTION);
2088 check_isnan_exc ("pow (-10.1, 1.1) == NaN plus invalid exception",
2089 FUNC(pow) (-10.1, 1.1), INVALID_EXCEPTION);
2090 check_isnan_exc ("pow (-10.1, -1.1) == NaN plus invalid exception",
2091 FUNC(pow) (-10.1, -1.1), INVALID_EXCEPTION);
2093 check_isinfp_exc ("pow (+0, -1) == +inf plus divide-by-zero exception",
2094 FUNC(pow) (0, -1), DIVIDE_BY_ZERO_EXCEPTION);
2095 check_isinfp_exc ("pow (+0, -11) == +inf plus divide-by-zero exception",
2096 FUNC(pow) (0, -11), DIVIDE_BY_ZERO_EXCEPTION);
2097 check_isinfn_exc ("pow (-0, -1) == -inf plus divide-by-zero exception",
2098 FUNC(pow) (minus_zero, -1), DIVIDE_BY_ZERO_EXCEPTION);
2099 check_isinfn_exc ("pow (-0, -11) == -inf plus divide-by-zero exception",
2100 FUNC(pow) (minus_zero, -11), DIVIDE_BY_ZERO_EXCEPTION);
2102 check_isinfp_exc ("pow (+0, -2) == +inf plus divide-by-zero exception",
2103 FUNC(pow) (0, -2), DIVIDE_BY_ZERO_EXCEPTION);
2104 check_isinfp_exc ("pow (+0, -11.1) == +inf plus divide-by-zero exception",
2105 FUNC(pow) (0, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2106 check_isinfp_exc ("pow (-0, -2) == +inf plus divide-by-zero exception",
2107 FUNC(pow) (minus_zero, -2), DIVIDE_BY_ZERO_EXCEPTION);
2108 check_isinfp_exc ("pow (-0, -11.1) == +inf plus divide-by-zero exception",
2109 FUNC(pow) (minus_zero, -11.1), DIVIDE_BY_ZERO_EXCEPTION);
2110 #endif
2112 check ("pow (+0, 1) == +0", FUNC(pow) (0, 1), 0);
2113 check ("pow (+0, 11) == +0", FUNC(pow) (0, 11), 0);
2114 #ifndef TEST_INLINE
2115 check ("pow (-0, 1) == -0", FUNC(pow) (minus_zero, 1), minus_zero);
2116 check ("pow (-0, 11) == -0", FUNC(pow) (minus_zero, 11), minus_zero);
2117 #endif
2119 check ("pow (+0, 2) == +0", FUNC(pow) (0, 2), 0);
2120 check ("pow (+0, 11.1) == +0", FUNC(pow) (0, 11.1), 0);
2122 #ifndef TEST_INLINE
2123 check ("pow (-0, 2) == +0", FUNC(pow) (minus_zero, 2), 0);
2124 check ("pow (-0, 11.1) == +0", FUNC(pow) (minus_zero, 11.1), 0);
2126 x = random_greater (1.0);
2127 check_isinfp_ext ("pow (x, +inf) == +inf for |x| > 1",
2128 FUNC(pow) (x, plus_infty), x);
2130 x = random_value (-1.0, 1.0);
2131 check_ext ("pow (x, +inf) == +0 for |x| < 1",
2132 FUNC(pow) (x, plus_infty), 0.0, x);
2134 x = random_greater (1.0);
2135 check_ext ("pow (x, -inf) == +0 for |x| > 1",
2136 FUNC(pow) (x, minus_infty), 0.0, x);
2138 x = random_value (-1.0, 1.0);
2139 check_isinfp_ext ("pow (x, -inf) == +inf for |x| < 1",
2140 FUNC(pow) (x, minus_infty), x);
2142 x = random_greater (0.0);
2143 check_isinfp_ext ("pow (+inf, y) == +inf for y > 0",
2144 FUNC(pow) (plus_infty, x), x);
2146 x = random_less (0.0);
2147 check_ext ("pow (+inf, y) == +0 for y < 0",
2148 FUNC(pow) (plus_infty, x), 0.0, x);
2150 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2151 check_isinfn_ext ("pow (-inf, y) == -inf for y an odd integer > 0",
2152 FUNC(pow) (minus_infty, x), x);
2154 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2155 check_isinfp_ext ("pow (-inf, y) == +inf for y > 0 and not an odd integer",
2156 FUNC(pow) (minus_infty, x), x);
2158 x = -((rand () % 1000000) * 2.0 + 1); /* Get random odd integer < 0 */
2159 check_ext ("pow (-inf, y) == -0 for y an odd integer < 0",
2160 FUNC(pow) (minus_infty, x), minus_zero, x);
2162 x = ((rand () % 1000000) + 1) * -2.0; /* Get random even integer < 0 */
2163 check_ext ("pow (-inf, y) == +0 for y < 0 and not an odd integer",
2164 FUNC(pow) (minus_infty, x), 0.0, x);
2165 #endif
2167 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2168 check_ext ("pow (+0, y) == +0 for y an odd integer > 0",
2169 FUNC(pow) (0.0, x), 0.0, x);
2170 #ifndef TEST_INLINE
2171 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
2172 check_ext ("pow (-0, y) == -0 for y an odd integer > 0",
2173 FUNC(pow) (minus_zero, x), minus_zero, x);
2174 #endif
2176 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2177 check_ext ("pow (+0, y) == +0 for y > 0 and not an odd integer",
2178 FUNC(pow) (0.0, x), 0.0, x);
2180 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
2181 check_ext ("pow (-0, y) == +0 for y > 0 and not an odd integer",
2182 FUNC(pow) (minus_zero, x), 0.0, x);
2184 check_eps ("pow (0.7, 1.2) == 0.65180...", FUNC(pow) (0.7, 1.2),
2185 0.65180494056638638188L, CHOOSE (4e-17L, 0, 0));
2187 #ifdef TEST_DOUBLE
2188 check ("pow (-7.49321e+133, -9.80818e+16) == 0",
2189 FUNC(pow) (-7.49321e+133, -9.80818e+16), 0);
2190 #endif
2194 static void
2195 fdim_test (void)
2197 check ("fdim (+0, +0) = +0", FUNC(fdim) (0, 0), 0);
2198 check ("fdim (9, 0) = 9", FUNC(fdim) (9, 0), 9);
2199 check ("fdim (0, 9) = 0", FUNC(fdim) (0, 9), 0);
2200 check ("fdim (-9, 0) = 0", FUNC(fdim) (-9, 0), 0);
2201 check ("fdim (0, -9) = 9", FUNC(fdim) (0, -9), 9);
2203 check_isinfp ("fdim (+inf, 9) = +inf", FUNC(fdim) (plus_infty, 9));
2204 check_isinfp ("fdim (+inf, -9) = +inf", FUNC(fdim) (plus_infty, -9));
2205 check ("fdim (-inf, 9) = 0", FUNC(fdim) (minus_infty, 9), 0);
2206 check ("fdim (-inf, -9) = 0", FUNC(fdim) (minus_infty, -9), 0);
2207 check_isinfp ("fdim (+9, -inf) = +inf", FUNC(fdim) (9, minus_infty));
2208 check_isinfp ("fdim (-9, -inf) = +inf", FUNC(fdim) (-9, minus_infty));
2209 check ("fdim (9, inf) = 0", FUNC(fdim) (9, plus_infty), 0);
2210 check ("fdim (-9, inf) = 0", FUNC(fdim) (-9, plus_infty), 0);
2212 check_isnan ("fdim (0, NaN) = NaN", FUNC(fdim) (0, nan_value));
2213 check_isnan ("fdim (9, NaN) = NaN", FUNC(fdim) (9, nan_value));
2214 check_isnan ("fdim (-9, NaN) = NaN", FUNC(fdim) (-9, nan_value));
2215 check_isnan ("fdim (NaN, 9) = NaN", FUNC(fdim) (nan_value, 9));
2216 check_isnan ("fdim (NaN, -9) = NaN", FUNC(fdim) (nan_value, -9));
2217 check_isnan ("fdim (+inf, NaN) = NaN", FUNC(fdim) (plus_infty, nan_value));
2218 check_isnan ("fdim (-inf, NaN) = NaN", FUNC(fdim) (minus_infty, nan_value));
2219 check_isnan ("fdim (NaN, +inf) = NaN", FUNC(fdim) (nan_value, plus_infty));
2220 check_isnan ("fdim (NaN, -inf) = NaN", FUNC(fdim) (nan_value, minus_infty));
2221 check_isnan ("fdim (NaN, NaN) = NaN", FUNC(fdim) (nan_value, nan_value));
2225 static void
2226 fmin_test (void)
2228 check ("fmin (+0, +0) = +0", FUNC(fmin) (0, 0), 0);
2229 check ("fmin (9, 0) = 0", FUNC(fmin) (9, 0), 0);
2230 check ("fmin (0, 9) = 0", FUNC(fmin) (0, 9), 0);
2231 check ("fmin (-9, 0) = -9", FUNC(fmin) (-9, 0), -9);
2232 check ("fmin (0, -9) = -9", FUNC(fmin) (0, -9), -9);
2234 check ("fmin (+inf, 9) = 9", FUNC(fmin) (plus_infty, 9), 9);
2235 check ("fmin (9, +inf) = 9", FUNC(fmin) (9, plus_infty), 9);
2236 check ("fmin (+inf, -9) = -9", FUNC(fmin) (plus_infty, -9), -9);
2237 check ("fmin (-9, +inf) = -9", FUNC(fmin) (-9, plus_infty), -9);
2238 check_isinfn ("fmin (-inf, 9) = -inf", FUNC(fmin) (minus_infty, 9));
2239 check_isinfn ("fmin (-inf, -9) = -inf", FUNC(fmin) (minus_infty, -9));
2240 check_isinfn ("fmin (+9, -inf) = -inf", FUNC(fmin) (9, minus_infty));
2241 check_isinfn ("fmin (-9, -inf) = -inf", FUNC(fmin) (-9, minus_infty));
2243 check ("fmin (0, NaN) = 0", FUNC(fmin) (0, nan_value), 0);
2244 check ("fmin (9, NaN) = 9", FUNC(fmin) (9, nan_value), 9);
2245 check ("fmin (-9, NaN) = 9", FUNC(fmin) (-9, nan_value), -9);
2246 check ("fmin (NaN, 0) = 0", FUNC(fmin) (nan_value, 0), 0);
2247 check ("fmin (NaN, 9) = NaN", FUNC(fmin) (nan_value, 9), 9);
2248 check ("fmin (NaN, -9) = NaN", FUNC(fmin) (nan_value, -9), -9);
2249 check_isinfp ("fmin (+inf, NaN) = +inf", FUNC(fmin) (plus_infty, nan_value));
2250 check_isinfn ("fmin (-inf, NaN) = -inf", FUNC(fmin) (minus_infty, nan_value));
2251 check_isinfp ("fmin (NaN, +inf) = +inf", FUNC(fmin) (nan_value, plus_infty));
2252 check_isinfn ("fmin (NaN, -inf) = -inf", FUNC(fmin) (nan_value, minus_infty));
2253 check_isnan ("fmin (NaN, NaN) = NaN", FUNC(fmin) (nan_value, nan_value));
2257 static void
2258 fmax_test (void)
2260 check ("fmax (+0, +0) = +0", FUNC(fmax) (0, 0), 0);
2261 check ("fmax (9, 0) = 9", FUNC(fmax) (9, 0), 9);
2262 check ("fmax (0, 9) = 9", FUNC(fmax) (0, 9), 9);
2263 check ("fmax (-9, 0) = 0", FUNC(fmax) (-9, 0), 0);
2264 check ("fmax (0, -9) = 0", FUNC(fmax) (0, -9), 0);
2266 check_isinfp ("fmax (+inf, 9) = +inf", FUNC(fmax) (plus_infty, 9));
2267 check_isinfp ("fmax (9, +inf) = +inf", FUNC(fmax) (0, plus_infty));
2268 check_isinfp ("fmax (-9, +inf) = +inf", FUNC(fmax) (-9, plus_infty));
2269 check_isinfp ("fmax (+inf, -9) = +inf", FUNC(fmax) (plus_infty, -9));
2270 check ("fmax (-inf, 9) = 9", FUNC(fmax) (minus_infty, 9), 9);
2271 check ("fmax (-inf, -9) = -9", FUNC(fmax) (minus_infty, -9), -9);
2272 check ("fmax (+9, -inf) = 9", FUNC(fmax) (9, minus_infty), 9);
2273 check ("fmax (-9, -inf) = -9", FUNC(fmax) (-9, minus_infty), -9);
2275 check ("fmax (0, NaN) = 0", FUNC(fmax) (0, nan_value), 0);
2276 check ("fmax (9, NaN) = 9", FUNC(fmax) (9, nan_value), 9);
2277 check ("fmax (-9, NaN) = 9", FUNC(fmax) (-9, nan_value), -9);
2278 check ("fmax (NaN, 0) = 0", FUNC(fmax) (nan_value, 0), 0);
2279 check ("fmax (NaN, 9) = NaN", FUNC(fmax) (nan_value, 9), 9);
2280 check ("fmax (NaN, -9) = NaN", FUNC(fmax) (nan_value, -9), -9);
2281 check_isinfp ("fmax (+inf, NaN) = +inf", FUNC(fmax) (plus_infty, nan_value));
2282 check_isinfn ("fmax (-inf, NaN) = -inf", FUNC(fmax) (minus_infty, nan_value));
2283 check_isinfp ("fmax (NaN, +inf) = +inf", FUNC(fmax) (nan_value, plus_infty));
2284 check_isinfn ("fmax (NaN, -inf) = -inf", FUNC(fmax) (nan_value, minus_infty));
2285 check_isnan ("fmax (NaN, NaN) = NaN", FUNC(fmax) (nan_value, nan_value));
2289 static void
2290 fmod_test (void)
2292 MATHTYPE x;
2294 x = random_greater (0);
2295 check_ext ("fmod (+0, y) == +0 for y != 0", FUNC(fmod) (0, x), 0, x);
2297 x = random_greater (0);
2298 check_ext ("fmod (-0, y) == -0 for y != 0", FUNC(fmod) (minus_zero, x),
2299 minus_zero, x);
2301 check_isnan_exc_ext ("fmod (+inf, y) == NaN plus invalid exception",
2302 FUNC(fmod) (plus_infty, x), INVALID_EXCEPTION, x);
2303 check_isnan_exc_ext ("fmod (-inf, y) == NaN plus invalid exception",
2304 FUNC(fmod) (minus_infty, x), INVALID_EXCEPTION, x);
2305 check_isnan_exc_ext ("fmod (x, +0) == NaN plus invalid exception",
2306 FUNC(fmod) (x, 0), INVALID_EXCEPTION, x);
2307 check_isnan_exc_ext ("fmod (x, -0) == NaN plus invalid exception",
2308 FUNC(fmod) (x, minus_zero), INVALID_EXCEPTION, x);
2310 x = random_greater (0);
2311 check_ext ("fmod (x, +inf) == x for x not infinite",
2312 FUNC(fmod) (x, plus_infty), x, x);
2313 x = random_greater (0);
2314 check_ext ("fmod (x, -inf) == x for x not infinite",
2315 FUNC(fmod) (x, minus_infty), x, x);
2317 check_eps ("fmod (6.5, 2.3) == 1.9", FUNC(fmod) (6.5, 2.3), 1.9,
2318 CHOOSE (5e-16, 1e-15, 2e-7));
2319 check_eps ("fmod (-6.5, 2.3) == -1.9", FUNC(fmod) (-6.5, 2.3), -1.9,
2320 CHOOSE (5e-16, 1e-15, 2e-7));
2321 check_eps ("fmod (6.5, -2.3) == 1.9", FUNC(fmod) (6.5, -2.3), 1.9,
2322 CHOOSE (5e-16, 1e-15, 2e-7));
2323 check_eps ("fmod (-6.5, -2.3) == -1.9", FUNC(fmod) (-6.5, -2.3), -1.9,
2324 CHOOSE (5e-16, 1e-15, 2e-7));
2328 static void
2329 nextafter_test (void)
2331 MATHTYPE x;
2333 check ("nextafter (+0, +0) = +0", FUNC(nextafter) (0, 0), 0);
2334 check ("nextafter (-0, +0) = +0", FUNC(nextafter) (minus_zero, 0), 0);
2335 check ("nextafter (+0, -0) = -0", FUNC(nextafter) (0, minus_zero),
2336 minus_zero);
2337 check ("nextafter (-0, -0) = -0", FUNC(nextafter) (minus_zero, minus_zero),
2338 minus_zero);
2340 check ("nextafter (9, 9) = 9", FUNC(nextafter) (9, 9), 9);
2341 check ("nextafter (-9, -9) = -9", FUNC(nextafter) (-9, -9), -9);
2342 check_isinfp ("nextafter (+inf, +inf) = +inf",
2343 FUNC(nextafter) (plus_infty, plus_infty));
2344 check_isinfn ("nextafter (-inf, -inf) = -inf",
2345 FUNC(nextafter) (minus_infty, minus_infty));
2347 x = rand () * 1.1;
2348 check_isnan ("nextafter (NaN, x) = NaN", FUNC(nextafter) (nan_value, x));
2349 check_isnan ("nextafter (x, NaN) = NaN", FUNC(nextafter) (x, nan_value));
2350 check_isnan ("nextafter (NaN, NaN) = NaN", FUNC(nextafter) (nan_value,
2351 nan_value));
2353 /* XXX We need the hexadecimal FP number representation here for further
2354 tests. */
2358 static void
2359 copysign_test (void)
2361 check ("copysign (0, 4) = 0", FUNC(copysign) (0, 4), 0);
2362 check ("copysign (0, -4) = -0", FUNC(copysign) (0, -4), minus_zero);
2363 check ("copysign (-0, 4) = 0", FUNC(copysign) (minus_zero, 4), 0);
2364 check ("copysign (-0, -4) = -0", FUNC(copysign) (minus_zero, -4),
2365 minus_zero);
2367 check_isinfp ("copysign (+inf, 0) = +inf", FUNC(copysign) (plus_infty, 0));
2368 check_isinfn ("copysign (+inf, -0) = -inf", FUNC(copysign) (plus_infty,
2369 minus_zero));
2370 check_isinfp ("copysign (-inf, 0) = +inf", FUNC(copysign) (minus_infty, 0));
2371 check_isinfn ("copysign (-inf, -0) = -inf", FUNC(copysign) (minus_infty,
2372 minus_zero));
2374 check ("copysign (0, +inf) = 0", FUNC(copysign) (0, plus_infty), 0);
2375 check ("copysign (0, -inf) = -0", FUNC(copysign) (0, minus_zero),
2376 minus_zero);
2377 check ("copysign (-0, +inf) = 0", FUNC(copysign) (minus_zero, plus_infty),
2379 check ("copysign (-0, -inf) = -0", FUNC(copysign) (minus_zero, minus_zero),
2380 minus_zero);
2382 /* XXX More correctly we would have to check the sign of the NaN. */
2383 check_isnan ("copysign (+NaN, 0) = +NaN", FUNC(copysign) (nan_value, 0));
2384 check_isnan ("copysign (+NaN, -0) = -NaN", FUNC(copysign) (nan_value,
2385 minus_zero));
2386 check_isnan ("copysign (-NaN, 0) = +NaN", FUNC(copysign) (-nan_value, 0));
2387 check_isnan ("copysign (-NaN, -0) = -NaN", FUNC(copysign) (-nan_value,
2388 minus_zero));
2392 static void
2393 trunc_test (void)
2395 check ("trunc(0) = 0", FUNC(trunc) (0), 0);
2396 check ("trunc(-0) = -0", FUNC(trunc) (minus_zero), minus_zero);
2397 check ("trunc(0.625) = 0", FUNC(trunc) (0.625), 0);
2398 check ("trunc(-0.625) = -0", FUNC(trunc) (-0.625), minus_zero);
2399 check ("trunc(1) = 1", FUNC(trunc) (1), 1);
2400 check ("trunc(-1) = -1", FUNC(trunc) (-1), -1);
2401 check ("trunc(1.625) = 1", FUNC(trunc) (1.625), 1);
2402 check ("trunc(-1.625) = -1", FUNC(trunc) (-1.625), -1);
2404 check ("trunc(1048580.625) = 1048580", FUNC(trunc) (1048580.625L),
2405 1048580L);
2406 check ("trunc(-1048580.625) = -1048580", FUNC(trunc) (-1048580.625L),
2407 -1048580L);
2409 check ("trunc(8388610.125) = 8388610", FUNC(trunc) (8388610.125L),
2410 8388610.0L);
2411 check ("trunc(-8388610.125) = -8388610", FUNC(trunc) (-8388610.125L),
2412 -8388610.0L);
2414 check ("trunc(4294967296.625) = 4294967296", FUNC(trunc) (4294967296.625L),
2415 4294967296.0L);
2416 check ("trunc(-4294967296.625) = -4294967296",
2417 FUNC(trunc) (-4294967296.625L), -4294967296.0L);
2419 check_isinfp ("trunc(+inf) = +inf", FUNC(trunc) (plus_infty));
2420 check_isinfn ("trunc(-inf) = -inf", FUNC(trunc) (minus_infty));
2421 check_isnan ("trunc(NaN) = NaN", FUNC(trunc) (nan_value));
2425 static void
2426 sqrt_test (void)
2428 MATHTYPE x;
2431 /* XXX Tests fuer negative x are missing */
2432 check ("sqrt (0) == 0", FUNC(sqrt) (0), 0);
2433 check_isnan ("sqrt (NaN) == NaN", FUNC(sqrt) (nan_value));
2434 check_isinfp ("sqrt (+inf) == +inf", FUNC(sqrt) (plus_infty));
2436 check ("sqrt (-0) == -0", FUNC(sqrt) (0), 0);
2438 x = random_less (0.0);
2439 check_isnan_exc_ext ("sqrt (x) == NaN plus invalid exception for x < 0",
2440 FUNC(sqrt) (x), INVALID_EXCEPTION, x);
2442 x = random_value (0, 10000);
2443 check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x);
2444 check ("sqrt (4) == 2", FUNC(sqrt) (4), 2);
2445 check ("sqrt (2) == 1.14142...", FUNC(sqrt) (2), M_SQRT2l);
2446 check ("sqrt (0.25) == 0.5", FUNC(sqrt) (0.25), 0.5);
2447 check ("sqrt (6642.25) == 81.5", FUNC(sqrt) (6642.25), 81.5);
2448 check_eps ("sqrt (15239.903) == 123.45", FUNC(sqrt) (15239.903), 123.45,
2449 CHOOSE (3e-6L, 3e-6, 8e-6));
2450 check_eps ("sqrt (0.7) == 0.8366600265", FUNC(sqrt) (0.7),
2451 0.83666002653407554798L, CHOOSE (3e-17L, 0, 0));
2455 static void
2456 remainder_test (void)
2458 MATHTYPE result;
2460 result = FUNC(remainder) (1, 0);
2461 check_isnan_exc ("remainder(1, +0) == NaN plus invalid exception",
2462 result, INVALID_EXCEPTION);
2464 result = FUNC(remainder) (1, minus_zero);
2465 check_isnan_exc ("remainder(1, -0) == NaN plus invalid exception",
2466 result, INVALID_EXCEPTION);
2468 result = FUNC(remainder) (plus_infty, 1);
2469 check_isnan_exc ("remainder(+inf, 1) == NaN plus invalid exception",
2470 result, INVALID_EXCEPTION);
2472 result = FUNC(remainder) (minus_infty, 1);
2473 check_isnan_exc ("remainder(-inf, 1) == NaN plus invalid exception",
2474 result, INVALID_EXCEPTION);
2476 result = FUNC(remainder) (1.625, 1.0);
2477 check ("remainder(1.625, 1.0) == -0.375", result, -0.375);
2479 result = FUNC(remainder) (-1.625, 1.0);
2480 check ("remainder(-1.625, 1.0) == 0.375", result, 0.375);
2482 result = FUNC(remainder) (1.625, -1.0);
2483 check ("remainder(1.625, -1.0) == -0.375", result, -0.375);
2485 result = FUNC(remainder) (-1.625, -1.0);
2486 check ("remainder(-1.625, -1.0) == 0.375", result, 0.375);
2488 result = FUNC(remainder) (5.0, 2.0);
2489 check ("remainder(5.0, 2.0) == 1.0", result, 1.0);
2491 result = FUNC(remainder) (3.0, 2.0);
2492 check ("remainder(3.0, 2.0) == -1.0", result, -1.0);
2496 static void
2497 remquo_test (void)
2499 int quo;
2500 MATHTYPE result;
2502 result = FUNC(remquo) (1, 0, &quo);
2503 check_isnan_exc ("remquo(1, +0, &x) == NaN plus invalid exception",
2504 result, INVALID_EXCEPTION);
2506 result = FUNC(remquo) (1, minus_zero, &quo);
2507 check_isnan_exc ("remquo(1, -0, &x) == NaN plus invalid exception",
2508 result, INVALID_EXCEPTION);
2510 result = FUNC(remquo) (plus_infty, 1, &quo);
2511 check_isnan_exc ("remquo(+inf, 1, &x) == NaN plus invalid exception",
2512 result, INVALID_EXCEPTION);
2514 result = FUNC(remquo) (minus_infty, 1, &quo);
2515 check_isnan_exc ("remquo(-inf, 1, &x) == NaN plus invalid exception",
2516 result, INVALID_EXCEPTION);
2518 result = FUNC(remquo) (1.625, 1.0, &quo);
2519 check ("remquo(1.625, 1.0, &x) == -0.375", result, -0.375);
2520 check_long ("remquo(1.625, 1.0, &x) puts 2 in x", quo, 2);
2522 result = FUNC(remquo) (-1.625, 1.0, &quo);
2523 check ("remquo(-1.625, 1.0, &x) == 0.375", result, 0.375);
2524 check_long ("remquo(-1.625, 1.0, &x) puts -2 in x", quo, -2);
2526 result = FUNC(remquo) (1.625, -1.0, &quo);
2527 check ("remquo(1.625, -1.0, &x) == -0.375", result, -0.375);
2528 check_long ("remquo(1.625, -1.0, &x) puts -2 in x", quo, -2);
2530 result = FUNC(remquo) (-1.625, -1.0, &quo);
2531 check ("remquo(-1.625, -1.0, &x) == 0.375", result, 0.375);
2532 check_long ("remquo(-1.625, -1.0, &x) puts 2 in x", quo, 2);
2534 result = FUNC(remquo) (5.0, 2.0, &quo);
2535 check ("remquo(5.0, 2.0, &x) == 1.0", result, 1.0);
2536 check_long ("remquo (5.0, 2.0, &x) puts 2 in x", quo, 2);
2538 result = FUNC(remquo) (3.0, 2.0, &quo);
2539 check ("remquo(3.0, 2.0, &x) == -1.0", result, -1.0);
2540 check_long ("remquo (3.0, 2.0, &x) puts 2 in x", quo, 2);
2544 static void
2545 cexp_test (void)
2547 __complex__ MATHTYPE result;
2549 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, plus_zero));
2550 check ("real(cexp(0 + 0i)) = 1", __real__ result, 1);
2551 check ("imag(cexp(0 + 0i)) = 0", __imag__ result, 0);
2552 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_zero));
2553 check ("real(cexp(-0 + 0i)) = 1", __real__ result, 1);
2554 check ("imag(cexp(-0 + 0i)) = 0", __imag__ result, 0);
2555 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, minus_zero));
2556 check ("real(cexp(0 - 0i)) = 1", __real__ result, 1);
2557 check ("imag(cexp(0 - 0i)) = -0", __imag__ result, minus_zero);
2558 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_zero));
2559 check ("real(cexp(-0 - 0i)) = 1", __real__ result, 1);
2560 check ("imag(cexp(-0 - 0i)) = -0", __imag__ result, minus_zero);
2562 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_zero));
2563 check_isinfp ("real(cexp(+inf + 0i)) = +inf", __real__ result);
2564 check ("imag(cexp(+inf + 0i)) = 0", __imag__ result, 0);
2565 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_zero));
2566 check_isinfp ("real(cexp(+inf - 0i)) = +inf", __real__ result);
2567 check ("imag(cexp(+inf - 0i)) = -0", __imag__ result, minus_zero);
2569 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_zero));
2570 check ("real(cexp(-inf + 0i)) = 0", __real__ result, 0);
2571 check ("imag(cexp(-inf + 0i)) = 0", __imag__ result, 0);
2572 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_zero));
2573 check ("real(cexp(-inf - 0i)) = 0", __real__ result, 0);
2574 check ("imag(cexp(-inf - 0i)) = -0", __imag__ result, minus_zero);
2577 result = FUNC(cexp) (BUILD_COMPLEX (0.0, plus_infty));
2578 check_isnan_exc ("real(cexp(0 + i inf)) = NaN plus invalid exception",
2579 __real__ result, INVALID_EXCEPTION);
2580 check_isnan ("imag(cexp(0 + i inf)) = NaN plus invalid exception",
2581 __imag__ result);
2583 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_infty));
2584 check_isnan_exc ("real(cexp(-0 + i inf)) = NaN plus invalid exception",
2585 __real__ result, INVALID_EXCEPTION);
2586 check_isnan ("imag(cexp(-0 + i inf)) = NaN plus invalid exception",
2587 __imag__ result);
2588 result = FUNC(cexp) (BUILD_COMPLEX (0.0, minus_infty));
2589 check_isnan_exc ("real(cexp(0 - i inf)) = NaN plus invalid exception",
2590 __real__ result, INVALID_EXCEPTION);
2591 check_isnan ("imag(cexp(0 - i inf)) = NaN plus invalid exception",
2592 __imag__ result);
2593 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_infty));
2594 check_isnan_exc ("real(cexp(-0 - i inf)) = NaN plus invalid exception",
2595 __real__ result, INVALID_EXCEPTION);
2596 check_isnan ("imag(cexp(-0 - i inf)) = NaN plus invalid exception",
2597 __imag__ result);
2599 result = FUNC(cexp) (BUILD_COMPLEX (100.0, plus_infty));
2600 check_isnan_exc ("real(cexp(100.0 + i inf)) = NaN plus invalid exception",
2601 __real__ result, INVALID_EXCEPTION);
2602 check_isnan ("imag(cexp(100.0 + i inf)) = NaN plus invalid exception",
2603 __imag__ result);
2604 result = FUNC(cexp) (BUILD_COMPLEX (-100.0, plus_infty));
2605 check_isnan_exc ("real(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2606 __real__ result, INVALID_EXCEPTION);
2607 check_isnan ("imag(cexp(-100.0 + i inf)) = NaN plus invalid exception",
2608 __imag__ result);
2609 result = FUNC(cexp) (BUILD_COMPLEX (100.0, minus_infty));
2610 check_isnan_exc ("real(cexp(100.0 - i inf)) = NaN plus invalid exception",
2611 __real__ result, INVALID_EXCEPTION);
2612 check_isnan ("imag(cexp(100.0 - i inf)) = NaN plus invalid exception",
2613 __imag__ result);
2614 result = FUNC(cexp) (BUILD_COMPLEX (-100.0, minus_infty));
2615 check_isnan_exc ("real(cexp(-100.0 - i inf)) = NaN plus invalid exception",
2616 __real__ result, INVALID_EXCEPTION);
2617 check_isnan ("imag(cexp(-100.0 - i inf)) = NaN", __imag__ result);
2619 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 2.0));
2620 check ("real(cexp(-inf + 2.0i)) = -0", __real__ result, minus_zero);
2621 check ("imag(cexp(-inf + 2.0i)) = 0", __imag__ result, 0);
2622 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 4.0));
2623 check ("real(cexp(-inf + 4.0i)) = -0", __real__ result, minus_zero);
2624 check ("imag(cexp(-inf + 4.0i)) = -0", __imag__ result, minus_zero);
2626 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 2.0));
2627 check_isinfn ("real(cexp(+inf + 2.0i)) = -inf", __real__ result);
2628 check_isinfp ("imag(cexp(+inf + 2.0i)) = +inf", __imag__ result);
2629 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 4.0));
2630 check_isinfn ("real(cexp(+inf + 4.0i)) = -inf", __real__ result);
2631 check_isinfn ("imag(cexp(+inf + 4.0i)) = -inf", __imag__ result);
2633 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_infty));
2634 check_isinfp_exc ("real(cexp(+inf + i inf)) = +inf plus invalid exception",
2635 __real__ result, INVALID_EXCEPTION);
2636 check_isnan ("imag(cexp(+inf + i inf)) = NaN plus invalid exception",
2637 __imag__ result);
2638 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_infty));
2639 check_isinfp_exc ("real(cexp(+inf - i inf)) = +inf plus invalid exception",
2640 __real__ result, INVALID_EXCEPTION);
2641 check_isnan ("imag(cexp(+inf - i inf)) = NaN plus invalid exception",
2642 __imag__ result);
2644 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_infty));
2645 check ("real(cexp(-inf + i inf)) = 0", __real__ result, 0);
2646 check ("imag(cexp(-inf + i inf)) = 0", __imag__ result, 0);
2647 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_infty));
2648 check ("real(cexp(-inf - i inf)) = 0", __real__ result, 0);
2649 check ("imag(cexp(-inf - i inf)) = -0", __imag__ result, minus_zero);
2651 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, nan_value));
2652 check ("real(cexp(-inf + i NaN)) = 0", __real__ result, 0);
2653 check ("imag(cexp(-inf + i NaN)) = 0", fabs (__imag__ result), 0);
2655 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, nan_value));
2656 check_isinfp ("real(cexp(+inf + i NaN)) = +inf", __real__ result);
2657 check_isnan ("imag(cexp(+inf + i NaN)) = NaN", __imag__ result);
2659 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 0.0));
2660 check_isnan_maybe_exc ("real(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2661 __real__ result, INVALID_EXCEPTION);
2662 check_isnan ("imag(cexp(NaN + i0)) = NaN plus maybe invalid exception",
2663 __imag__ result);
2664 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
2665 check_isnan_maybe_exc ("real(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2666 __real__ result, INVALID_EXCEPTION);
2667 check_isnan ("imag(cexp(NaN + 1i)) = NaN plus maybe invalid exception",
2668 __imag__ result);
2669 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, plus_infty));
2670 check_isnan_maybe_exc ("real(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2671 __real__ result, INVALID_EXCEPTION);
2672 check_isnan ("imag(cexp(NaN + i inf)) = NaN plus maybe invalid exception",
2673 __imag__ result);
2675 result = FUNC(cexp) (BUILD_COMPLEX (0, nan_value));
2676 check_isnan_maybe_exc ("real(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2677 __real__ result, INVALID_EXCEPTION);
2678 check_isnan ("imag(cexp(0 + i NaN)) = NaN plus maybe invalid exception",
2679 __imag__ result);
2680 result = FUNC(cexp) (BUILD_COMPLEX (1, nan_value));
2681 check_isnan_maybe_exc ("real(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2682 __real__ result, INVALID_EXCEPTION);
2683 check_isnan ("imag(cexp(1 + i NaN)) = NaN plus maybe invalid exception",
2684 __imag__ result);
2686 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, nan_value));
2687 check_isnan ("real(cexp(NaN + i NaN)) = NaN", __real__ result);
2688 check_isnan ("imag(cexp(NaN + i NaN)) = NaN", __imag__ result);
2690 result = FUNC(cexp) (BUILD_COMPLEX (0.7, 1.2));
2691 check_eps ("real(cexp(0.7 + i 1.2)) == 0.72969...", __real__ result,
2692 0.7296989091503236012L, CHOOSE (6e-17L, 2e-16, 2e-7));
2693 check_eps ("imag(cexp(0.7 + i 1.2)) == 1.87689...", __imag__ result,
2694 1.8768962328348102821L, CHOOSE (2e-16L, 4.5e-16, 3e-7));
2696 result = FUNC(cexp) (BUILD_COMPLEX (-2, -3));
2697 check_eps ("real(cexp(-2 - i 3)) == -0.13398...", __real__ result,
2698 -0.1339809149295426134L, CHOOSE (6.8e-20L, 2.8e-17, 2e-8));
2699 check_eps ("imag(cexp(-2 - i 3)) == -0.01909...", __imag__ result,
2700 -0.0190985162611351964L, CHOOSE (4e-20L, 3.5e-18, 2e-9));
2704 static void
2705 csin_test (void)
2707 __complex__ MATHTYPE result;
2709 result = FUNC(csin) (BUILD_COMPLEX (0.0, 0.0));
2710 check ("real(csin(0 + 0i)) = 0", __real__ result, 0);
2711 check ("imag(csin(0 + 0i)) = 0", __imag__ result, 0);
2712 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, 0.0));
2713 check ("real(csin(-0 + 0i)) = -0", __real__ result, minus_zero);
2714 check ("imag(csin(-0 + 0i)) = 0", __imag__ result, 0);
2715 result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_zero));
2716 check ("real(csin(0 - 0i)) = 0", __real__ result, 0);
2717 check ("imag(csin(0 - 0i)) = -0", __imag__ result, minus_zero);
2718 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_zero));
2719 check ("real(csin(-0 - 0i)) = -0", __real__ result, minus_zero);
2720 check ("imag(csin(-0 - 0i)) = -0", __imag__ result, minus_zero);
2722 result = FUNC(csin) (BUILD_COMPLEX (0.0, plus_infty));
2723 check ("real(csin(0 + i Inf)) = 0", __real__ result, 0);
2724 check_isinfp ("imag(csin(0 + i Inf)) = +Inf", __imag__ result);
2725 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, plus_infty));
2726 check ("real(csin(-0 + i Inf)) = -0", __real__ result, minus_zero);
2727 check_isinfp ("imag(csin(-0 + i Inf)) = +Inf", __imag__ result);
2728 result = FUNC(csin) (BUILD_COMPLEX (0.0, minus_infty));
2729 check ("real(csin(0 - i Inf)) = 0", __real__ result, 0);
2730 check_isinfn ("imag(csin(0 - i Inf)) = -Inf", __imag__ result);
2731 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, minus_infty));
2732 check ("real(csin(-0 - i Inf)) = -0", __real__ result, minus_zero);
2733 check_isinfn ("imag(csin(-0 - i Inf)) = -Inf", __imag__ result);
2735 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 0.0));
2736 check_isnan_exc ("real(csin(+Inf + 0i)) = NaN plus invalid exception",
2737 __real__ result, INVALID_EXCEPTION);
2738 check ("imag(csin(+Inf + 0i)) = +-0 plus invalid exception",
2739 FUNC(fabs) (__imag__ result), 0);
2740 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 0.0));
2741 check_isnan_exc ("real(csin(-Inf + 0i)) = NaN plus invalid exception",
2742 __real__ result, INVALID_EXCEPTION);
2743 check ("imag(csin(-Inf + 0i)) = +-0 plus invalid exception",
2744 FUNC(fabs) (__imag__ result), 0);
2745 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_zero));
2746 check_isnan_exc ("real(csin(+Inf - 0i)) = NaN plus invalid exception",
2747 __real__ result, INVALID_EXCEPTION);
2748 check ("imag(csin(+Inf - 0i)) = +-0 plus invalid exception",
2749 FUNC(fabs) (__imag__ result), 0.0);
2750 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_zero));
2751 check_isnan_exc ("real(csin(-Inf - 0i)) = NaN plus invalid exception",
2752 __real__ result, INVALID_EXCEPTION);
2753 check ("imag(csin(-Inf - 0i)) = +-0 plus invalid exception",
2754 FUNC(fabs) (__imag__ result), 0.0);
2756 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, plus_infty));
2757 check_isnan_exc ("real(csin(+Inf + i Inf)) = NaN plus invalid exception",
2758 __real__ result, INVALID_EXCEPTION);
2759 check_isinfp ("imag(csin(+Inf + i Inf)) = +-Inf plus invalid exception",
2760 FUNC(fabs) (__imag__ result));
2761 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, plus_infty));
2762 check_isnan_exc ("real(csin(-Inf + i Inf)) = NaN plus invalid exception",
2763 __real__ result, INVALID_EXCEPTION);
2764 check_isinfp ("imag(csin(-Inf + i Inf)) = +-Inf plus invalid exception",
2765 FUNC(fabs) (__imag__ result));
2766 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, minus_infty));
2767 check_isnan_exc ("real(csin(Inf - i Inf)) = NaN plus invalid exception",
2768 __real__ result, INVALID_EXCEPTION);
2769 check_isinfp ("imag(csin(Inf - i Inf)) = +-Inf plus invalid exception",
2770 FUNC(fabs) (__imag__ result));
2771 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, minus_infty));
2772 check_isnan_exc ("real(csin(-Inf - i Inf)) = NaN plus invalid exception",
2773 __real__ result, INVALID_EXCEPTION);
2774 check_isinfp ("imag(csin(-Inf - i Inf)) = +-Inf plus invalid exception",
2775 FUNC(fabs) (__imag__ result));
2777 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, 6.75));
2778 check_isnan_exc ("real(csin(+Inf + i 6.75)) = NaN plus invalid exception",
2779 __real__ result, INVALID_EXCEPTION);
2780 check_isnan ("imag(csin(+Inf + i6.75)) = NaN plus invalid exception",
2781 __imag__ result);
2782 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, -6.75));
2783 check_isnan_exc ("real(csin(+Inf - i 6.75)) = NaN plus invalid exception",
2784 __real__ result, INVALID_EXCEPTION);
2785 check_isnan ("imag(csin(+Inf - i6.75)) = NaN plus invalid exception",
2786 __imag__ result);
2787 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, 6.75));
2788 check_isnan_exc ("real(csin(-Inf + i6.75)) = NaN plus invalid exception",
2789 __real__ result, INVALID_EXCEPTION);
2790 check_isnan ("imag(csin(-Inf + i6.75)) = NaN plus invalid exception",
2791 __imag__ result);
2792 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, -6.75));
2793 check_isnan_exc ("real(csin(-Inf - i6.75)) = NaN plus invalid exception",
2794 __real__ result, INVALID_EXCEPTION);
2795 check_isnan ("imag(csin(-Inf - i6.75)) = NaN plus invalid exception",
2796 __imag__ result);
2798 result = FUNC(csin) (BUILD_COMPLEX (4.625, plus_infty));
2799 check_isinfn ("real(csin(4.625 + i Inf)) = -Inf", __real__ result);
2800 check_isinfn ("imag(csin(4.625 + i Inf)) = -Inf", __imag__ result);
2801 result = FUNC(csin) (BUILD_COMPLEX (4.625, minus_infty));
2802 check_isinfn ("real(csin(4.625 - i Inf)) = -Inf", __real__ result);
2803 check_isinfp ("imag(csin(4.625 - i Inf)) = +Inf", __imag__ result);
2804 result = FUNC(csin) (BUILD_COMPLEX (-4.625, plus_infty));
2805 check_isinfp ("real(csin(-4.625 + i Inf)) = +Inf", __real__ result);
2806 check_isinfn ("imag(csin(-4.625 + i Inf)) = -Inf", __imag__ result);
2807 result = FUNC(csin) (BUILD_COMPLEX (-4.625, minus_infty));
2808 check_isinfp ("real(csin(-4.625 - i Inf)) = +Inf", __real__ result);
2809 check_isinfp ("imag(csin(-4.625 - i Inf)) = +Inf", __imag__ result);
2811 result = FUNC(csin) (BUILD_COMPLEX (nan_value, 0.0));
2812 check_isnan ("real(csin(NaN + i0)) = NaN", __real__ result);
2813 check ("imag(csin(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2814 result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_zero));
2815 check_isnan ("real(csin(NaN - i0)) = NaN", __real__ result);
2816 check ("imag(csin(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
2818 result = FUNC(csin) (BUILD_COMPLEX (nan_value, plus_infty));
2819 check_isnan ("real(csin(NaN + i Inf)) = NaN", __real__ result);
2820 check_isinfp ("imag(csin(NaN + i Inf)) = +-Inf",
2821 FUNC(fabs) (__imag__ result));
2822 result = FUNC(csin) (BUILD_COMPLEX (nan_value, minus_infty));
2823 check_isnan ("real(csin(NaN - i Inf)) = NaN", __real__ result);
2824 check_isinfp ("real(csin(NaN - i Inf)) = +-Inf",
2825 FUNC(fabs) (__imag__ result));
2827 result = FUNC(csin) (BUILD_COMPLEX (nan_value, 9.0));
2828 check_isnan_maybe_exc ("real(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2829 __real__ result, INVALID_EXCEPTION);
2830 check_isnan ("imag(csin(NaN + i9.0)) = NaN plus maybe invalid exception",
2831 __imag__ result);
2832 result = FUNC(csin) (BUILD_COMPLEX (nan_value, -9.0));
2833 check_isnan_maybe_exc ("real(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2834 __real__ result, INVALID_EXCEPTION);
2835 check_isnan ("imag(csin(NaN - i9.0)) = NaN plus maybe invalid exception",
2836 __imag__ result);
2838 result = FUNC(csin) (BUILD_COMPLEX (0.0, nan_value));
2839 check ("real(csin(0 + i NaN))", __real__ result, 0.0);
2840 check_isnan ("imag(csin(0 + i NaN)) = NaN", __imag__ result);
2841 result = FUNC(csin) (BUILD_COMPLEX (minus_zero, nan_value));
2842 check ("real(csin(-0 + i NaN)) = -0", __real__ result, minus_zero);
2843 check_isnan ("imag(csin(-0 + NaN)) = NaN", __imag__ result);
2845 result = FUNC(csin) (BUILD_COMPLEX (10.0, nan_value));
2846 check_isnan_maybe_exc ("real(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2847 __real__ result, INVALID_EXCEPTION);
2848 check_isnan ("imag(csin(10 + i NaN)) = NaN plus maybe invalid exception",
2849 __imag__ result);
2850 result = FUNC(csin) (BUILD_COMPLEX (nan_value, -10.0));
2851 check_isnan_maybe_exc ("real(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2852 __real__ result, INVALID_EXCEPTION);
2853 check_isnan ("imag(csin(-10 + i NaN)) = NaN plus maybe invalid exception",
2854 __imag__ result);
2856 result = FUNC(csin) (BUILD_COMPLEX (plus_infty, nan_value));
2857 check_isnan_maybe_exc ("real(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2858 __real__ result, INVALID_EXCEPTION);
2859 check_isnan ("imag(csin(+Inf + i NaN)) = NaN plus maybe invalid exception",
2860 __imag__ result);
2861 result = FUNC(csin) (BUILD_COMPLEX (minus_infty, nan_value));
2862 check_isnan_maybe_exc ("real(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2863 __real__ result, INVALID_EXCEPTION);
2864 check_isnan ("imag(csin(-Inf + i NaN)) = NaN plus maybe invalid exception",
2865 __imag__ result);
2867 result = FUNC(csin) (BUILD_COMPLEX (nan_value, nan_value));
2868 check_isnan ("real(csin(NaN + i NaN)) = NaN", __real__ result);
2869 check_isnan ("imag(csin(NaN + i NaN)) = NaN", __imag__ result);
2871 result = FUNC(csin) (BUILD_COMPLEX (0.7, 1.2));
2872 check_eps ("real(csin(0.7 + i 1.2)) = 1.166456341...", __real__ result,
2873 1.1664563419657581376L, CHOOSE (2e-16L, 2.3e-16, 0));
2874 check_eps ("imag(csin(0.7 + i 1.2)) = 1.154499724...", __imag__ result,
2875 1.1544997246948547371L, CHOOSE (2e-17L, 0, 2e-7));
2877 result = FUNC(csin) (BUILD_COMPLEX (-2, -3));
2878 check_eps ("real(csin(-2 - i 3)) == -9.15449...", __real__ result,
2879 -9.1544991469114295734L, CHOOSE (4e-18L, 1.8e-15, 1e-6));
2880 check_eps ("imag(csin(-2 - i 3)) == -4.16890...", __imag__ result,
2881 4.1689069599665643507L, CHOOSE (2e-17L, 0, 5e-7));
2885 static void
2886 csinh_test (void)
2888 __complex__ MATHTYPE result;
2890 result = FUNC(csinh) (BUILD_COMPLEX (0.0, 0.0));
2891 check ("real(csinh(0 + 0i)) = 0", __real__ result, 0);
2892 check ("imag(csinh(0 + 0i)) = 0", __imag__ result, 0);
2893 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, 0.0));
2894 check ("real(csinh(-0 + 0i)) = -0", __real__ result, minus_zero);
2895 check ("imag(csinh(-0 + 0i)) = 0", __imag__ result, 0);
2896 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_zero));
2897 check ("real(csinh(0 - 0i)) = 0", __real__ result, 0);
2898 check ("imag(csinh(0 - 0i)) = -0", __imag__ result, minus_zero);
2899 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_zero));
2900 check ("real(csinh(-0 - 0i)) = -0", __real__ result, minus_zero);
2901 check ("imag(csinh(-0 - 0i)) = -0", __imag__ result, minus_zero);
2903 result = FUNC(csinh) (BUILD_COMPLEX (0.0, plus_infty));
2904 check_exc ("real(csinh(0 + i Inf)) = +-0 plus invalid exception",
2905 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2906 check_isnan ("imag(csinh(0 + i Inf)) = NaN plus invalid exception",
2907 __imag__ result);
2908 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, plus_infty));
2909 check_exc ("real(csinh(-0 + i Inf)) = +-0 plus invalid exception",
2910 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2911 check_isnan ("imag(csinh(-0 + i Inf)) = NaN plus invalid exception",
2912 __imag__ result);
2913 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_infty));
2914 check_exc ("real(csinh(0 - i Inf)) = +-0 plus invalid exception",
2915 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2916 check_isnan ("imag(csinh(0 - i Inf)) = NaN plus invalid exception",
2917 __imag__ result);
2918 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_infty));
2919 check_exc ("real(csinh(-0 - i Inf)) = +-0 plus invalid exception",
2920 FUNC(fabs) (__real__ result), 0, INVALID_EXCEPTION);
2921 check_isnan ("imag(csinh(-0 - i Inf)) = NaN plus invalid exception",
2922 __imag__ result);
2924 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 0.0));
2925 check_isinfp ("real(csinh(+Inf + 0i)) = +Inf", __real__ result);
2926 check ("imag(csinh(+Inf + 0i)) = 0", __imag__ result, 0);
2927 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 0.0));
2928 check_isinfn ("real(csinh(-Inf + 0i)) = -Inf", __real__ result);
2929 check ("imag(csinh(-Inf + 0i)) = 0", __imag__ result, 0);
2930 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_zero));
2931 check_isinfp ("real(csinh(+Inf - 0i)) = +Inf", __real__ result);
2932 check ("imag(csinh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
2933 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_zero));
2934 check_isinfn ("real(csinh(-Inf - 0i)) = -Inf", __real__ result);
2935 check ("imag(csinh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
2937 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, plus_infty));
2938 check_isinfp_exc ("real(csinh(+Inf + i Inf)) = +-Inf plus invalid exception",
2939 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2940 check_isnan ("imag(csinh(+Inf + i Inf)) = NaN plus invalid exception",
2941 __imag__ result);
2942 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, plus_infty));
2943 check_isinfp_exc ("real(csinh(-Inf + i Inf)) = +-Inf plus invalid exception",
2944 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2945 check_isnan ("imag(csinh(-Inf + i Inf)) = NaN plus invalid exception",
2946 __imag__ result);
2947 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_infty));
2948 check_isinfp_exc ("real(csinh(Inf - i Inf)) = +-Inf plus invalid exception",
2949 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2950 check_isnan ("imag(csinh(Inf - i Inf)) = NaN plus invalid exception",
2951 __imag__ result);
2952 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_infty));
2953 check_isinfp_exc ("real(csinh(-Inf - i Inf)) = +-Inf plus invalid exception",
2954 FUNC(fabs) (__real__ result), INVALID_EXCEPTION);
2955 check_isnan ("imag(csinh(-Inf - i Inf)) = NaN plus invalid exception",
2956 __imag__ result);
2958 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 4.625));
2959 check_isinfn ("real(csinh(+Inf + i4.625)) = -Inf", __real__ result);
2960 check_isinfn ("imag(csinh(+Inf + i4.625)) = -Inf", __imag__ result);
2961 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 4.625));
2962 check_isinfp ("real(csinh(-Inf + i4.625)) = +Inf", __real__ result);
2963 check_isinfn ("imag(csinh(-Inf + i4.625)) = -Inf", __imag__ result);
2964 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, -4.625));
2965 check_isinfn ("real(csinh(+Inf - i4.625)) = -Inf", __real__ result);
2966 check_isinfp ("imag(csinh(+Inf - i4.625)) = +Inf", __imag__ result);
2967 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, -4.625));
2968 check_isinfp ("real(csinh(-Inf - i4.625)) = +Inf", __real__ result);
2969 check_isinfp ("imag(csinh(-Inf - i4.625)) = +Inf", __imag__ result);
2971 result = FUNC(csinh) (BUILD_COMPLEX (6.75, plus_infty));
2972 check_isnan_exc ("real(csinh(6.75 + i Inf)) = NaN plus invalid exception",
2973 __real__ result, INVALID_EXCEPTION);
2974 check_isnan ("imag(csinh(6.75 + i Inf)) = NaN plus invalid exception",
2975 __imag__ result);
2976 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, plus_infty));
2977 check_isnan_exc ("real(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
2978 __real__ result, INVALID_EXCEPTION);
2979 check_isnan ("imag(csinh(-6.75 + i Inf)) = NaN plus invalid exception",
2980 __imag__ result);
2981 result = FUNC(csinh) (BUILD_COMPLEX (6.75, minus_infty));
2982 check_isnan_exc ("real(csinh(6.75 - i Inf)) = NaN plus invalid exception",
2983 __real__ result, INVALID_EXCEPTION);
2984 check_isnan ("imag(csinh(6.75 - i Inf)) = NaN plus invalid exception",
2985 __imag__ result);
2986 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, minus_infty));
2987 check_isnan_exc ("real(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
2988 __real__ result, INVALID_EXCEPTION);
2989 check_isnan ("imag(csinh(-6.75 - i Inf)) = NaN plus invalid exception",
2990 __imag__ result);
2992 result = FUNC(csinh) (BUILD_COMPLEX (0.0, nan_value));
2993 check ("real(csinh(0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
2994 check_isnan ("imag(csinh(0 + i NaN)) = NaN", __imag__ result);
2995 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, nan_value));
2996 check ("real(csinh(-0 + i NaN)) = +-0", FUNC(fabs) (__real__ result), 0);
2997 check_isnan ("imag(csinh(-0 + i NaN)) = NaN", __imag__ result);
2999 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, nan_value));
3000 check_isinfp ("real(csinh(+Inf + i NaN)) = +-Inf",
3001 FUNC(fabs) (__real__ result));
3002 check_isnan ("imag(csinh(+Inf + i NaN)) = NaN", __imag__ result);
3003 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, nan_value));
3004 check_isinfp ("real(csinh(-Inf + i NaN)) = +-Inf",
3005 FUNC(fabs) (__real__ result));
3006 check_isnan ("imag(csinh(-Inf + i NaN)) = NaN", __imag__ result);
3008 result = FUNC(csinh) (BUILD_COMPLEX (9.0, nan_value));
3009 check_isnan_maybe_exc ("real(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3010 __real__ result, INVALID_EXCEPTION);
3011 check_isnan ("imag(csinh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3012 __imag__ result);
3013 result = FUNC(csinh) (BUILD_COMPLEX (-9.0, nan_value));
3014 check_isnan_maybe_exc ("real(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3015 __real__ result, INVALID_EXCEPTION);
3016 check_isnan ("imag(csinh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3017 __imag__ result);
3019 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 0.0));
3020 check_isnan ("real(csinh(NaN + i0)) = NaN", __real__ result);
3021 check ("imag(csinh(NaN + i0)) = 0", __imag__ result, 0.0);
3022 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_zero));
3023 check_isnan ("real(csinh(NaN - i0)) = NaN", __real__ result);
3024 check ("imag(csinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3026 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 10.0));
3027 check_isnan_maybe_exc ("real(csinh(NaN + i10)) = NaN plus maybe invalid exception",
3028 __real__ result, INVALID_EXCEPTION);
3029 check_isnan ("imag(csinh(NaN + i10)) = NaN plus maybe invalid exception",
3030 __imag__ result);
3031 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, -10.0));
3032 check_isnan_maybe_exc ("real(csinh(NaN - i10)) = NaN plus maybe invalid exception",
3033 __real__ result, INVALID_EXCEPTION);
3034 check_isnan ("imag(csinh(NaN - i10)) = NaN plus maybe invalid exception",
3035 __imag__ result);
3037 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, plus_infty));
3038 check_isnan_maybe_exc ("real(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
3039 __real__ result, INVALID_EXCEPTION);
3040 check_isnan ("imag(csinh(NaN + i Inf)) = NaN plus maybe invalid exception",
3041 __imag__ result);
3042 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_infty));
3043 check_isnan_maybe_exc ("real(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
3044 __real__ result, INVALID_EXCEPTION);
3045 check_isnan ("imag(csinh(NaN - i Inf)) = NaN plus maybe invalid exception",
3046 __imag__ result);
3048 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, nan_value));
3049 check_isnan ("real(csinh(NaN + i NaN)) = NaN", __real__ result);
3050 check_isnan ("imag(csinh(NaN + i NaN)) = NaN", __imag__ result);
3052 result = FUNC(csinh) (BUILD_COMPLEX (0.7, 1.2));
3053 check_eps ("real(csinh(0.7 + i 1.2)) = 0.274878686...", __real__ result,
3054 0.27487868678117583582L, CHOOSE (2e-17L, 6e-17, 3e-8));
3055 check_eps ("imag(csinh(0.7 + i 1.2)) = 1.169866572...", __imag__ result,
3056 1.1698665727426565139L, CHOOSE (6e-17L, 2.3e-16, 2e-7));
3058 result = FUNC(csinh) (BUILD_COMPLEX (-2, -3));
3059 check_eps ("real(csinh(-2 - i 3)) == -3.59056...", __real__ result,
3060 3.5905645899857799520L, CHOOSE (7e-19L, 5e-16, 3e-7));
3061 check_eps ("imag(csinh(-2 - i 3)) == -0.53092...", __imag__ result,
3062 -0.5309210862485198052L, CHOOSE (3e-19L, 2e-16, 6e-8));
3066 static void
3067 ccos_test (void)
3069 __complex__ MATHTYPE result;
3071 result = FUNC(ccos) (BUILD_COMPLEX (0.0, 0.0));
3072 check ("real(ccos(0 + 0i)) = 1.0", __real__ result, 1.0);
3073 check ("imag(ccos(0 + 0i)) = -0", __imag__ result, minus_zero);
3074 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, 0.0));
3075 check ("real(ccos(-0 + 0i)) = 1.0", __real__ result, 1.0);
3076 check ("imag(ccos(-0 + 0i)) = 0", __imag__ result, 0.0);
3077 result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_zero));
3078 check ("real(ccos(0 - 0i)) = 1.0", __real__ result, 1.0);
3079 check ("imag(ccos(0 - 0i)) = 0", __imag__ result, 0.0);
3080 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_zero));
3081 check ("real(ccos(-0 - 0i)) = 1.0", __real__ result, 1.0);
3082 check ("imag(ccos(-0 - 0i)) = -0", __imag__ result, minus_zero);
3084 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 0.0));
3085 check_isnan_exc ("real(ccos(+Inf + i0)) = NaN plus invalid exception",
3086 __real__ result, INVALID_EXCEPTION);
3087 check ("imag(ccos(Inf + i0)) = +-0 plus invalid exception",
3088 FUNC(fabs) (__imag__ result), 0);
3089 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_zero));
3090 check_isnan_exc ("real(ccos(Inf - i0)) = NaN plus invalid exception",
3091 __real__ result, INVALID_EXCEPTION);
3092 check ("imag(ccos(Inf - i0)) = +-0 plus invalid exception",
3093 FUNC(fabs) (__imag__ result), 0);
3094 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 0.0));
3095 check_isnan_exc ("real(ccos(-Inf + i0)) = NaN plus invalid exception",
3096 __real__ result, INVALID_EXCEPTION);
3097 check ("imag(ccos(-Inf + i0)) = +-0 plus invalid exception",
3098 FUNC(fabs) (__imag__ result), 0);
3099 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_zero));
3100 check_isnan_exc ("real(ccos(-Inf - i0)) = NaN plus invalid exception",
3101 __real__ result, INVALID_EXCEPTION);
3102 check ("imag(ccos(-Inf - i0)) = +-0 plus invalid exception",
3103 FUNC(fabs) (__imag__ result), 0);
3105 result = FUNC(ccos) (BUILD_COMPLEX (0.0, plus_infty));
3106 check_isinfp ("real(ccos(0 + i Inf)) = +Inf", __real__ result);
3107 check ("imag(ccos(0 + i Inf)) = -0", __imag__ result, minus_zero);
3108 result = FUNC(ccos) (BUILD_COMPLEX (0.0, minus_infty));
3109 check_isinfp ("real(ccos(0 - i Inf)) = +Inf", __real__ result);
3110 check ("imag(ccos(0 - i Inf)) = 0", __imag__ result, 0);
3111 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, plus_infty));
3112 check_isinfp ("real(ccos(-0 + i Inf)) = +Inf", __real__ result);
3113 check ("imag(ccos(-0 + i Inf)) = 0", __imag__ result, 0.0);
3114 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, minus_infty));
3115 check_isinfp ("real(ccos(-0 - i Inf)) = +Inf", __real__ result);
3116 check ("imag(ccos(-0 - i Inf)) = -0", __imag__ result, minus_zero);
3118 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, plus_infty));
3119 check_isinfp_exc ("real(ccos(+Inf + i Inf)) = +Inf plus invalid exception",
3120 __real__ result, INVALID_EXCEPTION);
3121 check_isnan ("imag(ccos(+Inf + i Inf)) = NaN plus invalid exception",
3122 __imag__ result);
3123 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, plus_infty));
3124 check_isinfp_exc ("real(ccos(-Inf + i Inf)) = +Inf plus invalid exception",
3125 __real__ result, INVALID_EXCEPTION);
3126 check_isnan ("imag(ccos(-Inf + i Inf)) = NaN plus invalid exception",
3127 __imag__ result);
3128 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, minus_infty));
3129 check_isinfp_exc ("real(ccos(Inf - i Inf)) = +Inf plus invalid exception",
3130 __real__ result, INVALID_EXCEPTION);
3131 check_isnan ("imag(ccos(Inf - i Inf)) = NaN plus invalid exception",
3132 __imag__ result);
3133 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, minus_infty));
3134 check_isinfp_exc ("real(ccos(-Inf - i Inf)) = +Inf plus invalid exception",
3135 __real__ result, INVALID_EXCEPTION);
3136 check_isnan ("imag(ccos(-Inf - i Inf)) = NaN plus invalid exception",
3137 __imag__ result);
3139 result = FUNC(ccos) (BUILD_COMPLEX (4.625, plus_infty));
3140 check_isinfn ("real(ccos(4.625 + i Inf)) = -Inf", __real__ result);
3141 check_isinfp ("imag(ccos(4.625 + i Inf)) = +Inf", __imag__ result);
3142 result = FUNC(ccos) (BUILD_COMPLEX (4.625, minus_infty));
3143 check_isinfn ("real(ccos(4.625 - i Inf)) = -Inf", __real__ result);
3144 check_isinfn ("imag(ccos(4.625 - i Inf)) = -Inf", __imag__ result);
3145 result = FUNC(ccos) (BUILD_COMPLEX (-4.625, plus_infty));
3146 check_isinfn ("real(ccos(-4.625 + i Inf)) = -Inf", __real__ result);
3147 check_isinfn ("imag(ccos(-4.625 + i Inf)) = -Inf", __imag__ result);
3148 result = FUNC(ccos) (BUILD_COMPLEX (-4.625, minus_infty));
3149 check_isinfn ("real(ccos(-4.625 - i Inf)) = -Inf", __real__ result);
3150 check_isinfp ("imag(ccos(-4.625 - i Inf)) = +Inf", __imag__ result);
3152 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, 6.75));
3153 check_isnan_exc ("real(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3154 __real__ result, INVALID_EXCEPTION);
3155 check_isnan ("imag(ccos(+Inf + i6.75)) = NaN plus invalid exception",
3156 __imag__ result);
3157 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, -6.75));
3158 check_isnan_exc ("real(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3159 __real__ result, INVALID_EXCEPTION);
3160 check_isnan ("imag(ccos(+Inf - i6.75)) = NaN plus invalid exception",
3161 __imag__ result);
3162 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, 6.75));
3163 check_isnan_exc ("real(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3164 __real__ result, INVALID_EXCEPTION);
3165 check_isnan ("imag(ccos(-Inf + i6.75)) = NaN plus invalid exception",
3166 __imag__ result);
3167 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, -6.75));
3168 check_isnan_exc ("real(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3169 __real__ result, INVALID_EXCEPTION);
3170 check_isnan ("imag(ccos(-Inf - i6.75)) = NaN plus invalid exception",
3171 __imag__ result);
3173 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 0.0));
3174 check_isnan ("real(ccos(NaN + i0)) = NaN", __real__ result);
3175 check ("imag(ccos(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3176 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_zero));
3177 check_isnan ("real(ccos(NaN - i0)) = NaN", __real__ result);
3178 check ("imag(ccos(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0);
3180 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, plus_infty));
3181 check_isinfp ("real(ccos(NaN + i Inf)) = +Inf", __real__ result);
3182 check_isnan ("imag(ccos(NaN + i Inf)) = NaN", __imag__ result);
3183 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, minus_infty));
3184 check_isinfp ("real(ccos(NaN - i Inf)) = +Inf", __real__ result);
3185 check_isnan ("imag(ccos(NaN - i Inf)) = NaN", __imag__ result);
3187 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, 9.0));
3188 check_isnan_maybe_exc ("real(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3189 __real__ result, INVALID_EXCEPTION);
3190 check_isnan ("imag(ccos(NaN + i9.0)) = NaN plus maybe invalid exception",
3191 __imag__ result);
3192 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, -9.0));
3193 check_isnan_maybe_exc ("real(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3194 __real__ result, INVALID_EXCEPTION);
3195 check_isnan ("imag(ccos(NaN - i9.0)) = NaN plus maybe invalid exception",
3196 __imag__ result);
3198 result = FUNC(ccos) (BUILD_COMPLEX (0.0, nan_value));
3199 check_isnan ("real(ccos(0 + i NaN)) = NaN", __real__ result);
3200 check ("imag(ccos(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3201 result = FUNC(ccos) (BUILD_COMPLEX (minus_zero, nan_value));
3202 check_isnan ("real(ccos(-0 + i NaN)) = NaN", __real__ result);
3203 check ("imag(ccos(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3205 result = FUNC(ccos) (BUILD_COMPLEX (10.0, nan_value));
3206 check_isnan_maybe_exc ("real(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3207 __real__ result, INVALID_EXCEPTION);
3208 check_isnan ("imag(ccos(10 + i NaN)) = NaN plus maybe invalid exception",
3209 __imag__ result);
3210 result = FUNC(ccos) (BUILD_COMPLEX (-10.0, nan_value));
3211 check_isnan_maybe_exc ("real(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3212 __real__ result, INVALID_EXCEPTION);
3213 check_isnan ("imag(ccos(-10 + i NaN)) = NaN plus maybe invalid exception",
3214 __imag__ result);
3216 result = FUNC(ccos) (BUILD_COMPLEX (plus_infty, nan_value));
3217 check_isnan_maybe_exc ("real(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3218 __real__ result, INVALID_EXCEPTION);
3219 check_isnan ("imag(ccos(+Inf + i NaN)) = NaN plus maybe invalid exception",
3220 __imag__ result);
3221 result = FUNC(ccos) (BUILD_COMPLEX (minus_infty, nan_value));
3222 check_isnan_maybe_exc ("real(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3223 __real__ result, INVALID_EXCEPTION);
3224 check_isnan ("imag(ccos(-Inf + i NaN)) = NaN plus maybe invalid exception",
3225 __imag__ result);
3227 result = FUNC(ccos) (BUILD_COMPLEX (nan_value, nan_value));
3228 check_isnan ("real(ccos(NaN + i NaN)) = NaN", __real__ result);
3229 check_isnan ("imag(ccos(NaN + i NaN)) = NaN", __imag__ result);
3231 result = FUNC(ccos) (BUILD_COMPLEX (0.7, 1.2));
3232 check_eps ("real(ccos(0.7 + i 1.2)) = 1.384865764...", __real__ result,
3233 1.3848657645312111080L, CHOOSE (4e-18L, 3e-16, 2e-7));
3234 check_eps ("imag(ccos(0.7 + i 1.2)) = -0.972421703...", __imag__ result,
3235 -0.97242170335830028619L, CHOOSE (2e-16L, 2e-16, 0));
3237 result = FUNC(ccos) (BUILD_COMPLEX (-2, -3));
3238 check_eps ("real(ccos(-2 - i 3)) == -4.18962...", __real__ result,
3239 -4.1896256909688072301L, CHOOSE (2e-17L, 8.9e-16, 5e-7));
3240 check_eps ("imag(ccos(-2 - i 3)) == -9.10922...", __imag__ result,
3241 -9.1092278937553365979L, CHOOSE (3e-18L, 0, 1e-6));
3245 static void
3246 ccosh_test (void)
3248 __complex__ MATHTYPE result;
3250 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, 0.0));
3251 check ("real(ccosh(0 + 0i)) = 1.0", __real__ result, 1.0);
3252 check ("imag(ccosh(0 + 0i)) = 0", __imag__ result, 0);
3253 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, 0.0));
3254 check ("real(ccosh(-0 + 0i)) = 1.0", __real__ result, 1.0);
3255 check ("imag(ccosh(-0 + 0i)) = -0", __imag__ result, minus_zero);
3256 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_zero));
3257 check ("real(ccosh(0 - 0i)) = 1.0", __real__ result, 1.0);
3258 check ("imag(ccosh(0 - 0i)) = -0", __imag__ result, minus_zero);
3259 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3260 check ("real(ccosh(-0 - 0i)) = 1.0", __real__ result, 1.0);
3261 check ("imag(ccosh(-0 - 0i)) = 0", __imag__ result, 0.0);
3263 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, plus_infty));
3264 check_isnan_exc ("real(ccosh(0 + i Inf)) = NaN plus invalid exception",
3265 __real__ result, INVALID_EXCEPTION);
3266 check ("imag(ccosh(0 + i Inf)) = +-0 plus invalid exception",
3267 FUNC(fabs) (__imag__ result), 0);
3268 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, plus_infty));
3269 check_isnan_exc ("real(ccosh(-0 + i Inf)) = NaN plus invalid exception",
3270 __real__ result, INVALID_EXCEPTION);
3271 check ("imag(ccosh(-0 + i Inf)) = +-0 plus invalid exception",
3272 FUNC(fabs) (__imag__ result), 0);
3273 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_infty));
3274 check_isnan_exc ("real(ccosh(0 - i Inf)) = NaN plus invalid exception",
3275 __real__ result, INVALID_EXCEPTION);
3276 check ("imag(ccosh(0 - i Inf)) = +-0 plus invalid exception",
3277 FUNC(fabs) (__imag__ result), 0);
3278 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_infty));
3279 check_isnan_exc ("real(ccosh(-0 - i Inf)) = NaN plus invalid exception",
3280 __real__ result, INVALID_EXCEPTION);
3281 check ("imag(ccosh(-0 - i Inf)) = +-0 plus invalid exception",
3282 FUNC(fabs) (__imag__ result), 0);
3284 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 0.0));
3285 check_isinfp ("real(ccosh(+Inf + 0i)) = +Inf", __real__ result);
3286 check ("imag(ccosh(+Inf + 0i)) = 0", __imag__ result, 0);
3287 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 0.0));
3288 check_isinfp ("real(ccosh(-Inf + 0i)) = +Inf", __real__ result);
3289 check ("imag(ccosh(-Inf + 0i)) = -0", __imag__ result, minus_zero);
3290 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3291 check_isinfp ("real(ccosh(+Inf - 0i)) = +Inf", __real__ result);
3292 check ("imag(ccosh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
3293 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3294 check_isinfp ("real(ccosh(-Inf - 0i)) = +Inf", __real__ result);
3295 check ("imag(ccosh(-Inf - 0i)) = 0", __imag__ result, 0.0);
3297 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3298 check_isinfp_exc ("real(ccosh(+Inf + i Inf)) = +Inf plus invalid exception",
3299 __real__ result, INVALID_EXCEPTION);
3300 check_isnan ("imag(ccosh(+Inf + i Inf)) = NaN plus invalid exception",
3301 __imag__ result);
3302 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3303 check_isinfp_exc ("real(ccosh(-Inf + i Inf)) = +Inf plus invalid exception",
3304 __real__ result, INVALID_EXCEPTION);
3305 check_isnan ("imag(ccosh(-Inf + i Inf)) = NaN plus invalid exception",
3306 __imag__ result);
3307 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3308 check_isinfp_exc ("real(ccosh(Inf - i Inf)) = +Inf plus invalid exception",
3309 __real__ result, INVALID_EXCEPTION);
3310 check_isnan ("imag(ccosh(Inf - i Inf)) = NaN plus invalid exception",
3311 __imag__ result);
3312 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3313 check_isinfp_exc ("real(ccosh(-Inf - i Inf)) = +Inf plus invalid exception",
3314 __real__ result, INVALID_EXCEPTION);
3315 check_isnan ("imag(ccosh(-Inf - i Inf)) = NaN plus invalid exception",
3316 __imag__ result);
3318 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 4.625));
3319 check_isinfn ("real(ccosh(+Inf + i4.625)) = -Inf", __real__ result);
3320 check_isinfn ("imag(ccosh(+Inf + i4.625)) = -Inf", __imag__ result);
3321 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 4.625));
3322 check_isinfn ("real(ccosh(-Inf + i4.625)) = -Inf", __real__ result);
3323 check_isinfp ("imag(ccosh(-Inf + i4.625)) = Inf", __imag__ result);
3324 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, -4.625));
3325 check_isinfn ("real(ccosh(+Inf - i4.625)) = -Inf", __real__ result);
3326 check_isinfp ("imag(ccosh(+Inf - i4.625)) = +Inf", __imag__ result);
3327 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, -4.625));
3328 check_isinfn ("real(ccosh(-Inf - i4.625)) = -Inf", __real__ result);
3329 check_isinfn ("imag(ccosh(-Inf - i4.625)) = -Inf", __imag__ result);
3331 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, plus_infty));
3332 check_isnan_exc ("real(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3333 __real__ result, INVALID_EXCEPTION);
3334 check_isnan ("imag(ccosh(6.75 + i Inf)) = NaN plus invalid exception",
3335 __imag__ result);
3336 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, plus_infty));
3337 check_isnan_exc ("real(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3338 __real__ result, INVALID_EXCEPTION);
3339 check_isnan ("imag(ccosh(-6.75 + i Inf)) = NaN plus invalid exception",
3340 __imag__ result);
3341 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, minus_infty));
3342 check_isnan_exc ("real(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3343 __real__ result, INVALID_EXCEPTION);
3344 check_isnan ("imag(ccosh(6.75 - i Inf)) = NaN plus invalid exception",
3345 __imag__ result);
3346 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, minus_infty));
3347 check_isnan_exc ("real(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3348 __real__ result, INVALID_EXCEPTION);
3349 check_isnan ("imag(ccosh(-6.75 - i Inf)) = NaN plus invalid exception",
3350 __imag__ result);
3352 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, nan_value));
3353 check_isnan ("real(ccosh(0 + i NaN)) = NaN", __real__ result);
3354 check ("imag(ccosh(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3355 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, nan_value));
3356 check_isnan ("real(ccosh(-0 + i NaN)) = NaN", __real__ result);
3357 check ("imag(ccosh(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
3359 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, nan_value));
3360 check_isinfp ("real(ccosh(+Inf + i NaN)) = +Inf", __real__ result);
3361 check_isnan ("imag(ccosh(+Inf + i NaN)) = NaN", __imag__ result);
3362 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, nan_value));
3363 check_isinfp ("real(ccosh(-Inf + i NaN)) = +Inf", __real__ result);
3364 check_isnan ("imag(ccosh(-Inf + i NaN)) = NaN", __imag__ result);
3366 result = FUNC(ccosh) (BUILD_COMPLEX (9.0, nan_value));
3367 check_isnan_maybe_exc ("real(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3368 __real__ result, INVALID_EXCEPTION);
3369 check_isnan ("imag(ccosh(9.0 + i NaN)) = NaN plus maybe invalid exception",
3370 __imag__ result);
3371 result = FUNC(ccosh) (BUILD_COMPLEX (-9.0, nan_value));
3372 check_isnan_maybe_exc ("real(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3373 __real__ result, INVALID_EXCEPTION);
3374 check_isnan ("imag(ccosh(-9.0 + i NaN)) = NaN plus maybe invalid exception",
3375 __imag__ result);
3377 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 0.0));
3378 check_isnan ("real(ccosh(NaN + i0)) = NaN", __real__ result);
3379 check ("imag(ccosh(NaN + i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3380 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_zero));
3381 check_isnan ("real(ccosh(NaN - i0)) = NaN", __real__ result);
3382 check ("imag(ccosh(NaN - i0)) = +-0", FUNC(fabs) (__imag__ result), 0.0);
3384 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 10.0));
3385 check_isnan_maybe_exc ("real(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3386 __real__ result, INVALID_EXCEPTION);
3387 check_isnan ("imag(ccosh(NaN + i10)) = NaN plus maybe invalid exception",
3388 __imag__ result);
3389 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, -10.0));
3390 check_isnan_maybe_exc ("real(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3391 __real__ result, INVALID_EXCEPTION);
3392 check_isnan ("imag(ccosh(NaN - i10)) = NaN plus maybe invalid exception",
3393 __imag__ result);
3395 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, plus_infty));
3396 check_isnan_maybe_exc ("real(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3397 __real__ result, INVALID_EXCEPTION);
3398 check_isnan ("imag(ccosh(NaN + i Inf)) = NaN plus maybe invalid exception",
3399 __imag__ result);
3400 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_infty));
3401 check_isnan_maybe_exc ("real(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3402 __real__ result, INVALID_EXCEPTION);
3403 check_isnan ("imag(ccosh(NaN - i Inf)) = NaN plus maybe invalid exception",
3404 __imag__ result);
3406 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, nan_value));
3407 check_isnan ("real(ccosh(NaN + i NaN)) = NaN", __real__ result);
3408 check_isnan ("imag(ccosh(NaN + i NaN)) = NaN", __imag__ result);
3410 result = FUNC(ccosh) (BUILD_COMPLEX (0.7, 1.2));
3411 check_eps ("real(ccosh(0.7 + i 1.2)) == 0.45482...", __real__ result,
3412 0.4548202223691477654L, CHOOSE (5e-17L, 6e-17, 9e-8));
3413 check_eps ("imag(ccosh(0.7 + i 1.2)) == 0.70702...", __imag__ result,
3414 0.7070296600921537682L, CHOOSE (7e-17L, 2e-16, 6e-8));
3416 result = FUNC(ccosh) (BUILD_COMPLEX (-2, -3));
3417 check_eps ("real(ccosh(-2 - i 3)) == -3.72454...", __real__ result,
3418 -3.7245455049153225654L, CHOOSE (7e-19L, 4.5e-16, 3e-7));
3419 check_eps ("imag(ccosh(-2 - i 3)) == -0.51182...", __imag__ result,
3420 0.5118225699873846088L, CHOOSE (3e-19L, 2e-16, 6e-8));
3424 static void
3425 cacos_test (void)
3427 __complex__ MATHTYPE result;
3429 result = FUNC(cacos) (BUILD_COMPLEX (0, 0));
3430 check ("real(cacos(0 + i0)) = pi/2", __real__ result, M_PI_2l);
3431 check ("imag(cacos(0 + i0)) = -0", __imag__ result, minus_zero);
3432 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, 0));
3433 check ("real(cacos(-0 + i0)) = pi/2", __real__ result, M_PI_2l);
3434 check ("imag(cacos(-0 + i0)) = -0", __imag__ result, minus_zero);
3435 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_zero));
3436 check ("real(cacos(0 - i0)) = pi/2", __real__ result, M_PI_2l);
3437 check ("imag(cacos(0 - i0)) = 0", __imag__ result, 0);
3438 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, minus_zero));
3439 check ("real(cacos(-0 - i0)) = pi/2", __real__ result, M_PI_2l);
3440 check ("imag(cacos(-0 - i0)) = 0", __imag__ result, 0);
3442 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, plus_infty));
3443 check ("real(cacos(-Inf + i Inf)) = 3*pi/4", __real__ result,
3444 M_PIl - M_PI_4l);
3445 check_isinfn ("imag(cacos(-Inf + i Inf)) = -Inf", __imag__ result);
3446 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_infty));
3447 check ("real(cacos(-Inf - i Inf)) = 3*pi/4", __real__ result,
3448 M_PIl - M_PI_4l);
3449 check_isinfp ("imag(cacos(-Inf - i Inf)) = +Inf", __imag__ result);
3451 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, plus_infty));
3452 check ("real(cacos(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4l);
3453 check_isinfn ("imag(cacos(+Inf + i Inf)) = -Inf", __imag__ result);
3454 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_infty));
3455 check ("real(cacos(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4l);
3456 check_isinfp ("imag(cacos(+Inf - i Inf)) = +Inf", __imag__ result);
3458 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, plus_infty));
3459 check ("real(cacos(-10.0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3460 check_isinfn ("imag(cacos(-10.0 + i Inf)) = -Inf", __imag__ result);
3461 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, minus_infty));
3462 check ("real(cacos(-10.0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3463 check_isinfp ("imag(cacos(-10.0 - i Inf)) = +Inf", __imag__ result);
3464 result = FUNC(cacos) (BUILD_COMPLEX (0, plus_infty));
3465 check ("real(cacos(0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3466 check_isinfn ("imag(cacos(0 + i Inf)) = -Inf", __imag__ result);
3467 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_infty));
3468 check ("real(cacos(0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3469 check_isinfp ("imag(cacos(0 - i Inf)) = +Inf", __imag__ result);
3470 result = FUNC(cacos) (BUILD_COMPLEX (0.1, plus_infty));
3471 check ("real(cacos(0.1 + i Inf)) = pi/2", __real__ result, M_PI_2l);
3472 check_isinfn ("imag(cacos(0.1 + i Inf)) = -Inf", __imag__ result);
3473 result = FUNC(cacos) (BUILD_COMPLEX (0.1, minus_infty));
3474 check ("real(cacos(0.1 - i Inf)) = pi/2", __real__ result, M_PI_2l);
3475 check_isinfp ("imag(cacos(0.1 - i Inf)) = +Inf", __imag__ result);
3477 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 0));
3478 check ("real(cacos(-Inf + i0)) = pi", __real__ result, M_PIl);
3479 check_isinfn ("imag(cacos(-Inf + i0)) = -Inf", __imag__ result);
3480 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_zero));
3481 check ("real(cacos(-Inf - i0)) = pi", __real__ result, M_PIl);
3482 check_isinfp ("imag(cacos(-Inf - i0)) = +Inf", __imag__ result);
3483 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 100));
3484 check ("real(cacos(-Inf + i100)) = pi", __real__ result, M_PIl);
3485 check_isinfn ("imag(cacos(-Inf + i100)) = -Inf", __imag__ result);
3486 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, -100));
3487 check ("real(cacos(-Inf - i100)) = pi", __real__ result, M_PIl);
3488 check_isinfp ("imag(cacos(-Inf - i100)) = +Inf", __imag__ result);
3490 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0));
3491 check ("real(cacos(+Inf + i0)) = 0", __real__ result, 0);
3492 check_isinfn ("imag(cacos(+Inf + i0)) = -Inf", __imag__ result);
3493 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_zero));
3494 check ("real(cacos(+Inf - i0)) = 0", __real__ result, 0);
3495 check_isinfp ("imag(cacos(+Inf - i0)) = +Inf", __imag__ result);
3496 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0.5));
3497 check ("real(cacos(+Inf + i0.5)) = 0", __real__ result, 0);
3498 check_isinfn ("imag(cacos(+Inf + i0.5)) = -Inf", __imag__ result);
3499 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, -0.5));
3500 check ("real(cacos(+Inf - i0.5)) = 0", __real__ result, 0);
3501 check_isinfp ("imag(cacos(+Inf - i0.5)) = +Inf", __imag__ result);
3503 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, nan_value));
3504 check_isnan ("real(cacos(+Inf + i NaN)) = NaN", __real__ result);
3505 check_isinfp ("imag(cacos(+Inf + i NaN)) = +-Inf",
3506 FUNC(fabs) (__imag__ result));
3507 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, nan_value));
3508 check_isnan ("real(cacos(-Inf + i NaN)) = NaN", __real__ result);
3509 check_isinfp ("imag(cacos(-Inf + i NaN)) = +-Inf",
3510 FUNC(fabs) (__imag__ result));
3512 result = FUNC(cacos) (BUILD_COMPLEX (0, nan_value));
3513 check ("real(cacos(0 + i NaN)) = pi/2", __real__ result, M_PI_2l);
3514 check_isnan ("imag(cacos(0 + i NaN)) = NaN", __imag__ result);
3515 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, nan_value));
3516 check ("real(cacos(-0 + i NaN)) = pi/2", __real__ result, M_PI_2l);
3517 check_isnan ("imag(cacos(-0 + i NaN)) = NaN", __imag__ result);
3519 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, plus_infty));
3520 check_isnan ("real(cacos(NaN + i Inf)) = NaN", __real__ result);
3521 check_isinfn ("imag(cacos(NaN + i Inf)) = -Inf", __imag__ result);
3522 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, minus_infty));
3523 check_isnan ("real(cacos(NaN - i Inf)) = NaN", __real__ result);
3524 check_isinfp ("imag(cacos(NaN - i Inf)) = +Inf", __imag__ result);
3526 result = FUNC(cacos) (BUILD_COMPLEX (10.5, nan_value));
3527 check_isnan_maybe_exc ("real(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3528 __real__ result, INVALID_EXCEPTION);
3529 check_isnan ("imag(cacos(10.5 + i NaN)) = NaN plus maybe invalid exception",
3530 __imag__ result);
3531 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3532 check_isnan_maybe_exc ("real(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3533 __real__ result, INVALID_EXCEPTION);
3534 check_isnan ("imag(cacos(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3535 __imag__ result);
3537 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, 0.75));
3538 check_isnan_maybe_exc ("real(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3539 __real__ result, INVALID_EXCEPTION);
3540 check_isnan ("imag(cacos(NaN + i0.75)) = NaN plus maybe invalid exception",
3541 __imag__ result);
3542 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
3543 check_isnan_maybe_exc ("real(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3544 __real__ result, INVALID_EXCEPTION);
3545 check_isnan ("imag(cacos(NaN - i0.75)) = NaN plus maybe invalid exception",
3546 __imag__ result);
3548 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, nan_value));
3549 check_isnan ("real(cacos(NaN + i NaN)) = NaN", __real__ result);
3550 check_isnan ("imag(cacos(NaN + i NaN)) = NaN", __imag__ result);
3552 result = FUNC(cacos) (BUILD_COMPLEX (0.7, 1.2));
3553 check_eps ("real(cacos(0.7 + i 1.2)) == 1.13518...", __real__ result,
3554 1.1351827477151551089L, CHOOSE (2e-17L, 3e-16, 2e-7));
3555 check_eps ("imag(cacos(0.7 + i 1.2)) == -1.09276...", __imag__ result,
3556 -1.0927647857577371459L, CHOOSE (4e-17L, 3e-16, 3e-7));
3558 result = FUNC(cacos) (BUILD_COMPLEX (-2, -3));
3559 check_eps ("real(cacos(-2 - i 3)) == 2.14144...", __real__ result,
3560 2.1414491111159960199L, CHOOSE (3e-19L, 0, 0));
3561 check_eps ("imag(cacos(-2 - i 3)) == -1.98338...", __imag__ result,
3562 1.9833870299165354323L, CHOOSE (3e-19L, 0, 0));
3566 static void
3567 cacosh_test (void)
3569 __complex__ MATHTYPE result;
3571 result = FUNC(cacosh) (BUILD_COMPLEX (0, 0));
3572 check ("real(cacosh(0 + i0)) = 0", __real__ result, 0);
3573 check ("imag(cacosh(0 + i0)) = pi/2", __imag__ result, M_PI_2l);
3574 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, 0));
3575 check ("real(cacosh(-0 + i0)) = 0", __real__ result, 0);
3576 check ("imag(cacosh(-0 + i0)) = pi/2", __imag__ result, M_PI_2l);
3577 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_zero));
3578 check ("real(cacosh(0 - i0)) = 0", __real__ result, 0);
3579 check ("imag(cacosh(0 - i0)) = -pi/2", __imag__ result, -M_PI_2l);
3580 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, minus_zero));
3581 check ("real(cacosh(-0 - i0)) = 0", __real__ result, 0);
3582 check ("imag(cacosh(-0 - i0)) = -pi/2", __imag__ result, -M_PI_2l);
3584 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, plus_infty));
3585 check_isinfp ("real(cacosh(-Inf + i Inf)) = +Inf", __real__ result);
3586 check ("imag(cacosh(-Inf + i Inf)) = 3*pi/4", __imag__ result,
3587 M_PIl - M_PI_4l);
3588 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_infty));
3589 check_isinfp ("real(cacosh(-Inf - i Inf)) = +Inf", __real__ result);
3590 check ("imag(cacosh(-Inf - i Inf)) = -3*pi/4", __imag__ result,
3591 M_PI_4l - M_PIl);
3593 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, plus_infty));
3594 check_isinfp ("real(cacosh(+Inf + i Inf)) = +Inf", __real__ result);
3595 check ("imag(cacosh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3596 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_infty));
3597 check_isinfp ("real(cacosh(+Inf - i Inf)) = +Inf", __real__ result);
3598 check ("imag(cacosh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3600 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, plus_infty));
3601 check_isinfp ("real(cacosh(-10.0 + i Inf)) = +Inf", __real__ result);
3602 check ("imag(cacosh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3603 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, minus_infty));
3604 check_isinfp ("real(cacosh(-10.0 - i Inf)) = +Inf", __real__ result);
3605 check ("imag(cacosh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3606 result = FUNC(cacosh) (BUILD_COMPLEX (0, plus_infty));
3607 check_isinfp ("real(cacosh(0 + i Inf)) = +Inf", __real__ result);
3608 check ("imag(cacosh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3609 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_infty));
3610 check_isinfp ("real(cacosh(0 - i Inf)) = +Inf", __real__ result);
3611 check ("imag(cacosh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3612 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, plus_infty));
3613 check_isinfp ("real(cacosh(0.1 + i Inf)) = +Inf", __real__ result);
3614 check ("imag(cacosh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3615 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, minus_infty));
3616 check_isinfp ("real(cacosh(0.1 - i Inf)) = +Inf", __real__ result);
3617 check ("imag(cacosh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3619 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 0));
3620 check_isinfp ("real(cacosh(-Inf + i0)) = +Inf", __real__ result);
3621 check ("imag(cacosh(-Inf + i0)) = pi", __imag__ result, M_PIl);
3622 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_zero));
3623 check_isinfp ("real(cacosh(-Inf - i0)) = +Inf", __real__ result);
3624 check ("imag(cacosh(-Inf - i0)) = -pi", __imag__ result, -M_PIl);
3625 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 100));
3626 check_isinfp ("real(cacosh(-Inf + i100)) = +Inf", __real__ result);
3627 check ("imag(cacosh(-Inf + i100)) = pi", __imag__ result, M_PIl);
3628 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, -100));
3629 check_isinfp ("real(cacosh(-Inf - i100)) = +Inf", __real__ result);
3630 check ("imag(cacosh(-Inf - i100)) = -pi", __imag__ result, -M_PIl);
3632 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0));
3633 check_isinfp ("real(cacosh(+Inf + i0)) = +Inf", __real__ result);
3634 check ("imag(cacosh(+Inf + i0)) = 0", __imag__ result, 0);
3635 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_zero));
3636 check_isinfp ("real(cacosh(+Inf - i0)) = +Inf", __real__ result);
3637 check ("imag(cacosh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3638 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0.5));
3639 check_isinfp ("real(cacosh(+Inf + i0.5)) = +Inf", __real__ result);
3640 check ("imag(cacosh(+Inf + i0.5)) = 0", __imag__ result, 0);
3641 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, -0.5));
3642 check_isinfp ("real(cacosh(+Inf - i0.5)) = +Inf", __real__ result);
3643 check ("imag(cacosh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3645 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, nan_value));
3646 check_isinfp ("real(cacosh(+Inf + i NaN)) = +Inf", __real__ result);
3647 check_isnan ("imag(cacosh(+Inf + i NaN)) = NaN", __imag__ result);
3648 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, nan_value));
3649 check_isinfp ("real(cacosh(-Inf + i NaN)) = +Inf", __real__ result);
3650 check_isnan ("imag(cacosh(-Inf + i NaN)) = NaN", __imag__ result);
3652 result = FUNC(cacosh) (BUILD_COMPLEX (0, nan_value));
3653 check_isnan ("real(cacosh(0 + i NaN)) = NaN", __real__ result);
3654 check_isnan ("imag(cacosh(0 + i NaN)) = NaN", __imag__ result);
3655 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, nan_value));
3656 check_isnan ("real(cacosh(-0 + i NaN)) = NaN", __real__ result);
3657 check_isnan ("imag(cacosh(-0 + i NaN)) = NaN", __imag__ result);
3659 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, plus_infty));
3660 check_isinfp ("real(cacosh(NaN + i Inf)) = +Inf", __real__ result);
3661 check_isnan ("imag(cacosh(NaN + i Inf)) = NaN", __imag__ result);
3662 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, minus_infty));
3663 check_isinfp ("real(cacosh(NaN - i Inf)) = +Inf", __real__ result);
3664 check_isnan ("imag(cacosh(NaN - i Inf)) = NaN", __imag__ result);
3666 result = FUNC(cacosh) (BUILD_COMPLEX (10.5, nan_value));
3667 check_isnan_maybe_exc ("real(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3668 __real__ result, INVALID_EXCEPTION);
3669 check_isnan ("imag(cacosh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3670 __imag__ result);
3671 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3672 check_isnan_maybe_exc ("real(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3673 __real__ result, INVALID_EXCEPTION);
3674 check_isnan ("imag(cacosh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3675 __imag__ result);
3677 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, 0.75));
3678 check_isnan_maybe_exc ("real(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3679 __real__ result, INVALID_EXCEPTION);
3680 check_isnan ("imag(cacosh(NaN + i0.75)) = NaN plus maybe invalid exception",
3681 __imag__ result);
3682 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
3683 check_isnan_maybe_exc ("real(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3684 __real__ result, INVALID_EXCEPTION);
3685 check_isnan ("imag(cacosh(NaN - i0.75)) = NaN plus maybe invalid exception",
3686 __imag__ result);
3688 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, nan_value));
3689 check_isnan ("real(cacosh(NaN + i NaN)) = NaN", __real__ result);
3690 check_isnan ("imag(cacosh(NaN + i NaN)) = NaN", __imag__ result);
3692 result = FUNC(cacosh) (BUILD_COMPLEX (0.7, 1.2));
3693 check_eps ("real(cacosh(0.7 + i 1.2)) == 1.09276...", __real__ result,
3694 1.0927647857577371459L, CHOOSE (4e-17L, 3e-16, 2e-7));
3695 check_eps ("imag(cacosh(0.7 + i 1.2)) == 1.13518...", __imag__ result,
3696 1.1351827477151551089L, CHOOSE (2e-17L, 0, 1.2e-7));
3698 result = FUNC(cacosh) (BUILD_COMPLEX (-2, -3));
3699 check_eps ("real(cacosh(-2 - i 3)) == -1.98338...", __real__ result,
3700 -1.9833870299165354323L, CHOOSE (2e-18L, 3e-16, 9e-7));
3701 check_eps ("imag(cacosh(-2 - i 3)) == 2.14144...", __imag__ result,
3702 2.1414491111159960199L, CHOOSE (4.5e-19, 5e-16, 1e-6));
3706 static void
3707 casin_test (void)
3709 __complex__ MATHTYPE result;
3711 result = FUNC(casin) (BUILD_COMPLEX (0, 0));
3712 check ("real(casin(0 + i0)) = 0", __real__ result, 0);
3713 check ("imag(casin(0 + i0)) = 0", __imag__ result, 0);
3714 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, 0));
3715 check ("real(casin(-0 + i0)) = -0", __real__ result, minus_zero);
3716 check ("imag(casin(-0 + i0)) = 0", __imag__ result, 0);
3717 result = FUNC(casin) (BUILD_COMPLEX (0, minus_zero));
3718 check ("real(casin(0 - i0)) = 0", __real__ result, 0);
3719 check ("imag(casin(0 - i0)) = -0", __imag__ result, minus_zero);
3720 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_zero));
3721 check ("real(casin(-0 - i0)) = -0", __real__ result, minus_zero);
3722 check ("imag(casin(-0 - i0)) = -0", __imag__ result, minus_zero);
3724 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, plus_infty));
3725 check ("real(casin(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4l);
3726 check_isinfp ("imag(casin(+Inf + i Inf)) = +Inf", __imag__ result);
3727 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_infty));
3728 check ("real(casin(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4l);
3729 check_isinfn ("imag(casin(+Inf - i Inf)) = -Inf", __imag__ result);
3730 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, plus_infty));
3731 check ("real(casin(-Inf + i Inf)) = -pi/4", __real__ result, -M_PI_4l);
3732 check_isinfp ("imag(casin(-Inf + i Inf)) = +Inf", __imag__ result);
3733 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_infty));
3734 check ("real(casin(-Inf - i Inf)) = -pi/4", __real__ result, -M_PI_4l);
3735 check_isinfn ("imag(casin(-Inf - i Inf)) = -Inf", __imag__ result);
3737 result = FUNC(casin) (BUILD_COMPLEX (-10.0, plus_infty));
3738 check ("real(casin(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
3739 check_isinfp ("imag(casin(-10.0 + i Inf)) = +Inf", __imag__ result);
3740 result = FUNC(casin) (BUILD_COMPLEX (-10.0, minus_infty));
3741 check ("real(casin(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
3742 check_isinfn ("imag(casin(-10.0 - i Inf)) = -Inf", __imag__ result);
3743 result = FUNC(casin) (BUILD_COMPLEX (0, plus_infty));
3744 check ("real(casin(0 + i Inf)) = 0", __real__ result, 0.0);
3745 check_isinfp ("imag(casin(0 + i Inf)) = +Inf", __imag__ result);
3746 result = FUNC(casin) (BUILD_COMPLEX (0, minus_infty));
3747 check ("real(casin(0 - i Inf)) = 0", __real__ result, 0.0);
3748 check_isinfn ("imag(casin(0 - i Inf)) = -Inf", __imag__ result);
3749 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, plus_infty));
3750 check ("real(casin(-0 + i Inf)) = -0", __real__ result, minus_zero);
3751 check_isinfp ("imag(casin(-0 + i Inf)) = +Inf", __imag__ result);
3752 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, minus_infty));
3753 check ("real(casin(-0 - i Inf)) = -0", __real__ result, minus_zero);
3754 check_isinfn ("imag(casin(-0 - i Inf)) = -Inf", __imag__ result);
3755 result = FUNC(casin) (BUILD_COMPLEX (0.1, plus_infty));
3756 check ("real(casin(0.1 + i Inf)) = 0", __real__ result, 0);
3757 check_isinfp ("imag(casin(0.1 + i Inf)) = +Inf", __imag__ result);
3758 result = FUNC(casin) (BUILD_COMPLEX (0.1, minus_infty));
3759 check ("real(casin(0.1 - i Inf)) = 0", __real__ result, 0);
3760 check_isinfn ("imag(casin(0.1 - i Inf)) = -Inf", __imag__ result);
3762 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 0));
3763 check ("real(casin(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2l);
3764 check_isinfp ("imag(casin(-Inf + i0)) = +Inf", __imag__ result);
3765 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, minus_zero));
3766 check ("real(casin(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2l);
3767 check_isinfn ("imag(casin(-Inf - i0)) = -Inf", __imag__ result);
3768 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, 100));
3769 check ("real(casin(-Inf + i100)) = -pi/2", __real__ result, -M_PI_2l);
3770 check_isinfp ("imag(casin(-Inf + i100)) = +Inf", __imag__ result);
3771 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, -100));
3772 check ("real(casin(-Inf - i100)) = -pi/2", __real__ result, -M_PI_2l);
3773 check_isinfn ("imag(casin(-Inf - i100)) = -Inf", __imag__ result);
3775 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0));
3776 check ("real(casin(+Inf + i0)) = pi/2", __real__ result, M_PI_2l);
3777 check_isinfp ("imag(casin(+Inf + i0)) = +Inf", __imag__ result);
3778 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, minus_zero));
3779 check ("real(casin(+Inf - i0)) = pi/2", __real__ result, M_PI_2l);
3780 check_isinfn ("imag(casin(+Inf - i0)) = -Inf", __imag__ result);
3781 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, 0.5));
3782 check ("real(casin(+Inf + i0.5)) = pi/2", __real__ result, M_PI_2l);
3783 check_isinfp ("imag(casin(+Inf + i0.5)) = +Inf", __imag__ result);
3784 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, -0.5));
3785 check ("real(casin(+Inf - i0.5)) = pi/2", __real__ result, M_PI_2l);
3786 check_isinfn ("imag(casin(+Inf - i0.5)) = -Inf", __imag__ result);
3788 result = FUNC(casin) (BUILD_COMPLEX (nan_value, plus_infty));
3789 check_isnan ("real(casin(NaN + i Inf)) = NaN", __real__ result);
3790 check_isinfp ("imag(casin(NaN + i Inf)) = +Inf", __imag__ result);
3791 result = FUNC(casin) (BUILD_COMPLEX (nan_value, minus_infty));
3792 check_isnan ("real(casin(NaN - i Inf)) = NaN", __real__ result);
3793 check_isinfn ("imag(casin(NaN - i Inf)) = -Inf", __imag__ result);
3795 result = FUNC(casin) (BUILD_COMPLEX (0.0, nan_value));
3796 check ("real(casin(0 + i NaN)) = 0", __real__ result, 0.0);
3797 check_isnan ("imag(casin(0 + i NaN)) = NaN", __imag__ result);
3798 result = FUNC(casin) (BUILD_COMPLEX (minus_zero, nan_value));
3799 check ("real(casin(-0 + i NaN)) = -0", __real__ result, minus_zero);
3800 check_isnan ("imag(casin(-0 + i NaN)) = NaN", __imag__ result);
3802 result = FUNC(casin) (BUILD_COMPLEX (plus_infty, nan_value));
3803 check_isnan ("real(casin(+Inf + i NaN)) = NaN", __real__ result);
3804 check_isinfp ("imag(casin(+Inf + i NaN)) = +-Inf",
3805 FUNC(fabs) (__imag__ result));
3806 result = FUNC(casin) (BUILD_COMPLEX (minus_infty, nan_value));
3807 check_isnan ("real(casin(-Inf + i NaN)) = NaN", __real__ result);
3808 check_isinfp ("imag(casin(-Inf + NaN)) = +-Inf",
3809 FUNC(fabs) (__imag__ result));
3811 result = FUNC(casin) (BUILD_COMPLEX (nan_value, 10.5));
3812 check_isnan_maybe_exc ("real(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3813 __real__ result, INVALID_EXCEPTION);
3814 check_isnan ("imag(casin(NaN + i10.5)) = NaN plus maybe invalid exception",
3815 __imag__ result);
3816 result = FUNC(casin) (BUILD_COMPLEX (nan_value, -10.5));
3817 check_isnan_maybe_exc ("real(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3818 __real__ result, INVALID_EXCEPTION);
3819 check_isnan ("imag(casin(NaN - i10.5)) = NaN plus maybe invalid exception",
3820 __imag__ result);
3822 result = FUNC(casin) (BUILD_COMPLEX (0.75, nan_value));
3823 check_isnan_maybe_exc ("real(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3824 __real__ result, INVALID_EXCEPTION);
3825 check_isnan ("imag(casin(0.75 + i NaN)) = NaN plus maybe invalid exception",
3826 __imag__ result);
3827 result = FUNC(casin) (BUILD_COMPLEX (-0.75, nan_value));
3828 check_isnan_maybe_exc ("real(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3829 __real__ result, INVALID_EXCEPTION);
3830 check_isnan ("imag(casin(-0.75 + i NaN)) = NaN plus maybe invalid exception",
3831 __imag__ result);
3833 result = FUNC(casin) (BUILD_COMPLEX (nan_value, nan_value));
3834 check_isnan ("real(casin(NaN + i NaN)) = NaN", __real__ result);
3835 check_isnan ("imag(casin(NaN + i NaN)) = NaN", __imag__ result);
3837 result = FUNC(casin) (BUILD_COMPLEX (0.7, 1.2));
3838 check_eps ("real(casin(0.7 + i 1.2)) == 0.43561...", __real__ result,
3839 0.4356135790797415103L, CHOOSE (2e-17L, 2e-16, 2e-7));
3840 check_eps ("imag(casin(0.7 + i 1.2)) == 1.09276...", __imag__ result,
3841 1.0927647857577371459L, CHOOSE (4e-17L, 3e-16, 3e-7));
3843 result = FUNC(casin) (BUILD_COMPLEX (-2, -3));
3844 check_eps ("real(casin(-2 - i 3)) == -0.57065...", __real__ result,
3845 -0.5706527843210994007L, CHOOSE (4e-19L, 0, 0));
3846 check_eps ("imag(casin(-2 - i 3)) == -1.98338...", __imag__ result,
3847 -1.9833870299165354323L, CHOOSE (3e-19L, 0, 0));
3851 static void
3852 casinh_test (void)
3854 __complex__ MATHTYPE result;
3856 result = FUNC(casinh) (BUILD_COMPLEX (0, 0));
3857 check ("real(casinh(0 + i0)) = 0", __real__ result, 0);
3858 check ("imag(casinh(0 + i0)) = 0", __imag__ result, 0);
3859 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, 0));
3860 check ("real(casinh(-0 + i0)) = -0", __real__ result, minus_zero);
3861 check ("imag(casinh(-0 + i0)) = 0", __imag__ result, 0);
3862 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_zero));
3863 check ("real(casinh(0 - i0)) = 0", __real__ result, 0);
3864 check ("imag(casinh(0 - i0)) = -0", __imag__ result, minus_zero);
3865 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_zero));
3866 check ("real(casinh(-0 - i0)) = -0", __real__ result, minus_zero);
3867 check ("imag(casinh(-0 - i0)) = -0", __imag__ result, minus_zero);
3869 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, plus_infty));
3870 check_isinfp ("real(casinh(+Inf + i Inf)) = +Inf", __real__ result);
3871 check ("imag(casinh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3872 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_infty));
3873 check_isinfp ("real(casinh(+Inf - i Inf)) = +Inf", __real__ result);
3874 check ("imag(casinh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3875 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, plus_infty));
3876 check_isinfn ("real(casinh(-Inf + i Inf)) = -Inf", __real__ result);
3877 check ("imag(casinh(-Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
3878 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_infty));
3879 check_isinfn ("real(casinh(-Inf - i Inf)) = -Inf", __real__ result);
3880 check ("imag(casinh(-Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
3882 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, plus_infty));
3883 check_isinfn ("real(casinh(-10.0 + i Inf)) = -Inf", __real__ result);
3884 check ("imag(casinh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3885 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, minus_infty));
3886 check_isinfn ("real(casinh(-10.0 - i Inf)) = -Inf", __real__ result);
3887 check ("imag(casinh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3888 result = FUNC(casinh) (BUILD_COMPLEX (0, plus_infty));
3889 check_isinfp ("real(casinh(0 + i Inf)) = +Inf", __real__ result);
3890 check ("imag(casinh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3891 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_infty));
3892 check_isinfp ("real(casinh(0 - i Inf)) = +Inf", __real__ result);
3893 check ("imag(casinh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3894 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, plus_infty));
3895 check_isinfn ("real(casinh(-0 + i Inf)) = -Inf", __real__ result);
3896 check ("imag(casinh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3897 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_infty));
3898 check_isinfn ("real(casinh(-0 - i Inf)) = -Inf", __real__ result);
3899 check ("imag(casinh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3900 result = FUNC(casinh) (BUILD_COMPLEX (0.1, plus_infty));
3901 check_isinfp ("real(casinh(0.1 + i Inf)) = +Inf", __real__ result);
3902 check ("imag(casinh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
3903 result = FUNC(casinh) (BUILD_COMPLEX (0.1, minus_infty));
3904 check_isinfp ("real(casinh(0.1 - i Inf)) = +Inf", __real__ result);
3905 check ("imag(casinh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
3907 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 0));
3908 check_isinfn ("real(casinh(-Inf + i0)) = -Inf", __real__ result);
3909 check ("imag(casinh(-Inf + i0)) = 0", __imag__ result, 0);
3910 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_zero));
3911 check_isinfn ("real(casinh(-Inf - i0)) = -Inf", __real__ result);
3912 check ("imag(casinh(-Inf - i0)) = -0", __imag__ result, minus_zero);
3913 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 100));
3914 check_isinfn ("real(casinh(-Inf + i100)) = -Inf", __real__ result);
3915 check ("imag(casinh(-Inf + i100)) = 0", __imag__ result, 0);
3916 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, -100));
3917 check_isinfn ("real(casinh(-Inf - i100)) = -Inf", __real__ result);
3918 check ("imag(casinh(-Inf - i100)) = -0", __imag__ result, minus_zero);
3920 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0));
3921 check_isinfp ("real(casinh(+Inf + i0)) = +Inf", __real__ result);
3922 check ("imag(casinh(+Inf + i0)) = 0", __imag__ result, 0);
3923 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_zero));
3924 check_isinfp ("real(casinh(+Inf - i0)) = +Inf", __real__ result);
3925 check ("imag(casinh(+Inf - i0)) = -0", __imag__ result, minus_zero);
3926 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0.5));
3927 check_isinfp ("real(casinh(+Inf + i0.5)) = +Inf", __real__ result);
3928 check ("imag(casinh(+Inf + i0.5)) = 0", __imag__ result, 0);
3929 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, -0.5));
3930 check_isinfp ("real(casinh(+Inf - i0.5)) = +Inf", __real__ result);
3931 check ("imag(casinh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
3933 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, nan_value));
3934 check_isinfp ("real(casinh(+Inf + i NaN)) = +Inf", __real__ result);
3935 check_isnan ("imag(casinh(+Inf + i NaN)) = NaN", __imag__ result);
3936 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, nan_value));
3937 check_isinfn ("real(casinh(-Inf + i NaN)) = -Inf", __real__ result);
3938 check_isnan ("imag(casinh(-Inf + i NaN)) = NaN", __imag__ result);
3940 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0));
3941 check_isnan ("real(casinh(NaN + i0)) = NaN", __real__ result);
3942 check ("imag(casinh(NaN + i0)) = 0", __imag__ result, 0);
3943 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_zero));
3944 check_isnan ("real(casinh(NaN - i0)) = NaN", __real__ result);
3945 check ("imag(casinh(NaN - i0)) = -0", __imag__ result, minus_zero);
3947 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, plus_infty));
3948 check_isinfp ("real(casinh(NaN + i Inf)) = +-Inf",
3949 FUNC(fabs) (__real__ result));
3950 check_isnan ("imag(casinh(NaN + i Inf)) = NaN", __imag__ result);
3951 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_infty));
3952 check_isinfp ("real(casinh(NaN - i Inf)) = +-Inf",
3953 FUNC(fabs) (__real__ result));
3954 check_isnan ("imag(casinh(NaN - i Inf)) = NaN", __imag__ result);
3956 result = FUNC(casinh) (BUILD_COMPLEX (10.5, nan_value));
3957 check_isnan_maybe_exc ("real(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3958 __real__ result, INVALID_EXCEPTION);
3959 check_isnan ("imag(casinh(10.5 + i NaN)) = NaN plus maybe invalid exception",
3960 __imag__ result);
3961 result = FUNC(casinh) (BUILD_COMPLEX (-10.5, nan_value));
3962 check_isnan_maybe_exc ("real(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3963 __real__ result, INVALID_EXCEPTION);
3964 check_isnan ("imag(casinh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
3965 __imag__ result);
3967 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0.75));
3968 check_isnan_maybe_exc ("real(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
3969 __real__ result, INVALID_EXCEPTION);
3970 check_isnan ("imag(casinh(NaN + i0.75)) = NaN plus maybe invalid exception",
3971 __imag__ result);
3972 result = FUNC(casinh) (BUILD_COMPLEX (-0.75, nan_value));
3973 check_isnan_maybe_exc ("real(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
3974 __real__ result, INVALID_EXCEPTION);
3975 check_isnan ("imag(casinh(NaN - i0.75)) = NaN plus maybe invalid exception",
3976 __imag__ result);
3978 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, nan_value));
3979 check_isnan ("real(casinh(NaN + i NaN)) = NaN", __real__ result);
3980 check_isnan ("imag(casinh(NaN + i NaN)) = NaN", __imag__ result);
3982 result = FUNC(casinh) (BUILD_COMPLEX (0.7, 1.2));
3983 check_eps ("real(casinh(0.7 + i 1.2)) == 0.97865...", __real__ result,
3984 0.9786545955936738768L, CHOOSE (5e-17L, 2e-16, 0));
3985 check_eps ("imag(casinh(0.7 + i 1.2)) == 0.91135...", __imag__ result,
3986 0.9113541895315601156L, CHOOSE (7e-19L, 2e-16, 2e-7));
3988 result = FUNC(casinh) (BUILD_COMPLEX (-2, -3));
3989 check_eps ("real(casinh(-2 - i 3)) == -1.96863...", __real__ result,
3990 -1.9686379257930962917L, CHOOSE (7e-19L, 2e-15, 3e-6));
3991 check_eps ("imag(casinh(-2 - i 3)) == -0.96465...", __imag__ result,
3992 -0.9646585044076027920L, CHOOSE (4e-19L, 2e-15, 4.5e-7));
3996 static void
3997 catan_test (void)
3999 __complex__ MATHTYPE result;
4001 result = FUNC(catan) (BUILD_COMPLEX (0, 0));
4002 check ("real(catan(0 + i0)) = 0", __real__ result, 0);
4003 check ("imag(catan(0 + i0)) = 0", __imag__ result, 0);
4004 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, 0));
4005 check ("real(catan(-0 + i0)) = -0", __real__ result, minus_zero);
4006 check ("imag(catan(-0 + i0)) = 0", __imag__ result, 0);
4007 result = FUNC(catan) (BUILD_COMPLEX (0, minus_zero));
4008 check ("real(catan(0 - i0)) = 0", __real__ result, 0);
4009 check ("imag(catan(0 - i0)) = -0", __imag__ result, minus_zero);
4010 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_zero));
4011 check ("real(catan(-0 - i0)) = -0", __real__ result, minus_zero);
4012 check ("imag(catan(-0 - i0)) = -0", __imag__ result, minus_zero);
4014 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, plus_infty));
4015 check ("real(catan(+Inf + i Inf)) = pi/2", __real__ result, M_PI_2l);
4016 check ("imag(catan(+Inf + i Inf)) = 0", __imag__ result, 0);
4017 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_infty));
4018 check ("real(catan(+Inf - i Inf)) = pi/2", __real__ result, M_PI_2l);
4019 check ("imag(catan(+Inf - i Inf)) = -0", __imag__ result, minus_zero);
4020 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, plus_infty));
4021 check ("real(catan(-Inf + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4022 check ("imag(catan(-Inf + i Inf)) = 0", __imag__ result, 0.0);
4023 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_infty));
4024 check ("real(catan(-Inf - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4025 check ("imag(catan(-Inf - i Inf)) = -0", __imag__ result, minus_zero);
4027 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, -10.0));
4028 check ("real(catan(+Inf - i10.0)) = pi/2", __real__ result, M_PI_2l);
4029 check ("imag(catan(+Inf - i10.0)) = -0", __imag__ result, minus_zero);
4030 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, -10.0));
4031 check ("real(catan(-Inf - i10.0)) = -pi/2", __real__ result, -M_PI_2l);
4032 check ("imag(catan(-Inf - i10.0)) = -0", __imag__ result, minus_zero);
4033 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, minus_zero));
4034 check ("real(catan(Inf - i0)) = pi/2", __real__ result, M_PI_2l);
4035 check ("imag(catan(Inf - i0)) = -0", __imag__ result, minus_zero);
4036 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, minus_zero));
4037 check ("real(catan(-Inf - i0)) = -pi/2", __real__ result, -M_PI_2l);
4038 check ("imag(catan(-Inf - i0)) = -0", __imag__ result, minus_zero);
4039 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.0));
4040 check ("real(catan(Inf + i0)) = pi/2", __real__ result, M_PI_2l);
4041 check ("imag(catan(Inf + i0)) = 0", __imag__ result, 0.0);
4042 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.0));
4043 check ("real(catan(-Inf + i0)) = -pi/2", __real__ result, -M_PI_2l);
4044 check ("imag(catan(-Inf + i0)) = 0", __imag__ result, 0.0);
4045 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, 0.1));
4046 check ("real(catan(+Inf + i0.1)) = pi/2", __real__ result, M_PI_2l);
4047 check ("imag(catan(+Inf + i0.1)) = 0", __imag__ result, 0);
4048 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, 0.1));
4049 check ("real(catan(-Inf + i0.1)) = -pi/2", __real__ result, -M_PI_2l);
4050 check ("imag(catan(-Inf + i0.1)) = 0", __imag__ result, 0);
4052 result = FUNC(catan) (BUILD_COMPLEX (0.0, minus_infty));
4053 check ("real(catan(0 - i Inf)) = pi/2", __real__ result, M_PI_2l);
4054 check ("imag(catan(0 - i Inf)) = -0", __imag__ result, minus_zero);
4055 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, minus_infty));
4056 check ("real(catan(-0 - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4057 check ("imag(catan(-0 - i Inf)) = -0", __imag__ result, minus_zero);
4058 result = FUNC(catan) (BUILD_COMPLEX (100.0, minus_infty));
4059 check ("real(catan(100 - i Inf)) = pi/2", __real__ result, M_PI_2l);
4060 check ("imag(catan(100 - i Inf)) = -0", __imag__ result, minus_zero);
4061 result = FUNC(catan) (BUILD_COMPLEX (-100.0, minus_infty));
4062 check ("real(catan(-100 - i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4063 check ("imag(catan(-100 - i Inf)) = -0", __imag__ result, minus_zero);
4065 result = FUNC(catan) (BUILD_COMPLEX (0.0, plus_infty));
4066 check ("real(catan(0 + i Inf)) = pi/2", __real__ result, M_PI_2l);
4067 check ("imag(catan(0 + i Inf)) = 0", __imag__ result, 0);
4068 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, plus_infty));
4069 check ("real(catan(-0 + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4070 check ("imag(catan(-0 + i Inf)) = 0", __imag__ result, 0);
4071 result = FUNC(catan) (BUILD_COMPLEX (0.5, plus_infty));
4072 check ("real(catan(0.5 + i Inf)) = pi/2", __real__ result, M_PI_2l);
4073 check ("imag(catan(0.5 + i Inf)) = 0", __imag__ result, 0);
4074 result = FUNC(catan) (BUILD_COMPLEX (-0.5, plus_infty));
4075 check ("real(catan(-0.5 + i Inf)) = -pi/2", __real__ result, -M_PI_2l);
4076 check ("imag(catan(-0.5 + i Inf)) = 0", __imag__ result, 0);
4078 result = FUNC(catan) (BUILD_COMPLEX (nan_value, 0.0));
4079 check_isnan ("real(catan(NaN + i0)) = NaN", __real__ result);
4080 check ("imag(catan(NaN + i0)) = 0", __imag__ result, 0.0);
4081 result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_zero));
4082 check_isnan ("real(catan(NaN - i0)) = NaN", __real__ result);
4083 check ("imag(catan(NaN - i0)) = -0", __imag__ result, minus_zero);
4085 result = FUNC(catan) (BUILD_COMPLEX (nan_value, plus_infty));
4086 check_isnan ("real(catan(NaN + i Inf)) = NaN", __real__ result);
4087 check ("imag(catan(NaN + i Inf)) = 0", __imag__ result, 0);
4088 result = FUNC(catan) (BUILD_COMPLEX (nan_value, minus_infty));
4089 check_isnan ("real(catan(NaN - i Inf)) = NaN", __real__ result);
4090 check ("imag(catan(NaN - i Inf)) = -0", __imag__ result, minus_zero);
4092 result = FUNC(catan) (BUILD_COMPLEX (0.0, nan_value));
4093 check_isnan ("real(catan(0 + i NaN)) = NaN", __real__ result);
4094 check_isnan ("imag(catan(0 + i NaN)) = NaN", __imag__ result);
4095 result = FUNC(catan) (BUILD_COMPLEX (minus_zero, nan_value));
4096 check_isnan ("real(catan(-0 + i NaN)) = NaN", __real__ result);
4097 check_isnan ("imag(catan(-0 + i NaN)) = NaN", __imag__ result);
4099 result = FUNC(catan) (BUILD_COMPLEX (plus_infty, nan_value));
4100 check ("real(catan(+Inf + i NaN)) = pi/2", __real__ result, M_PI_2l);
4101 check ("imag(catan(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4102 result = FUNC(catan) (BUILD_COMPLEX (minus_infty, nan_value));
4103 check ("real(catan(-Inf + i NaN)) = -pi/2", __real__ result, -M_PI_2l);
4104 check ("imag(catan(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4106 result = FUNC(catan) (BUILD_COMPLEX (nan_value, 10.5));
4107 check_isnan_maybe_exc ("real(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
4108 __real__ result, INVALID_EXCEPTION);
4109 check_isnan ("imag(catan(NaN + i10.5)) = NaN plus maybe invalid exception",
4110 __imag__ result);
4111 result = FUNC(catan) (BUILD_COMPLEX (nan_value, -10.5));
4112 check_isnan_maybe_exc ("real(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
4113 __real__ result, INVALID_EXCEPTION);
4114 check_isnan ("imag(catan(NaN - i10.5)) = NaN plus maybe invalid exception",
4115 __imag__ result);
4117 result = FUNC(catan) (BUILD_COMPLEX (0.75, nan_value));
4118 check_isnan_maybe_exc ("real(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
4119 __real__ result, INVALID_EXCEPTION);
4120 check_isnan ("imag(catan(0.75 + i NaN)) = NaN plus maybe invalid exception",
4121 __imag__ result);
4122 result = FUNC(catan) (BUILD_COMPLEX (-0.75, nan_value));
4123 check_isnan_maybe_exc ("real(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
4124 __real__ result, INVALID_EXCEPTION);
4125 check_isnan ("imag(catan(-0.75 + i NaN)) = NaN plus maybe invalid exception",
4126 __imag__ result);
4128 result = FUNC(catan) (BUILD_COMPLEX (nan_value, nan_value));
4129 check_isnan ("real(catan(NaN + i NaN)) = NaN", __real__ result);
4130 check_isnan ("imag(catan(NaN + i NaN)) = NaN", __imag__ result);
4132 result = FUNC(catan) (BUILD_COMPLEX (0.7, 1.2));
4133 check_eps ("real(catan(0.7 + i 1.2)) == 1.07857...", __real__ result,
4134 1.0785743834118921877L, CHOOSE (3e-17, 0, 5e-7));
4135 check_eps ("imag(catan(0.7 + i 1.2)) == 0.57705...", __imag__ result,
4136 0.5770573776534306764L, CHOOSE (3e-17L, 2e-16, 6e-8));
4138 result = FUNC(catan) (BUILD_COMPLEX (-2, -3));
4139 check_eps ("real(catan(-2 - i 3)) == -1.40992...", __real__ result,
4140 -1.4099210495965755225L, CHOOSE (0, 0, 4e-7));
4141 check_eps ("imag(catan(-2 - i 3)) == -0.22907...", __imag__ result,
4142 -0.2290726829685387662L, CHOOSE (1.1e-19L, 3e-17, 2e-8));
4146 static void
4147 catanh_test (void)
4149 __complex__ MATHTYPE result;
4151 result = FUNC(catanh) (BUILD_COMPLEX (0, 0));
4152 check ("real(catanh(0 + i0)) = 0", __real__ result, 0);
4153 check ("imag(catanh(0 + i0)) = 0", __imag__ result, 0);
4154 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, 0));
4155 check ("real(catanh(-0 + i0)) = -0", __real__ result, minus_zero);
4156 check ("imag(catanh(-0 + i0)) = 0", __imag__ result, 0);
4157 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_zero));
4158 check ("real(catanh(0 - i0)) = 0", __real__ result, 0);
4159 check ("imag(catanh(0 - i0)) = -0", __imag__ result, minus_zero);
4160 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4161 check ("real(catanh(-0 - i0)) = -0", __real__ result, minus_zero);
4162 check ("imag(catanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4164 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, plus_infty));
4165 check ("real(catanh(+Inf + i Inf)) = 0", __real__ result, 0);
4166 check ("imag(catanh(+Inf + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4167 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_infty));
4168 check ("real(catanh(+Inf - i Inf)) = 0", __real__ result, 0);
4169 check ("imag(catanh(+Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4170 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, plus_infty));
4171 check ("real(catanh(-Inf + i Inf)) = -0", __real__ result, minus_zero);
4172 check ("imag(catanh(-Inf + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4173 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_infty));
4174 check ("real(catanh(-Inf - i Inf)) = -0", __real__ result, minus_zero);
4175 check ("imag(catanh(-Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4177 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, plus_infty));
4178 check ("real(catanh(-10.0 + i Inf)) = -0", __real__ result, minus_zero);
4179 check ("imag(catanh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4180 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, minus_infty));
4181 check ("real(catanh(-10.0 - i Inf)) = -0", __real__ result, minus_zero);
4182 check ("imag(catanh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4183 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4184 check ("real(catanh(-0 + i Inf)) = -0", __real__ result, minus_zero);
4185 check ("imag(catanh(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4186 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4187 check ("real(catanh(-0 - i Inf)) = -0", __real__ result, minus_zero);
4188 check ("imag(catanh(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4189 result = FUNC(catanh) (BUILD_COMPLEX (0, plus_infty));
4190 check ("real(catanh(0 + i Inf)) = 0", __real__ result, 0);
4191 check ("imag(catanh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4192 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_infty));
4193 check ("real(catanh(0 - i Inf)) = 0", __real__ result, 0);
4194 check ("imag(catanh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4195 result = FUNC(catanh) (BUILD_COMPLEX (0.1, plus_infty));
4196 check ("real(catanh(0.1 + i Inf)) = 0", __real__ result, 0);
4197 check ("imag(catanh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4198 result = FUNC(catanh) (BUILD_COMPLEX (0.1, minus_infty));
4199 check ("real(catanh(0.1 - i Inf)) = 0", __real__ result, 0);
4200 check ("imag(catanh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4202 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 0));
4203 check ("real(catanh(-Inf + i0)) = -0", __real__ result, minus_zero);
4204 check ("imag(catanh(-Inf + i0)) = pi/2", __imag__ result, M_PI_2l);
4205 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4206 check ("real(catanh(-Inf - i0)) = -0", __real__ result, minus_zero);
4207 check ("imag(catanh(-Inf - i0)) = -pi/2", __imag__ result, -M_PI_2l);
4208 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 100));
4209 check ("real(catanh(-Inf + i100)) = -0", __real__ result, minus_zero);
4210 check ("imag(catanh(-Inf + i100)) = pi/2", __imag__ result, M_PI_2l);
4211 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, -100));
4212 check ("real(catanh(-Inf - i100)) = -0", __real__ result, minus_zero);
4213 check ("imag(catanh(-Inf - i100)) = -pi/2", __imag__ result, -M_PI_2l);
4215 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0));
4216 check ("real(catanh(+Inf + i0)) = 0", __real__ result, 0);
4217 check ("imag(catanh(+Inf + i0)) = pi/2", __imag__ result, M_PI_2l);
4218 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4219 check ("real(catanh(+Inf - i0)) = 0", __real__ result, 0);
4220 check ("imag(catanh(+Inf - i0)) = -pi/2", __imag__ result, -M_PI_2l);
4221 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0.5));
4222 check ("real(catanh(+Inf + i0.5)) = 0", __real__ result, 0);
4223 check ("imag(catanh(+Inf + i0.5)) = pi/2", __imag__ result, M_PI_2l);
4224 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, -0.5));
4225 check ("real(catanh(+Inf - i0.5)) = 0", __real__ result, 0);
4226 check ("imag(catanh(+Inf - i0.5)) = -pi/2", __imag__ result, -M_PI_2l);
4228 result = FUNC(catanh) (BUILD_COMPLEX (0, nan_value));
4229 check ("real(catanh(0 + i NaN)) = 0", __real__ result, 0);
4230 check_isnan ("imag(catanh(0 + i NaN)) = NaN", __imag__ result);
4231 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, nan_value));
4232 check ("real(catanh(-0 + i NaN)) = -0", __real__ result, minus_zero);
4233 check_isnan ("imag(catanh(-0 + i NaN)) = NaN", __imag__ result);
4235 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, nan_value));
4236 check ("real(catanh(+Inf + i NaN)) = 0", __real__ result, 0);
4237 check_isnan ("imag(catanh(+Inf + i NaN)) = NaN", __imag__ result);
4238 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, nan_value));
4239 check ("real(catanh(-Inf + i NaN)) = -0", __real__ result, minus_zero);
4240 check_isnan ("imag(catanh(-Inf + i NaN)) = NaN", __imag__ result);
4242 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0));
4243 check_isnan ("real(catanh(NaN + i0)) = NaN", __real__ result);
4244 check_isnan ("imag(catanh(NaN + i0)) = NaN", __imag__ result);
4245 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_zero));
4246 check_isnan ("real(catanh(NaN - i0)) = NaN", __real__ result);
4247 check_isnan ("imag(catanh(NaN - i0)) = NaN", __imag__ result);
4249 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, plus_infty));
4250 check ("real(catanh(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4251 check ("imag(catanh(NaN + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4252 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_infty));
4253 check ("real(catanh(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4254 check ("imag(catanh(NaN - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4256 result = FUNC(catanh) (BUILD_COMPLEX (10.5, nan_value));
4257 check_isnan_maybe_exc ("real(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4258 __real__ result, INVALID_EXCEPTION);
4259 check_isnan ("imag(catanh(10.5 + i NaN)) = NaN plus maybe invalid exception",
4260 __imag__ result);
4261 result = FUNC(catanh) (BUILD_COMPLEX (-10.5, nan_value));
4262 check_isnan_maybe_exc ("real(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4263 __real__ result, INVALID_EXCEPTION);
4264 check_isnan ("imag(catanh(-10.5 + i NaN)) = NaN plus maybe invalid exception",
4265 __imag__ result);
4267 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0.75));
4268 check_isnan_maybe_exc ("real(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4269 __real__ result, INVALID_EXCEPTION);
4270 check_isnan ("imag(catanh(NaN + i0.75)) = NaN plus maybe invalid exception",
4271 __imag__ result);
4272 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, -0.75));
4273 check_isnan_maybe_exc ("real(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4274 __real__ result, INVALID_EXCEPTION);
4275 check_isnan ("imag(catanh(NaN - i0.75)) = NaN plus maybe invalid exception",
4276 __imag__ result);
4278 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, nan_value));
4279 check_isnan ("real(catanh(NaN + i NaN)) = NaN", __real__ result);
4280 check_isnan ("imag(catanh(NaN + i NaN)) = NaN", __imag__ result);
4282 result = FUNC(catanh) (BUILD_COMPLEX (0.7, 1.2));
4283 check_eps ("real(catanh(0.7 + i 1.2)) == 0.26007...", __real__ result,
4284 0.2600749516525135959L, CHOOSE (2e-18, 6e-17, 3e-8));
4285 check_eps ("imag(catanh(0.7 + i 1.2)) == 0.97024...", __imag__ result,
4286 0.9702403077950989849L, CHOOSE (3e-17, 2e-16, 4e-7));
4288 result = FUNC(catanh) (BUILD_COMPLEX (-2, -3));
4289 check_eps ("real(catanh(-2 - i 3)) == -0.14694...", __real__ result,
4290 -0.1469466662255297520L, CHOOSE (9e-20L, 2e-16, 2e-8));
4291 check_eps ("imag(catanh(-2 - i 3)) == -1.33897...", __imag__ result,
4292 -1.3389725222944935611L, CHOOSE (7e-19L, 0, 5e-7));
4296 static void
4297 ctan_test (void)
4299 __complex__ MATHTYPE result;
4301 result = FUNC(ctan) (BUILD_COMPLEX (0, 0));
4302 check ("real(ctan(0 + i0)) = 0", __real__ result, 0);
4303 check ("imag(ctan(0 + i0)) = 0", __imag__ result, 0);
4304 result = FUNC(ctan) (BUILD_COMPLEX (0, minus_zero));
4305 check ("real(ctan(0 - i0)) = 0", __real__ result, 0);
4306 check ("imag(ctan(0 - i0)) = -0", __imag__ result, minus_zero);
4307 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, 0));
4308 check ("real(ctan(-0 + i0)) = -0", __real__ result, minus_zero);
4309 check ("imag(ctan(-0 + i0)) = 0", __imag__ result, 0);
4310 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_zero));
4311 check ("real(ctan(-0 - i0)) = -0", __real__ result, minus_zero);
4312 check ("imag(ctan(-0 - i0)) = -0", __imag__ result, minus_zero);
4315 result = FUNC(ctan) (BUILD_COMPLEX (0, plus_infty));
4316 check ("real(ctan(0 + i Inf)) = 0", __real__ result, 0);
4317 check ("imag(ctan(0 + i Inf)) = 1", __imag__ result, 1);
4318 result = FUNC(ctan) (BUILD_COMPLEX (1, plus_infty));
4319 check ("real(ctan(1 + i Inf)) = 0", __real__ result, 0);
4320 check ("imag(ctan(1 + i Inf)) = 1", __imag__ result, 1);
4321 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, plus_infty));
4322 check ("real(ctan(-0 + i Inf)) = -0", __real__ result, minus_zero);
4323 check ("imag(ctan(-0 + i Inf)) = 1", __imag__ result, 1);
4324 result = FUNC(ctan) (BUILD_COMPLEX (-1, plus_infty));
4325 check ("real(ctan(-1 + i Inf)) = -0", __real__ result, minus_zero);
4326 check ("imag(ctan(-1 + i Inf)) = 1", __imag__ result, 1);
4328 result = FUNC(ctan) (BUILD_COMPLEX (0, minus_infty));
4329 check ("real(ctan(0 - i Inf)) = 0", __real__ result, 0);
4330 check ("imag(ctan(0 - i Inf)) = -1", __imag__ result, -1);
4331 result = FUNC(ctan) (BUILD_COMPLEX (1, minus_infty));
4332 check ("real(ctan(1 - i Inf)) = 0", __real__ result, 0);
4333 check ("imag(ctan(1 - i Inf)) = -1", __imag__ result, -1);
4334 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, minus_infty));
4335 check ("real(ctan(-0 - i Inf)) = -0", __real__ result, minus_zero);
4336 check ("imag(ctan(-0 - i Inf)) = -1", __imag__ result, -1);
4337 result = FUNC(ctan) (BUILD_COMPLEX (-1, minus_infty));
4338 check ("real(ctan(-1 - i Inf)) = -0", __real__ result, minus_zero);
4339 check ("imag(ctan(-1 - i Inf)) = -1", __imag__ result, -1);
4341 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 0));
4342 check_isnan_exc ("real(ctan(Inf + i 0)) = NaN plus invalid exception",
4343 __real__ result, INVALID_EXCEPTION);
4344 check_isnan ("imag(ctan(Inf + i 0)) = NaN plus invalid exception",
4345 __imag__ result);
4346 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, 2));
4347 check_isnan_exc ("real(ctan(Inf + i 2)) = NaN plus invalid exception",
4348 __real__ result, INVALID_EXCEPTION);
4349 check_isnan ("imag(ctan(Inf + i 2)) = NaN plus invalid exception",
4350 __imag__ result);
4351 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 0));
4352 check_isnan_exc ("real(ctan(-Inf + i 0)) = NaN plus invalid exception",
4353 __real__ result, INVALID_EXCEPTION);
4354 check_isnan ("imag(ctan(-Inf + i 0)) = NaN plus invalid exception",
4355 __imag__ result);
4356 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, 2));
4357 check_isnan_exc ("real(ctan(- Inf + i 2)) = NaN plus invalid exception",
4358 __real__ result, INVALID_EXCEPTION);
4359 check_isnan ("imag(ctan(- Inf + i 2)) = NaN plus invalid exception",
4360 __imag__ result);
4361 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, minus_zero));
4362 check_isnan_exc ("real(ctan(Inf - i 0)) = NaN plus invalid exception",
4363 __real__ result, INVALID_EXCEPTION);
4364 check_isnan ("imag(ctan(Inf - i 0)) = NaN plus invalid exception",
4365 __imag__ result);
4366 result = FUNC(ctan) (BUILD_COMPLEX (plus_infty, -2));
4367 check_isnan_exc ("real(ctan(Inf - i 2)) = NaN plus invalid exception",
4368 __real__ result, INVALID_EXCEPTION);
4369 check_isnan ("imag(ctan(Inf - i 2)) = NaN plus invalid exception",
4370 __imag__ result);
4371 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, minus_zero));
4372 check_isnan_exc ("real(ctan(-Inf - i 0)) = NaN plus invalid exception",
4373 __real__ result, INVALID_EXCEPTION);
4374 check_isnan ("imag(ctan(-Inf - i 0)) = NaN plus invalid exception",
4375 __imag__ result);
4376 result = FUNC(ctan) (BUILD_COMPLEX (minus_infty, -2));
4377 check_isnan_exc ("real(ctan(-Inf - i 2)) = NaN plus invalid exception",
4378 __real__ result, INVALID_EXCEPTION);
4379 check_isnan ("imag(ctan(-Inf - i 2)) = NaN plus invalid exception",
4380 __imag__ result);
4382 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, plus_infty));
4383 check ("real(ctan(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4384 check ("imag(ctan(NaN + i Inf)) = 1", __imag__ result, 1);
4385 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_infty));
4386 check ("real(ctan(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
4387 check ("imag(ctan(NaN - i Inf)) = -1", __imag__ result, -1);
4389 result = FUNC(ctan) (BUILD_COMPLEX (0, nan_value));
4390 check ("real(ctan(0 + i NaN)) = 0", __real__ result, 0);
4391 check_isnan ("imag(ctan(0 + i NaN)) = NaN", __imag__ result);
4392 result = FUNC(ctan) (BUILD_COMPLEX (minus_zero, nan_value));
4393 check ("real(ctan(-0 + i NaN)) = -0", __real__ result, minus_zero);
4394 check_isnan ("imag(ctan(-0 + i NaN)) = NaN", __imag__ result);
4396 result = FUNC(ctan) (BUILD_COMPLEX (0.5, nan_value));
4397 check_isnan_maybe_exc ("real(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4398 __real__ result, INVALID_EXCEPTION);
4399 check_isnan ("imag(ctan(0.5 + i NaN)) = NaN plus maybe invalid exception",
4400 __imag__ result);
4401 result = FUNC(ctan) (BUILD_COMPLEX (-4.5, nan_value));
4402 check_isnan_maybe_exc ("real(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4403 __real__ result, INVALID_EXCEPTION);
4404 check_isnan ("imag(ctan(-4.5 + i NaN)) = NaN plus maybe invalid exception",
4405 __imag__ result);
4407 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 0));
4408 check_isnan_maybe_exc ("real(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4409 __real__ result, INVALID_EXCEPTION);
4410 check_isnan ("imag(ctan(NaN + i 0)) = NaN plus maybe invalid exception",
4411 __imag__ result);
4412 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, 5));
4413 check_isnan_maybe_exc ("real(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4414 __real__ result, INVALID_EXCEPTION);
4415 check_isnan ("imag(ctan(NaN + i 5)) = NaN plus maybe invalid exception",
4416 __imag__ result);
4417 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, minus_zero));
4418 check_isnan_maybe_exc ("real(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4419 __real__ result, INVALID_EXCEPTION);
4420 check_isnan ("imag(ctan(NaN - i 0)) = NaN plus maybe invalid exception",
4421 __imag__ result);
4422 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, -0.25));
4423 check_isnan_maybe_exc ("real(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4424 __real__ result, INVALID_EXCEPTION);
4425 check_isnan ("imag(ctan(NaN -i 0.25)) = NaN plus maybe invalid exception",
4426 __imag__ result);
4428 result = FUNC(ctan) (BUILD_COMPLEX (nan_value, nan_value));
4429 check_isnan ("real(ctan(NaN + i NaN)) = NaN", __real__ result);
4430 check_isnan ("imag(ctan(NaN + i NaN)) = NaN", __imag__ result);
4432 result = FUNC(ctan) (BUILD_COMPLEX (0.7, 1.2));
4433 check_eps ("real(ctan(0.7 + i 1.2)) == 0.17207...", __real__ result,
4434 0.1720734197630349001L, CHOOSE (1e-17L, 5.6e-17, 2e-8));
4435 check_eps ("imag(ctan(0.7 + i 1.2)) == 0.95448...", __imag__ result,
4436 0.9544807059989405538L, CHOOSE (2e-17L, 2.3e-16, 6e-8));
4438 result = FUNC(ctan) (BUILD_COMPLEX (-2, -3));
4439 check_eps ("real(ctan(-2 - i 3)) == -0.00376...", __real__ result,
4440 0.0037640256415042482L, CHOOSE (1e-19L, 5e-19, 0));
4441 check_eps ("imag(ctan(-2 - i 3)) == -1.00323...", __imag__ result,
4442 -1.0032386273536098014L, CHOOSE (2e-19L, 2.3e-16, 2e-7));
4446 static void
4447 ctanh_test (void)
4449 __complex__ MATHTYPE result;
4451 result = FUNC(ctanh) (BUILD_COMPLEX (0, 0));
4452 check ("real(ctanh(0 + i0)) = 0", __real__ result, 0);
4453 check ("imag(ctanh(0 + i0)) = 0", __imag__ result, 0);
4454 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_zero));
4455 check ("real(ctanh(0 - i0)) = 0", __real__ result, 0);
4456 check ("imag(ctanh(0 - i0)) = -0", __imag__ result, minus_zero);
4457 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, 0));
4458 check ("real(ctanh(-0 + i0)) = -0", __real__ result, minus_zero);
4459 check ("imag(ctanh(-0 + i0)) = 0", __imag__ result, 0);
4460 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_zero));
4461 check ("real(ctanh(-0 - i0)) = -0", __real__ result, minus_zero);
4462 check ("imag(ctanh(-0 - i0)) = -0", __imag__ result, minus_zero);
4464 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 0));
4465 check ("real(ctanh(+Inf + i0)) = 1", __real__ result, 1);
4466 check ("imag(ctanh(+Inf + i0)) = 0", __imag__ result, 0);
4467 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 1));
4468 check ("real(ctanh(+Inf + i1)) = 1", __real__ result, 1);
4469 check ("imag(ctanh(+Inf + i1)) = 0", __imag__ result, 0);
4470 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, minus_zero));
4471 check ("real(ctanh(+Inf - i0)) = 1", __real__ result, 1);
4472 check ("imag(ctanh(+Inf - i0)) = -0", __imag__ result, minus_zero);
4473 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, -1));
4474 check ("real(ctanh(+Inf - i1)) = 1", __real__ result, 1);
4475 check ("imag(ctanh(+Inf - i1)) = -0", __imag__ result, minus_zero);
4476 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 0));
4477 check ("real(ctanh(-Inf + i0)) = -1", __real__ result, -1);
4478 check ("imag(ctanh(-Inf + i0)) = 0", __imag__ result, 0);
4479 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 1));
4480 check ("real(ctanh(-Inf + i1)) = -1", __real__ result, -1);
4481 check ("imag(ctanh(-Inf + i1)) = 0", __imag__ result, 0);
4482 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, minus_zero));
4483 check ("real(ctanh(-Inf - i0)) = -1", __real__ result, -1);
4484 check ("imag(ctanh(-Inf - i0)) = -0", __imag__ result, minus_zero);
4485 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, -1));
4486 check ("real(ctanh(-Inf - i1)) = -1", __real__ result, -1);
4487 check ("imag(ctanh(-Inf - i1)) = -0", __imag__ result, minus_zero);
4489 result = FUNC(ctanh) (BUILD_COMPLEX (0, plus_infty));
4490 check_isnan_exc ("real(ctanh(0 + i Inf)) = NaN plus invalid exception",
4491 __real__ result, INVALID_EXCEPTION);
4492 check_isnan ("imag(ctanh(0 + i Inf)) = NaN plus invalid exception",
4493 __imag__ result);
4494 result = FUNC(ctanh) (BUILD_COMPLEX (2, plus_infty));
4495 check_isnan_exc ("real(ctanh(2 + i Inf)) = NaN plus invalid exception",
4496 __real__ result, INVALID_EXCEPTION);
4497 check_isnan ("imag(ctanh(2 + i Inf)) = NaN plus invalid exception",
4498 __imag__ result);
4499 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_infty));
4500 check_isnan_exc ("real(ctanh(0 - i Inf)) = NaN plus invalid exception",
4501 __real__ result, INVALID_EXCEPTION);
4502 check_isnan ("imag(ctanh(0 - i Inf)) = NaN plus invalid exception",
4503 __imag__ result);
4504 result = FUNC(ctanh) (BUILD_COMPLEX (2, minus_infty));
4505 check_isnan_exc ("real(ctanh(2 - i Inf)) = NaN plus invalid exception",
4506 __real__ result, INVALID_EXCEPTION);
4507 check_isnan ("imag(ctanh(2 - i Inf)) = NaN plus invalid exception",
4508 __imag__ result);
4509 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, plus_infty));
4510 check_isnan_exc ("real(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4511 __real__ result, INVALID_EXCEPTION);
4512 check_isnan ("imag(ctanh(-0 + i Inf)) = NaN plus invalid exception",
4513 __imag__ result);
4514 result = FUNC(ctanh) (BUILD_COMPLEX (-2, plus_infty));
4515 check_isnan_exc ("real(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4516 __real__ result, INVALID_EXCEPTION);
4517 check_isnan ("imag(ctanh(-2 + i Inf)) = NaN plus invalid exception",
4518 __imag__ result);
4519 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_infty));
4520 check_isnan_exc ("real(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4521 __real__ result, INVALID_EXCEPTION);
4522 check_isnan ("imag(ctanh(-0 - i Inf)) = NaN plus invalid exception",
4523 __imag__ result);
4524 result = FUNC(ctanh) (BUILD_COMPLEX (-2, minus_infty));
4525 check_isnan_exc ("real(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4526 __real__ result, INVALID_EXCEPTION);
4527 check_isnan ("imag(ctanh(-2 - i Inf)) = NaN plus invalid exception",
4528 __imag__ result);
4530 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, nan_value));
4531 check ("real(ctanh(+Inf + i NaN)) = 1", __real__ result, 1);
4532 check ("imag(ctanh(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4533 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, nan_value));
4534 check ("real(ctanh(-Inf + i NaN)) = -1", __real__ result, -1);
4535 check ("imag(ctanh(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
4537 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0));
4538 check_isnan ("real(ctanh(NaN + i0)) = NaN", __real__ result);
4539 check ("imag(ctanh(NaN + i0)) = 0", __imag__ result, 0);
4540 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, minus_zero));
4541 check_isnan ("real(ctanh(NaN - i0)) = NaN", __real__ result);
4542 check ("imag(ctanh(NaN - i0)) = -0", __imag__ result, minus_zero);
4544 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0.5));
4545 check_isnan_maybe_exc ("real(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4546 __real__ result, INVALID_EXCEPTION);
4547 check_isnan ("imag(ctanh(NaN + i0.5)) = NaN plus maybe invalid exception",
4548 __imag__ result);
4549 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, -4.5));
4550 check_isnan_maybe_exc ("real(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4551 __real__ result, INVALID_EXCEPTION);
4552 check_isnan ("imag(ctanh(NaN - i4.5)) = NaN plus maybe invalid exception",
4553 __imag__ result);
4555 result = FUNC(ctanh) (BUILD_COMPLEX (0, nan_value));
4556 check_isnan_maybe_exc ("real(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4557 __real__ result, INVALID_EXCEPTION);
4558 check_isnan ("imag(ctanh(0 + i NaN)) = NaN plus maybe invalid exception",
4559 __imag__ result);
4560 result = FUNC(ctanh) (BUILD_COMPLEX (5, nan_value));
4561 check_isnan_maybe_exc ("real(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4562 __real__ result, INVALID_EXCEPTION);
4563 check_isnan ("imag(ctanh(5 + i NaN)) = NaN plus maybe invalid exception",
4564 __imag__ result);
4565 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, nan_value));
4566 check_isnan_maybe_exc ("real(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4567 __real__ result, INVALID_EXCEPTION);
4568 check_isnan ("imag(ctanh(-0 + i NaN)) = NaN plus maybe invalid exception",
4569 __imag__ result);
4570 result = FUNC(ctanh) (BUILD_COMPLEX (-0.25, nan_value));
4571 check_isnan_maybe_exc ("real(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4572 __real__ result, INVALID_EXCEPTION);
4573 check_isnan ("imag(ctanh(-0.25 + i NaN)) = NaN plus maybe invalid exception",
4574 __imag__ result);
4576 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, nan_value));
4577 check_isnan ("real(ctanh(NaN + i NaN)) = NaN", __real__ result);
4578 check_isnan ("imag(ctanh(NaN + i NaN)) = NaN", __imag__ result);
4580 result = FUNC(ctanh) (BUILD_COMPLEX (0, M_PI_4l));
4581 check ("real(ctanh (0 + i pi/4)) == 0", __real__ result, 0);
4582 check_eps ("imag(ctanh (0 + i pi/4)) == 1", __imag__ result, 1,
4583 CHOOSE (0, 2e-16, 2e-7));
4585 result = FUNC(ctanh) (BUILD_COMPLEX (0.7, 1.2));
4586 check_eps ("real(ctanh(0.7 + i 1.2)) == 1.34721...", __real__ result,
4587 1.3472197399061191630L, CHOOSE (4e-17L, 6.7e-16, 2e-7));
4588 check_eps ("imag(ctanh(0.7 + i 1.2)) == -0.47786...", __imag__ result,
4589 0.4778641038326365540L, CHOOSE (9e-17L, 2.8e-16, 9e-8));
4591 result = FUNC(ctanh) (BUILD_COMPLEX (-2, -3));
4592 check_eps ("real(ctanh(-2 - i 3)) == -0.96538...", __real__ result,
4593 -0.9653858790221331242L, CHOOSE (2e-19L, 2e-16, 2e-7));
4594 check_eps ("imag(ctanh(-2 - i 3)) == 0.00988...", __imag__ result,
4595 0.0098843750383224937L, CHOOSE (7e-20L, 2e-16, 1e-9));
4599 static void
4600 clog_test (void)
4602 __complex__ MATHTYPE result;
4604 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, 0));
4605 check_isinfn_exc ("real(clog(-0 + i0)) = -Inf plus divide-by-zero exception",
4606 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4607 check ("imag(clog(-0 + i0)) = pi plus divide-by-zero exception",
4608 __imag__ result, M_PIl);
4609 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_zero));
4610 check_isinfn_exc ("real(clog(-0 - i0)) = -Inf plus divide-by-zero exception",
4611 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4612 check ("imag(clog(-0 - i0)) = -pi plus divide-by-zero exception",
4613 __imag__ result, -M_PIl);
4615 result = FUNC(clog) (BUILD_COMPLEX (0, 0));
4616 check_isinfn_exc ("real(clog(0 + i0)) = -Inf plus divide-by-zero exception",
4617 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4618 check ("imag(clog(0 + i0)) = 0 plus divide-by-zero exception",
4619 __imag__ result, 0);
4620 result = FUNC(clog) (BUILD_COMPLEX (0, minus_zero));
4621 check_isinfn_exc ("real(clog(0 - i0)) = -Inf plus divide-by-zero exception",
4622 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4623 check ("imag(clog(0 - i0)) = -0 plus divide-by-zero exception",
4624 __imag__ result, minus_zero);
4626 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, plus_infty));
4627 check_isinfp ("real(clog(-Inf + i Inf)) = +Inf", __real__ result);
4628 check ("imag(clog(-Inf + i Inf)) = 3*pi/4", __imag__ result,
4629 M_PIl - M_PI_4l);
4630 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_infty));
4631 check_isinfp ("real(clog(-Inf - i Inf)) = +Inf", __real__ result);
4632 check ("imag(clog(-Inf - i Inf)) = -3*pi/4", __imag__ result,
4633 M_PI_4l - M_PIl);
4635 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, plus_infty));
4636 check_isinfp ("real(clog(+Inf + i Inf)) = +Inf", __real__ result);
4637 check ("imag(clog(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4l);
4638 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_infty));
4639 check_isinfp ("real(clog(+Inf - i Inf)) = +Inf", __real__ result);
4640 check ("imag(clog(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4l);
4642 result = FUNC(clog) (BUILD_COMPLEX (0, plus_infty));
4643 check_isinfp ("real(clog(0 + i Inf)) = +Inf", __real__ result);
4644 check ("imag(clog(0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4645 result = FUNC(clog) (BUILD_COMPLEX (3, plus_infty));
4646 check_isinfp ("real(clog(3 + i Inf)) = +Inf", __real__ result);
4647 check ("imag(clog(3 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4648 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, plus_infty));
4649 check_isinfp ("real(clog(-0 + i Inf)) = +Inf", __real__ result);
4650 check ("imag(clog(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4651 result = FUNC(clog) (BUILD_COMPLEX (-3, plus_infty));
4652 check_isinfp ("real(clog(-3 + i Inf)) = +Inf", __real__ result);
4653 check ("imag(clog(-3 + i Inf)) = pi/2", __imag__ result, M_PI_2l);
4654 result = FUNC(clog) (BUILD_COMPLEX (0, minus_infty));
4655 check_isinfp ("real(clog(0 - i Inf)) = +Inf", __real__ result);
4656 check ("imag(clog(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4657 result = FUNC(clog) (BUILD_COMPLEX (3, minus_infty));
4658 check_isinfp ("real(clog(3 - i Inf)) = +Inf", __real__ result);
4659 check ("imag(clog(3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4660 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_infty));
4661 check_isinfp ("real(clog(-0 - i Inf)) = +Inf", __real__ result);
4662 check ("imag(clog(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4663 result = FUNC(clog) (BUILD_COMPLEX (-3, minus_infty));
4664 check_isinfp ("real(clog(-3 - i Inf)) = +Inf", __real__ result);
4665 check ("imag(clog(-3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2l);
4667 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 0));
4668 check_isinfp ("real(clog(-Inf + i0)) = +Inf", __real__ result);
4669 check ("imag(clog(-Inf + i0)) = pi", __imag__ result, M_PIl);
4670 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 1));
4671 check_isinfp ("real(clog(-Inf + i1)) = +Inf", __real__ result);
4672 check ("imag(clog(-Inf + i1)) = pi", __imag__ result, M_PIl);
4673 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_zero));
4674 check_isinfp ("real(clog(-Inf - i0)) = +Inf", __real__ result);
4675 check ("imag(clog(-Inf - i0)) = -pi", __imag__ result, -M_PIl);
4676 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, -1));
4677 check_isinfp ("real(clog(-Inf - i1)) = +Inf", __real__ result);
4678 check ("imag(clog(-Inf - i1)) = -pi", __imag__ result, -M_PIl);
4680 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 0));
4681 check_isinfp ("real(clog(+Inf + i0)) = +Inf", __real__ result);
4682 check ("imag(clog(+Inf + i0)) = 0", __imag__ result, 0);
4683 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 1));
4684 check_isinfp ("real(clog(+Inf + i1)) = +Inf", __real__ result);
4685 check ("imag(clog(+Inf + i1)) = 0", __imag__ result, 0);
4686 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_zero));
4687 check_isinfp ("real(clog(+Inf - i0)) = +Inf", __real__ result);
4688 check ("imag(clog(+Inf - i0)) = -0", __imag__ result, minus_zero);
4689 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, -1));
4690 check_isinfp ("real(clog(+Inf - i1)) = +Inf", __real__ result);
4691 check ("imag(clog(+Inf - i1)) = -0", __imag__ result, minus_zero);
4693 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, nan_value));
4694 check_isinfp ("real(clog(+Inf + i NaN)) = +Inf", __real__ result);
4695 check_isnan ("imag(clog(+Inf + i NaN)) = NaN", __imag__ result);
4696 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, nan_value));
4697 check_isinfp ("real(clog(-Inf + i NaN)) = +Inf", __real__ result);
4698 check_isnan ("imag(clog(-Inf + i NaN)) = NaN", __imag__ result);
4700 result = FUNC(clog) (BUILD_COMPLEX (nan_value, plus_infty));
4701 check_isinfp ("real(clog(NaN + i Inf)) = +Inf", __real__ result);
4702 check_isnan ("imag(clog(NaN + i Inf)) = NaN", __imag__ result);
4703 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_infty));
4704 check_isinfp ("real(clog(NaN - i Inf)) = +Inf", __real__ result);
4705 check_isnan ("imag(clog(NaN - i Inf)) = NaN", __imag__ result);
4707 result = FUNC(clog) (BUILD_COMPLEX (0, nan_value));
4708 check_isnan_maybe_exc ("real(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4709 __real__ result, INVALID_EXCEPTION);
4710 check_isnan ("imag(clog(0 + i NaN)) = NaN plus maybe invalid exception",
4711 __imag__ result);
4712 result = FUNC(clog) (BUILD_COMPLEX (3, nan_value));
4713 check_isnan_maybe_exc ("real(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4714 __real__ result, INVALID_EXCEPTION);
4715 check_isnan ("imag(clog(3 + i NaN)) = NaN plus maybe invalid exception",
4716 __imag__ result);
4717 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, nan_value));
4718 check_isnan_maybe_exc ("real(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4719 __real__ result, INVALID_EXCEPTION);
4720 check_isnan ("imag(clog(-0 + i NaN)) = NaN plus maybe invalid exception",
4721 __imag__ result);
4722 result = FUNC(clog) (BUILD_COMPLEX (-3, nan_value));
4723 check_isnan_maybe_exc ("real(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4724 __real__ result, INVALID_EXCEPTION);
4725 check_isnan ("imag(clog(-3 + i NaN)) = NaN plus maybe invalid exception",
4726 __imag__ result);
4728 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 0));
4729 check_isnan_maybe_exc ("real(clog(NaN + i0)) = NaN plus maybe invalid exception",
4730 __real__ result, INVALID_EXCEPTION);
4731 check_isnan ("imag(clog(NaN + i0)) = NaN plus maybe invalid exception",
4732 __imag__ result);
4733 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 5));
4734 check_isnan_maybe_exc ("real(clog(NaN + i5)) = NaN plus maybe invalid exception",
4735 __real__ result, INVALID_EXCEPTION);
4736 check_isnan ("imag(clog(NaN + i5)) = NaN plus maybe invalid exception",
4737 __imag__ result);
4738 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_zero));
4739 check_isnan_maybe_exc ("real(clog(NaN - i0)) = NaN plus maybe invalid exception",
4740 __real__ result, INVALID_EXCEPTION);
4741 check_isnan ("imag(clog(NaN - i0)) = NaN plus maybe invalid exception",
4742 __imag__ result);
4743 result = FUNC(clog) (BUILD_COMPLEX (nan_value, -5));
4744 check_isnan_maybe_exc ("real(clog(NaN - i5)) = NaN plus maybe invalid exception",
4745 __real__ result, INVALID_EXCEPTION);
4746 check_isnan ("imag(clog(NaN - i5)) = NaN plus maybe invalid exception",
4747 __imag__ result);
4749 result = FUNC(clog) (BUILD_COMPLEX (nan_value, nan_value));
4750 check_isnan ("real(clog(NaN + i NaN)) = NaN", __real__ result);
4751 check_isnan ("imag(clog(NaN + i NaN)) = NaN", __imag__ result);
4753 result = FUNC(clog) (BUILD_COMPLEX (0.7, 1.2));
4754 check_eps ("real(clog(0.7 + i 1.2)) == 0.32876...", __real__ result,
4755 0.3287600014583970919L, CHOOSE (5e-17L, 6e-17, 3e-8));
4756 check_eps ("imag(clog(0.7 + i 1.2)) == 1.04272...", __imag__ result,
4757 1.0427218783685369524L, CHOOSE (2e-17L, 2.5e-16, 1.2e-7));
4759 result = FUNC(clog) (BUILD_COMPLEX (-2, -3));
4760 check_eps ("real(clog(-2 - i 3)) == 1.28247...", __real__ result,
4761 1.2824746787307683680L, CHOOSE (3e-19L, 0, 0));
4762 check_eps ("imag(clog(-2 - i 3)) == -2.15879...", __imag__ result,
4763 -2.1587989303424641704L, CHOOSE (2e-18L, 5e-16, 8e-7));
4767 static void
4768 clog10_test (void)
4770 __complex__ MATHTYPE result;
4772 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, 0));
4773 check_isinfn_exc ("real(clog10(-0 + i0)) = -Inf plus divide-by-zero exception",
4774 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4775 check ("imag(clog10(-0 + i0)) = pi plus divide-by-zero exception",
4776 __imag__ result, M_PIl);
4777 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_zero));
4778 check_isinfn_exc ("real(clog10(-0 - i0)) = -Inf plus divide-by-zero exception",
4779 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4780 check ("imag(clog10(-0 - i0)) = -pi plus divide-by-zero exception",
4781 __imag__ result, -M_PIl);
4783 result = FUNC(clog10) (BUILD_COMPLEX (0, 0));
4784 check_isinfn_exc ("real(clog10(0 + i0)) = -Inf plus divide-by-zero exception",
4785 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4786 check ("imag(clog10(0 + i0)) = 0 plus divide-by-zero exception",
4787 __imag__ result, 0);
4788 result = FUNC(clog10) (BUILD_COMPLEX (0, minus_zero));
4789 check_isinfn_exc ("real(clog10(0 - i0)) = -Inf plus divide-by-zero exception",
4790 __real__ result, DIVIDE_BY_ZERO_EXCEPTION);
4791 check ("imag(clog10(0 - i0)) = -0 plus divide-by-zero exception",
4792 __imag__ result, minus_zero);
4794 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, plus_infty));
4795 check_isinfp ("real(clog10(-Inf + i Inf)) = +Inf", __real__ result);
4796 check_eps ("imag(clog10(-Inf + i Inf)) = 3*pi/4*M_LOG10E", __imag__ result,
4797 (M_PIl - M_PI_4l) * M_LOG10El, CHOOSE (0, 3e-16, 0));
4798 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_infty));
4799 check_isinfp ("real(clog10(-Inf - i Inf)) = +Inf", __real__ result);
4800 check_eps ("imag(clog10(-Inf - i Inf)) = -3*pi/4*M_LOG10E", __imag__ result,
4801 (M_PI_4l - M_PIl) * M_LOG10El, CHOOSE (0, 3e-16, 0));
4803 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, plus_infty));
4804 check_isinfp ("real(clog10(+Inf + i Inf)) = +Inf", __real__ result);
4805 check_eps ("imag(clog10(+Inf + i Inf)) = pi/4*M_LOG10E", __imag__ result,
4806 M_PI_4l * M_LOG10El, CHOOSE (0, 6e-17, 3e-8));
4807 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_infty));
4808 check_isinfp ("real(clog10(+Inf - i Inf)) = +Inf", __real__ result);
4809 check_eps ("imag(clog10(+Inf - i Inf)) = -pi/4*M_LOG10E", __imag__ result,
4810 -M_PI_4l * M_LOG10El, CHOOSE (0, 6e-17, 3e-8));
4812 result = FUNC(clog10) (BUILD_COMPLEX (0, plus_infty));
4813 check_isinfp ("real(clog10(0 + i Inf)) = +Inf", __real__ result);
4814 check_eps ("imag(clog10(0 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4815 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4816 result = FUNC(clog10) (BUILD_COMPLEX (3, plus_infty));
4817 check_isinfp ("real(clog10(3 + i Inf)) = +Inf", __real__ result);
4818 check_eps ("imag(clog10(3 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4819 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4820 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, plus_infty));
4821 check_isinfp ("real(clog10(-0 + i Inf)) = +Inf", __real__ result);
4822 check_eps ("imag(clog10(-0 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4823 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4824 result = FUNC(clog10) (BUILD_COMPLEX (-3, plus_infty));
4825 check_isinfp ("real(clog10(-3 + i Inf)) = +Inf", __real__ result);
4826 check_eps ("imag(clog10(-3 + i Inf)) = pi/2*M_LOG10E", __imag__ result,
4827 M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4828 result = FUNC(clog10) (BUILD_COMPLEX (0, minus_infty));
4829 check_isinfp ("real(clog10(0 - i Inf)) = +Inf", __real__ result);
4830 check_eps ("imag(clog10(0 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4831 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4832 result = FUNC(clog10) (BUILD_COMPLEX (3, minus_infty));
4833 check_isinfp ("real(clog10(3 - i Inf)) = +Inf", __real__ result);
4834 check_eps ("imag(clog10(3 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4835 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4836 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, minus_infty));
4837 check_isinfp ("real(clog10(-0 - i Inf)) = +Inf", __real__ result);
4838 check_eps ("imag(clog10(-0 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4839 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4840 result = FUNC(clog10) (BUILD_COMPLEX (-3, minus_infty));
4841 check_isinfp ("real(clog10(-3 - i Inf)) = +Inf", __real__ result);
4842 check_eps ("imag(clog10(-3 - i Inf)) = -pi/2*M_LOG10E", __imag__ result,
4843 -M_PI_2l * M_LOG10El, CHOOSE (0, 2e-16, 6e-8));
4845 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 0));
4846 check_isinfp ("real(clog10(-Inf + i0)) = +Inf", __real__ result);
4847 check_eps ("imag(clog10(-Inf + i0)) = pi*M_LOG10E", __imag__ result,
4848 M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4849 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, 1));
4850 check_isinfp ("real(clog10(-Inf + i1)) = +Inf", __real__ result);
4851 check_eps ("imag(clog10(-Inf + i1)) = pi*M_LOG10E", __imag__ result,
4852 M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4853 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, minus_zero));
4854 check_isinfp ("real(clog10(-Inf - i0)) = +Inf", __real__ result);
4855 check_eps ("imag(clog10(-Inf - i0)) = -pi*M_LOG10E", __imag__ result,
4856 -M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4857 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, -1));
4858 check_isinfp ("real(clog10(-Inf - i1)) = +Inf", __real__ result);
4859 check_eps ("imag(clog10(-Inf - i1)) = -pi*M_LOG10E", __imag__ result,
4860 -M_PIl * M_LOG10El, CHOOSE (0, 3e-16, 2e-7));
4862 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 0));
4863 check_isinfp ("real(clog10(+Inf + i0)) = +Inf", __real__ result);
4864 check ("imag(clog10(+Inf + i0)) = 0", __imag__ result, 0);
4865 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, 1));
4866 check_isinfp ("real(clog10(+Inf + i1)) = +Inf", __real__ result);
4867 check ("imag(clog10(+Inf + i1)) = 0", __imag__ result, 0);
4868 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, minus_zero));
4869 check_isinfp ("real(clog10(+Inf - i0)) = +Inf", __real__ result);
4870 check ("imag(clog10(+Inf - i0)) = -0", __imag__ result, minus_zero);
4871 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, -1));
4872 check_isinfp ("real(clog10(+Inf - i1)) = +Inf", __real__ result);
4873 check ("imag(clog10(+Inf - i1)) = -0", __imag__ result, minus_zero);
4875 result = FUNC(clog10) (BUILD_COMPLEX (plus_infty, nan_value));
4876 check_isinfp ("real(clog10(+Inf + i NaN)) = +Inf", __real__ result);
4877 check_isnan ("imag(clog10(+Inf + i NaN)) = NaN", __imag__ result);
4878 result = FUNC(clog10) (BUILD_COMPLEX (minus_infty, nan_value));
4879 check_isinfp ("real(clog10(-Inf + i NaN)) = +Inf", __real__ result);
4880 check_isnan ("imag(clog10(-Inf + i NaN)) = NaN", __imag__ result);
4882 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, plus_infty));
4883 check_isinfp ("real(clog10(NaN + i Inf)) = +Inf", __real__ result);
4884 check_isnan ("imag(clog10(NaN + i Inf)) = NaN", __imag__ result);
4885 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_infty));
4886 check_isinfp ("real(clog10(NaN - i Inf)) = +Inf", __real__ result);
4887 check_isnan ("imag(clog10(NaN - i Inf)) = NaN", __imag__ result);
4889 result = FUNC(clog10) (BUILD_COMPLEX (0, nan_value));
4890 check_isnan_maybe_exc ("real(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4891 __real__ result, INVALID_EXCEPTION);
4892 check_isnan ("imag(clog10(0 + i NaN)) = NaN plus maybe invalid exception",
4893 __imag__ result);
4894 result = FUNC(clog10) (BUILD_COMPLEX (3, nan_value));
4895 check_isnan_maybe_exc ("real(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4896 __real__ result, INVALID_EXCEPTION);
4897 check_isnan ("imag(clog10(3 + i NaN)) = NaN plus maybe invalid exception",
4898 __imag__ result);
4899 result = FUNC(clog10) (BUILD_COMPLEX (minus_zero, nan_value));
4900 check_isnan_maybe_exc ("real(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4901 __real__ result, INVALID_EXCEPTION);
4902 check_isnan ("imag(clog10(-0 + i NaN)) = NaN plus maybe invalid exception",
4903 __imag__ result);
4904 result = FUNC(clog10) (BUILD_COMPLEX (-3, nan_value));
4905 check_isnan_maybe_exc ("real(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4906 __real__ result, INVALID_EXCEPTION);
4907 check_isnan ("imag(clog10(-3 + i NaN)) = NaN plus maybe invalid exception",
4908 __imag__ result);
4910 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 0));
4911 check_isnan_maybe_exc ("real(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4912 __real__ result, INVALID_EXCEPTION);
4913 check_isnan ("imag(clog10(NaN + i0)) = NaN plus maybe invalid exception",
4914 __imag__ result);
4915 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, 5));
4916 check_isnan_maybe_exc ("real(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4917 __real__ result, INVALID_EXCEPTION);
4918 check_isnan ("imag(clog10(NaN + i5)) = NaN plus maybe invalid exception",
4919 __imag__ result);
4920 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, minus_zero));
4921 check_isnan_maybe_exc ("real(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4922 __real__ result, INVALID_EXCEPTION);
4923 check_isnan ("imag(clog10(NaN - i0)) = NaN plus maybe invalid exception",
4924 __imag__ result);
4925 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, -5));
4926 check_isnan_maybe_exc ("real(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4927 __real__ result, INVALID_EXCEPTION);
4928 check_isnan ("imag(clog10(NaN - i5)) = NaN plus maybe invalid exception",
4929 __imag__ result);
4931 result = FUNC(clog10) (BUILD_COMPLEX (nan_value, nan_value));
4932 check_isnan ("real(clog10(NaN + i NaN)) = NaN", __real__ result);
4933 check_isnan ("imag(clog10(NaN + i NaN)) = NaN", __imag__ result);
4935 result = FUNC(clog10) (BUILD_COMPLEX (0.7, 1.2));
4936 check_eps ("real(clog10(0.7 + i 1.2)) == 0.14277...", __real__ result,
4937 0.1427786545038868803L, CHOOSE (2e-17L, 6e-17, 2e-8));
4938 check_eps ("imag(clog10(0.7 + i 1.2)) == 0.45284...", __imag__ result,
4939 0.4528483579352493248L, CHOOSE (6e-18, 6e-17, 6e-8));
4941 result = FUNC(clog10) (BUILD_COMPLEX (-2, -3));
4942 check_eps ("real(clog10(-2 - i 3)) == 0.55697...", __real__ result,
4943 0.5569716761534183846L, CHOOSE (6e-20L, 0, 0));
4944 check_eps ("imag(clog10(-2 - i 3)) == -0.93755...", __imag__ result,
4945 -0.9375544629863747085L, CHOOSE (7e-19L, 2e-16, 3e-7));
4949 static void
4950 csqrt_test (void)
4952 __complex__ MATHTYPE result;
4954 result = FUNC(csqrt) (BUILD_COMPLEX (0, 0));
4955 check ("real(csqrt(0 + i0)) = 0", __real__ result, 0);
4956 check ("imag(csqrt(0 + i0)) = 0", __imag__ result, 0);
4957 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_zero));
4958 check ("real(csqrt(0 - i0)) = 0", __real__ result, 0);
4959 check ("imag(csqrt(0 - i0)) = -0", __imag__ result, minus_zero);
4960 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, 0));
4961 check ("real(csqrt(-0 + i0)) = 0", __real__ result, 0);
4962 check ("imag(csqrt(-0 + i0)) = 0", __imag__ result, 0);
4963 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_zero));
4964 check ("real(csqrt(-0 - i0)) = 0", __real__ result, 0);
4965 check ("imag(csqrt(-0 - i0)) = -0", __imag__ result, minus_zero);
4967 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 0));
4968 check ("real(csqrt(-Inf + i0)) = 0", __real__ result, 0);
4969 check_isinfp ("imag(csqrt(-Inf + i0)) = +Inf", __imag__ result);
4970 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 6));
4971 check ("real(csqrt(-Inf + i6)) = 0", __real__ result, 0);
4972 check_isinfp ("imag(csqrt(-Inf + i6)) = +Inf", __imag__ result);
4973 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_zero));
4974 check ("real(csqrt(-Inf - i0)) = 0", __real__ result, 0);
4975 check_isinfn ("imag(csqrt(-Inf - i0)) = -Inf", __imag__ result);
4976 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, -6));
4977 check ("real(csqrt(-Inf - i6)) = 0", __real__ result, 0);
4978 check_isinfn ("imag(csqrt(-Inf - i6)) = -Inf", __imag__ result);
4980 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 0));
4981 check_isinfp ("real(csqrt(+Inf + i0)) = +Inf", __real__ result);
4982 check ("imag(csqrt(+Inf + i0)) = 0", __imag__ result, 0);
4983 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 6));
4984 check_isinfp ("real(csqrt(+Inf + i6)) = +Inf", __real__ result);
4985 check ("imag(csqrt(+Inf + i6)) = 0", __imag__ result, 0);
4986 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_zero));
4987 check_isinfp ("real(csqrt(+Inf - i0)) = +Inf", __real__ result);
4988 check ("imag(csqrt(+Inf - i0)) = -0", __imag__ result, minus_zero);
4989 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, -6));
4990 check_isinfp ("real(csqrt(+Inf - i6)) = +Inf", __real__ result);
4991 check ("imag(csqrt(+Inf - i6)) = -0", __imag__ result, minus_zero);
4993 result = FUNC(csqrt) (BUILD_COMPLEX (0, plus_infty));
4994 check_isinfp ("real(csqrt(0 + i Inf)) = +Inf", __real__ result);
4995 check_isinfp ("imag(csqrt(0 + i Inf)) = +Inf", __imag__ result);
4996 result = FUNC(csqrt) (BUILD_COMPLEX (4, plus_infty));
4997 check_isinfp ("real(csqrt(4 + i Inf)) = +Inf", __real__ result);
4998 check_isinfp ("imag(csqrt(4 + i Inf)) = +Inf", __imag__ result);
4999 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, plus_infty));
5000 check_isinfp ("real(csqrt(+Inf + i Inf)) = +Inf", __real__ result);
5001 check_isinfp ("imag(csqrt(+Inf + i Inf)) = +Inf", __imag__ result);
5002 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, plus_infty));
5003 check_isinfp ("real(csqrt(-0 + i Inf)) = +Inf", __real__ result);
5004 check_isinfp ("imag(csqrt(-0 + i Inf)) = +Inf", __imag__ result);
5005 result = FUNC(csqrt) (BUILD_COMPLEX (-4, plus_infty));
5006 check_isinfp ("real(csqrt(-4 + i Inf)) = +Inf", __real__ result);
5007 check_isinfp ("imag(csqrt(-4 + i Inf)) = +Inf", __imag__ result);
5008 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, plus_infty));
5009 check_isinfp ("real(csqrt(-Inf + i Inf)) = +Inf", __real__ result);
5010 check_isinfp ("imag(csqrt(-Inf + i Inf)) = +Inf", __imag__ result);
5011 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_infty));
5012 check_isinfp ("real(csqrt(0 - i Inf)) = +Inf", __real__ result);
5013 check_isinfn ("imag(csqrt(0 - i Inf)) = -Inf", __imag__ result);
5014 result = FUNC(csqrt) (BUILD_COMPLEX (4, minus_infty));
5015 check_isinfp ("real(csqrt(4 - i Inf)) = +Inf", __real__ result);
5016 check_isinfn ("imag(csqrt(4 - i Inf)) = -Inf", __imag__ result);
5017 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_infty));
5018 check_isinfp ("real(csqrt(+Inf - i Inf)) = +Inf", __real__ result);
5019 check_isinfn ("imag(csqrt(+Inf - i Inf)) = -Inf", __imag__ result);
5020 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_infty));
5021 check_isinfp ("real(csqrt(-0 - i Inf)) = +Inf", __real__ result);
5022 check_isinfn ("imag(csqrt(-0 - i Inf)) = -Inf", __imag__ result);
5023 result = FUNC(csqrt) (BUILD_COMPLEX (-4, minus_infty));
5024 check_isinfp ("real(csqrt(-4 - i Inf)) = +Inf", __real__ result);
5025 check_isinfn ("imag(csqrt(-4 - i Inf)) = -Inf", __imag__ result);
5026 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_infty));
5027 check_isinfp ("real(csqrt(-Inf - i Inf)) = +Inf", __real__ result);
5028 check_isinfn ("imag(csqrt(-Inf - i Inf)) = -Inf", __imag__ result);
5030 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, nan_value));
5031 check_isnan ("real(csqrt(-Inf + i NaN)) = NaN", __real__ result);
5032 check_isinfp ("imag(csqrt(-Inf + i NaN)) = +-Inf",
5033 FUNC(fabs) (__imag__ result));
5035 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, nan_value));
5036 check_isinfp ("real(csqrt(+Inf + i NaN)) = +Inf", __real__ result);
5037 check_isnan ("imag(csqrt(+Inf + i NaN)) = NaN", __imag__ result);
5039 result = FUNC(csqrt) (BUILD_COMPLEX (0, nan_value));
5040 check_isnan_maybe_exc ("real(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
5041 __real__ result, INVALID_EXCEPTION);
5042 check_isnan ("imag(csqrt(0 + i NaN)) = NaN plus maybe invalid exception",
5043 __imag__ result);
5044 result = FUNC(csqrt) (BUILD_COMPLEX (1, nan_value));
5045 check_isnan_maybe_exc ("real(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
5046 __real__ result, INVALID_EXCEPTION);
5047 check_isnan ("imag(csqrt(1 + i NaN)) = NaN plus maybe invalid exception",
5048 __imag__ result);
5049 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, nan_value));
5050 check_isnan_maybe_exc ("real(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
5051 __real__ result, INVALID_EXCEPTION);
5052 check_isnan ("imag(csqrt(-0 + i NaN)) = NaN plus maybe invalid exception",
5053 __imag__ result);
5054 result = FUNC(csqrt) (BUILD_COMPLEX (-1, nan_value));
5055 check_isnan_maybe_exc ("real(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
5056 __real__ result, INVALID_EXCEPTION);
5057 check_isnan ("imag(csqrt(-1 + i NaN)) = NaN plus maybe invalid exception",
5058 __imag__ result);
5060 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 0));
5061 check_isnan_maybe_exc ("real(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
5062 __real__ result, INVALID_EXCEPTION);
5063 check_isnan ("imag(csqrt(NaN + i0)) = NaN plus maybe invalid exception",
5064 __imag__ result);
5065 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 8));
5066 check_isnan_maybe_exc ("real(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
5067 __real__ result, INVALID_EXCEPTION);
5068 check_isnan ("imag(csqrt(NaN + i8)) = NaN plus maybe invalid exception",
5069 __imag__ result);
5070 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, minus_zero));
5071 check_isnan_maybe_exc ("real(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
5072 __real__ result, INVALID_EXCEPTION);
5073 check_isnan ("imag(csqrt(NaN - i0)) = NaN plus maybe invalid exception",
5074 __imag__ result);
5075 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, -8));
5076 check_isnan_maybe_exc ("real(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
5077 __real__ result, INVALID_EXCEPTION);
5078 check_isnan ("imag(csqrt(NaN - i8)) = NaN plus maybe invalid exception",
5079 __imag__ result);
5081 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, nan_value));
5082 check_isnan ("real(csqrt(NaN + i NaN)) = NaN", __real__ result);
5083 check_isnan ("imag(csqrt(NaN + i NaN)) = NaN", __imag__ result);
5085 result = FUNC(csqrt) (BUILD_COMPLEX (16.0, -30.0));
5086 check ("real(csqrt(16 - 30i)) = 5", __real__ result, 5.0);
5087 check ("imag(csqrt(16 - 30i)) = -3", __imag__ result, -3.0);
5089 result = FUNC(csqrt) (BUILD_COMPLEX (-1, 0));
5090 check ("real(csqrt(1 + i0) = 0", __real__ result, 0);
5091 check ("imag(csqrt(1 + i0) = 1", __imag__ result, 1);
5093 result = FUNC(csqrt) (BUILD_COMPLEX (0, 2));
5094 check ("real(csqrt(0 + i 2) = 1", __real__ result, 1);
5095 check ("imag(csqrt(0 + i 2) = 1", __imag__ result, 1);
5097 result = FUNC(csqrt) (BUILD_COMPLEX (119, 120));
5098 check ("real(csqrt(119 + i 120) = 12", __real__ result, 12);
5099 check ("imag(csqrt(119 + i 120) = 5", __imag__ result, 5);
5101 result = FUNC(csqrt) (BUILD_COMPLEX (0.7, 1.2));
5102 check_eps ("real(csqrt(0.7 + i 1.2)) == 1.02206...", __real__ result,
5103 1.0220676100300264507L, CHOOSE (3e-17L, 3e-16, 2e-7));
5104 check_eps ("imag(csqrt(0.7 + i 1.2)) == 0.58704...", __imag__ result,
5105 0.5870453129635652115L, CHOOSE (7e-18L, 0, 6e-8));
5107 result = FUNC(csqrt) (BUILD_COMPLEX (-2, -3));
5108 check_eps ("real(csqrt(-2 - i 3)) == 0.89597...", __real__ result,
5109 0.8959774761298381247L, CHOOSE (6e-16L, 4e-16, 6e-8));
5110 check_eps ("imag(csqrt(-2 - i 3)) == -1.67414...", __imag__ result,
5111 -1.6741492280355400404L, CHOOSE (0, 5e-16, 0));
5113 result = FUNC(csqrt) (BUILD_COMPLEX (-2, 3));
5114 check_eps ("real(csqrt(-2 + i 3)) == 0.89597...", __real__ result,
5115 0.8959774761298381247L, CHOOSE (6e-20L, 4e-16, 6e-8));
5116 check_eps ("imag(csqrt(-2 + i 3)) == 1.67414...", __imag__ result,
5117 1.6741492280355400404L, CHOOSE (0, 5e-16, 0));
5121 static void
5122 cpow_test (void)
5124 __complex__ MATHTYPE result;
5126 result = FUNC(cpow) (BUILD_COMPLEX (1, 0), BUILD_COMPLEX (0, 0));
5127 check ("real(cpow (1 + i0), (0 + i0)) == 0", __real__ result, 1);
5128 check ("imag(cpow (1 + i0), (0 + i0)) == 0", __imag__ result, 0);
5130 result = FUNC(cpow) (BUILD_COMPLEX (2, 0), BUILD_COMPLEX (10, 0));
5131 check_eps ("real(cpow (2 + i0), (10 + i0)) == 1024", __real__ result, 1024,
5132 CHOOSE (6e-16L, 1.2e-13, 0));
5133 check ("imag(cpow (2 + i0), (10 + i0)) == 0", __imag__ result, 0);
5135 result = FUNC(cpow) (BUILD_COMPLEX (M_El, 0), BUILD_COMPLEX (0, 2 * M_PIl));
5136 check_eps ("real(cpow (e + i0), (0 + i 2*PI)) == 1", __real__ result, 1,
5137 CHOOSE (0, 0, 6e-8));
5138 check_eps ("imag(cpow (e + i0), (0 + i 2*PI)) == 0", __imag__ result, 0,
5139 CHOOSE (3e-18L, 3e-16, 4e-7));
5141 result = FUNC(cpow) (BUILD_COMPLEX (2, 3), BUILD_COMPLEX (4, 0));
5142 check_eps ("real(cpow (2 + i3), (4 + i0)) == -119", __real__ result, -119,
5143 CHOOSE (9e-16L, 2e-14, 4e-5));
5144 check_eps ("imag(cpow (2 + i3), (4 + i0)) == -120", __imag__ result, -120,
5145 CHOOSE (1e-15L, 0, 5e-5));
5149 static void
5150 cabs_test (void)
5152 /* cabs (x + iy) is specified as hypot (x,y) */
5153 MATHTYPE a;
5154 a = random_greater (0);
5155 check_isinfp_ext ("cabs (+inf + i x) == +inf",
5156 FUNC(cabs) (BUILD_COMPLEX (plus_infty, a)), a);
5157 check_isinfp_ext ("cabs (-inf + i x) == +inf",
5158 FUNC(cabs) (BUILD_COMPLEX (minus_infty, a)), a);
5160 check_isinfp ("cabs (+inf+ iNaN) == +inf",
5161 FUNC(cabs) (BUILD_COMPLEX (minus_infty, nan_value)));
5162 check_isinfp ("cabs (-inf+ iNaN) == +inf",
5163 FUNC(cabs) (BUILD_COMPLEX (minus_infty, nan_value)));
5165 check_isnan ("cabs (NaN+ iNaN) == NaN",
5166 FUNC(cabs) (BUILD_COMPLEX (nan_value, nan_value)));
5168 a = FUNC(cabs) (BUILD_COMPLEX (12.4L, 0.7L));
5169 check ("cabs (x,y) == cabs (y,x)",
5170 FUNC(cabs) (BUILD_COMPLEX (0.7L, 12.4L)), a);
5171 check ("cabs (x,y) == cabs (-x,y)",
5172 FUNC(cabs) (BUILD_COMPLEX (-12.4L, 0.7L)), a);
5173 check ("cabs (x,y) == cabs (-y,x)",
5174 FUNC(cabs) (BUILD_COMPLEX (-0.7L, 12.4L)), a);
5175 check ("cabs (x,y) == cabs (-x,-y)",
5176 FUNC(cabs) (BUILD_COMPLEX (-12.4L, -0.7L)), a);
5177 check ("cabs (x,y) == cabs (-y,-x)",
5178 FUNC(cabs) (BUILD_COMPLEX (-0.7L, -12.4L)), a);
5179 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX (-0.7L, 0)), 0.7L);
5180 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX (0.7L, 0)), 0.7L);
5181 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX (-1.0L, 0)), 1.0L);
5182 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX (1.0L, 0)), 1.0L);
5183 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX (-5.7e7L, 0)),
5184 5.7e7L);
5185 check ("cabs (x,0) == fabs (x)", FUNC(cabs) (BUILD_COMPLEX (5.7e7L, 0)),
5186 5.7e7L);
5188 check_eps ("cabs (0.7 + i 1.2) == 1.38924...", FUNC(cabs) (BUILD_COMPLEX (0.7, 1.2)),
5189 1.3892443989449804508L, CHOOSE (7e-17L, 3e-16, 0));
5193 static void
5194 carg_test (void)
5196 /* carg (x + iy) is specified as atan2 (y, x) */
5197 MATHTYPE x;
5199 x = random_greater (0);
5200 check ("carg (x + i 0) == 0 for x > 0",
5201 FUNC(carg) (BUILD_COMPLEX (x, 0)), 0);
5202 x = random_greater (0);
5203 check ("carg (x - i 0) == -0 for x > 0",
5204 FUNC(carg) (BUILD_COMPLEX (x, minus_zero)), minus_zero);
5206 check ("carg (+0 + i 0) == +0", FUNC(carg) (BUILD_COMPLEX (0, 0)), 0);
5207 check ("carg (+0 - i 0) == -0", FUNC(carg) (BUILD_COMPLEX (0, minus_zero)),
5208 minus_zero);
5210 x = -random_greater (0);
5211 check ("carg (x + i 0) == +pi for x < 0", FUNC(carg) (BUILD_COMPLEX (x, 0)),
5212 M_PIl);
5214 x = -random_greater (0);
5215 check ("carg (x - i 0) == -pi for x < 0",
5216 FUNC(carg) (BUILD_COMPLEX (x, minus_zero)), -M_PIl);
5218 check ("carg (-0 + i 0) == +pi", FUNC(carg) (BUILD_COMPLEX (minus_zero, 0)),
5219 M_PIl);
5220 check ("carg (-0 - i 0) == -pi",
5221 FUNC(carg) (BUILD_COMPLEX (minus_zero, minus_zero)), -M_PIl);
5223 x = random_greater (0);
5224 check ("carg (+0 + i y) == pi/2 for y > 0", FUNC(carg) (BUILD_COMPLEX (0, x)),
5225 M_PI_2l);
5227 x = random_greater (0);
5228 check ("carg (-0 + i y) == pi/2 for y > 0",
5229 FUNC(carg) (BUILD_COMPLEX (minus_zero, x)), M_PI_2l);
5231 x = random_less (0);
5232 check ("carg (+0 + i y) == -pi/2 for y < 0", FUNC(carg) (BUILD_COMPLEX (0, x)),
5233 -M_PI_2l);
5235 x = random_less (0);
5236 check ("carg (-0 + i y) == -pi/2 for y < 0",
5237 FUNC(carg) (BUILD_COMPLEX (minus_zero, x)), -M_PI_2l);
5239 x = random_greater (0);
5240 check ("carg (inf + i y) == +0 for finite y > 0",
5241 FUNC(carg) (BUILD_COMPLEX (plus_infty, x)), 0);
5243 x = -random_greater (0);
5244 check ("carg (inf + i y) == -0 for finite y < 0",
5245 FUNC(carg) (BUILD_COMPLEX (plus_infty, x)), minus_zero);
5247 x = random_value (-1e4, 1e4);
5248 check ("carg(x + i inf) == pi/2 for finite x",
5249 FUNC(carg) (BUILD_COMPLEX (x, plus_infty)), M_PI_2l);
5251 x = random_value (-1e4, 1e4);
5252 check ("carg(x - i inf) == -pi/2 for finite x",
5253 FUNC(carg) (BUILD_COMPLEX (x, minus_infty)), -M_PI_2l);
5255 x = random_greater (0);
5256 check ("carg (-inf + i y) == +pi for finite y > 0",
5257 FUNC(carg) (BUILD_COMPLEX (minus_infty, x)), M_PIl);
5259 x = -random_greater (0);
5260 check ("carg (-inf + i y) == -pi for finite y < 0",
5261 FUNC(carg) (BUILD_COMPLEX (minus_infty, x)), -M_PIl);
5263 check ("carg (+inf + i inf) == +pi/4",
5264 FUNC(carg) (BUILD_COMPLEX (plus_infty, plus_infty)), M_PI_4l);
5266 check ("carg (+inf -i inf) == -pi/4",
5267 FUNC(carg) (BUILD_COMPLEX (plus_infty, minus_infty)), -M_PI_4l);
5269 check ("carg (-inf +i inf) == +3*pi/4",
5270 FUNC(carg) (BUILD_COMPLEX (minus_infty, plus_infty)), 3 * M_PI_4l);
5272 check ("carg (-inf -i inf) == -3*pi/4",
5273 FUNC(carg) (BUILD_COMPLEX (minus_infty, minus_infty)), -3 * M_PI_4l);
5277 static void
5278 nearbyint_test (void)
5280 check ("nearbyint(+0) = 0", FUNC(nearbyint) (0.0), 0.0);
5281 check ("nearbyint(-0) = -0", FUNC(nearbyint) (minus_zero), minus_zero);
5282 check_isinfp ("nearbyint(+Inf) = +Inf", FUNC(nearbyint) (plus_infty));
5283 check_isinfn ("nearbyint(-Inf) = -Inf", FUNC(nearbyint) (minus_infty));
5287 static void
5288 rint_test (void)
5290 check ("rint(0) = 0", FUNC(rint) (0.0), 0.0);
5291 check ("rint(-0) = -0", FUNC(rint) (minus_zero), minus_zero);
5292 check_isinfp ("rint(+Inf) = +Inf", FUNC(rint) (plus_infty));
5293 check_isinfn ("rint(-Inf) = -Inf", FUNC(rint) (minus_infty));
5297 static void
5298 lrint_test (void)
5300 /* XXX this test is incomplete. We need to have a way to specifiy
5301 the rounding method and test the critical cases. So far, only
5302 unproblematic numbers are tested. */
5304 check_long ("lrint(0) = 0", FUNC(lrint) (0.0), 0);
5305 check_long ("lrint(-0) = 0", FUNC(lrint) (minus_zero), 0);
5306 check_long ("lrint(0.2) = 0", FUNC(lrint) (0.2), 0);
5307 check_long ("lrint(-0.2) = 0", FUNC(lrint) (-0.2), 0);
5309 check_long ("lrint(1.4) = 1", FUNC(lrint) (1.4), 1);
5310 check_long ("lrint(-1.4) = -1", FUNC(lrint) (-1.4), -1);
5312 check_long ("lrint(8388600.3) = 8388600", FUNC(lrint) (8388600.3), 8388600);
5313 check_long ("lrint(-8388600.3) = -8388600", FUNC(lrint) (-8388600.3),
5314 -8388600);
5318 static void
5319 llrint_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_longlong ("llrint(0) = 0", FUNC(llrint) (0.0), 0);
5326 check_longlong ("llrint(-0) = 0", FUNC(llrint) (minus_zero), 0);
5327 check_longlong ("llrint(0.2) = 0", FUNC(llrint) (0.2), 0);
5328 check_longlong ("llrint(-0.2) = 0", FUNC(llrint) (-0.2), 0);
5330 check_longlong ("llrint(1.4) = 1", FUNC(llrint) (1.4), 1);
5331 check_longlong ("llrint(-1.4) = -1", FUNC(llrint) (-1.4), -1);
5333 check_longlong ("llrint(8388600.3) = 8388600", FUNC(llrint) (8388600.3),
5334 8388600);
5335 check_longlong ("llrint(-8388600.3) = -8388600", FUNC(llrint) (-8388600.3),
5336 -8388600);
5338 /* Test boundary conditions. */
5339 /* 0x1FFFFF */
5340 check_longlong ("llrint(2097151.0) = 2097151", FUNC(llrint) (2097151.0),
5341 2097151LL);
5342 /* 0x800000 */
5343 check_longlong ("llrint(8388608.0) = 8388608", FUNC(llrint) (8388608.0),
5344 8388608LL);
5345 /* 0x1000000 */
5346 check_longlong ("llrint(16777216.0) = 16777216",
5347 FUNC(llrint) (16777216.0), 16777216LL);
5348 /* 0x20000000000 */
5349 check_longlong ("llrint(2199023255552.0) = 2199023255552",
5350 FUNC(llrint) (2199023255552.0), 2199023255552LL);
5351 /* 0x40000000000 */
5352 check_longlong ("llrint(4398046511104.0) = 4398046511104",
5353 FUNC(llrint) (4398046511104.0), 4398046511104LL);
5354 /* 0x10000000000000 */
5355 check_longlong ("llrint(4503599627370496.0) = 4503599627370496",
5356 FUNC(llrint) (4503599627370496.0), 4503599627370496LL);
5357 /* 0x10000080000000 */
5358 check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5359 FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5360 /* 0x20000000000000 */
5361 check_longlong ("llrint(9007199254740992.0) = 9007199254740992",
5362 FUNC(llrint) (9007199254740992.0), 9007199254740992LL);
5363 /* 0x80000000000000 */
5364 check_longlong ("llrint(36028797018963968.0) = 36028797018963968",
5365 FUNC(llrint) (36028797018963968.0), 36028797018963968LL);
5366 /* 0x100000000000000 */
5367 check_longlong ("llrint(72057594037927936.0) = 72057594037927936",
5368 FUNC(llrint) (72057594037927936.0), 72057594037927936LL);
5372 static void
5373 round_test (void)
5375 check ("round(0) = 0", FUNC(round) (0), 0);
5376 check ("round(-0) = -0", FUNC(round) (minus_zero), minus_zero);
5377 check ("round(0.2) = 0", FUNC(round) (0.2), 0.0);
5378 check ("round(-0.2) = -0", FUNC(round) (-0.2), minus_zero);
5379 check ("round(0.5) = 1", FUNC(round) (0.5), 1.0);
5380 check ("round(-0.5) = -1", FUNC(round) (-0.5), -1.0);
5381 check ("round(0.8) = 1", FUNC(round) (0.8), 1.0);
5382 check ("round(-0.8) = -1", FUNC(round) (-0.8), -1.0);
5383 check ("round(1.5) = 2", FUNC(round) (1.5), 2.0);
5384 check ("round(-1.5) = -2", FUNC(round) (-1.5), -2.0);
5385 check ("round(2097152.5) = 2097153", FUNC(round) (2097152.5), 2097153);
5386 check ("round(-2097152.5) = -2097153", FUNC(round) (-2097152.5), -2097153);
5390 static void
5391 lround_test (void)
5393 check_long ("lround(0) = 0", FUNC(lround) (0), 0);
5394 check_long ("lround(-0) = 0", FUNC(lround) (minus_zero), 0);
5395 check_long ("lround(0.2) = 0", FUNC(lround) (0.2), 0.0);
5396 check_long ("lround(-0.2) = 0", FUNC(lround) (-0.2), 0);
5397 check_long ("lround(0.5) = 1", FUNC(lround) (0.5), 1);
5398 check_long ("lround(-0.5) = -1", FUNC(lround) (-0.5), -1);
5399 check_long ("lround(0.8) = 1", FUNC(lround) (0.8), 1);
5400 check_long ("lround(-0.8) = -1", FUNC(lround) (-0.8), -1);
5401 check_long ("lround(1.5) = 2", FUNC(lround) (1.5), 2);
5402 check_long ("lround(-1.5) = -2", FUNC(lround) (-1.5), -2);
5403 check_long ("lround(22514.5) = 22515", FUNC(lround) (22514.5), 22515);
5404 check_long ("lround(-22514.5) = -22515", FUNC(lround) (-22514.5), -22515);
5405 #ifndef TEST_FLOAT
5406 check_long ("lround(2097152.5) = 2097153", FUNC(lround) (2097152.5),
5407 2097153);
5408 check_long ("lround(-2097152.5) = -2097153", FUNC(lround) (-2097152.5),
5409 -2097153);
5410 #endif
5414 static void
5415 llround_test (void)
5417 check_longlong ("llround(0) = 0", FUNC(llround) (0), 0);
5418 check_longlong ("llround(-0) = 0", FUNC(llround) (minus_zero), 0);
5419 check_longlong ("llround(0.2) = 0", FUNC(llround) (0.2), 0.0);
5420 check_longlong ("llround(-0.2) = 0", FUNC(llround) (-0.2), 0);
5421 check_longlong ("llround(0.5) = 1", FUNC(llround) (0.5), 1);
5422 check_longlong ("llround(-0.5) = -1", FUNC(llround) (-0.5), -1);
5423 check_longlong ("llround(0.8) = 1", FUNC(llround) (0.8), 1);
5424 check_longlong ("llround(-0.8) = -1", FUNC(llround) (-0.8), -1);
5425 check_longlong ("llround(1.5) = 2", FUNC(llround) (1.5), 2);
5426 check_longlong ("llround(-1.5) = -2", FUNC(llround) (-1.5), -2);
5427 check_longlong ("llround(22514.5) = 22515", FUNC(llround) (22514.5), 22515);
5428 check_longlong ("llround(-22514.5) = -22515", FUNC(llround) (-22514.5),
5429 -22515);
5430 #ifndef TEST_FLOAT
5431 check_longlong ("llround(2097152.5) = 2097153",
5432 FUNC(llround) (2097152.5), 2097153);
5433 check_longlong ("llround(-2097152.5) = -2097153",
5434 FUNC(llround) (-2097152.5), -2097153);
5435 check_longlong ("llround(34359738368.5) = 34359738369",
5436 FUNC(llround) (34359738368.5), 34359738369ll);
5437 check_longlong ("llround(-34359738368.5) = -34359738369",
5438 FUNC(llround) (-34359738368.5), -34359738369ll);
5439 #endif
5441 /* Test boundary conditions. */
5442 /* 0x1FFFFF */
5443 check_longlong ("llround(2097151.0) = 2097151", FUNC(llround) (2097151.0),
5444 2097151LL);
5445 /* 0x800000 */
5446 check_longlong ("llround(8388608.0) = 8388608", FUNC(llround) (8388608.0),
5447 8388608LL);
5448 /* 0x1000000 */
5449 check_longlong ("llround(16777216.0) = 16777216",
5450 FUNC(llround) (16777216.0), 16777216LL);
5451 /* 0x20000000000 */
5452 check_longlong ("llround(2199023255552.0) = 2199023255552",
5453 FUNC(llround) (2199023255552.0), 2199023255552LL);
5454 /* 0x40000000000 */
5455 check_longlong ("llround(4398046511104.0) = 4398046511104",
5456 FUNC(llround) (4398046511104.0), 4398046511104LL);
5457 /* 0x10000000000000 */
5458 check_longlong ("llround(4503599627370496.0) = 4503599627370496",
5459 FUNC(llround) (4503599627370496.0), 4503599627370496LL);
5460 /* 0x10000080000000 */
5461 check_longlong ("llrint(4503601774854144.0) = 4503601774854144",
5462 FUNC(llrint) (4503601774854144.0), 4503601774854144LL);
5463 /* 0x20000000000000 */
5464 check_longlong ("llround(9007199254740992.0) = 9007199254740992",
5465 FUNC(llround) (9007199254740992.0), 9007199254740992LL);
5466 /* 0x80000000000000 */
5467 check_longlong ("llround(36028797018963968.0) = 36028797018963968",
5468 FUNC(llround) (36028797018963968.0), 36028797018963968LL);
5469 /* 0x100000000000000 */
5470 check_longlong ("llround(72057594037927936.0) = 72057594037927936",
5471 FUNC(llround) (72057594037927936.0), 72057594037927936LL);
5475 static void
5476 fma_test (void)
5478 check ("fma(1.0, 2.0, 3.0) = 5.0", FUNC(fma) (1.0, 2.0, 3.0), 5.0);
5479 check_isnan ("fma(NaN, 2.0, 3.0) = NaN", FUNC(fma) (nan_value, 2.0, 3.0));
5480 check_isnan ("fma(1.0, NaN, 3.0) = NaN", FUNC(fma) (1.0, nan_value, 3.0));
5481 check_isnan_maybe_exc ("fma(1.0, 2.0, NaN) = NaN",
5482 FUNC(fma) (1.0, 2.0, nan_value), INVALID_EXCEPTION);
5483 check_isnan_maybe_exc ("fma(+Inf, 0.0, NaN) = NaN",
5484 FUNC(fma) (plus_infty, 0.0, nan_value),
5485 INVALID_EXCEPTION);
5486 check_isnan_maybe_exc ("fma(-Inf, 0.0, NaN) = NaN",
5487 FUNC(fma) (minus_infty, 0.0, nan_value),
5488 INVALID_EXCEPTION);
5489 check_isnan_maybe_exc ("fma(0.0, +Inf, NaN) = NaN",
5490 FUNC(fma) (0.0, plus_infty, nan_value),
5491 INVALID_EXCEPTION);
5492 check_isnan_maybe_exc ("fma(0.0, -Inf, NaN) = NaN",
5493 FUNC(fma) (0.0, minus_infty, nan_value),
5494 INVALID_EXCEPTION);
5495 check_isnan_exc ("fma(+Inf, 0.0, 1.0) = NaN",
5496 FUNC(fma) (plus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5497 check_isnan_exc ("fma(-Inf, 0.0, 1.0) = NaN",
5498 FUNC(fma) (minus_infty, 0.0, 1.0), INVALID_EXCEPTION);
5499 check_isnan_exc ("fma(0.0, +Inf, 1.0) = NaN",
5500 FUNC(fma) (0.0, plus_infty, 1.0), INVALID_EXCEPTION);
5501 check_isnan_exc ("fma(0.0, -Inf, 1.0) = NaN",
5502 FUNC(fma) (0.0, minus_infty, 1.0), INVALID_EXCEPTION);
5504 check_isnan_exc ("fma(+Inf, +Inf, -Inf) = NaN",
5505 FUNC(fma) (plus_infty, plus_infty, minus_infty),
5506 INVALID_EXCEPTION);
5507 check_isnan_exc ("fma(-Inf, +Inf, +Inf) = NaN",
5508 FUNC(fma) (minus_infty, plus_infty, plus_infty),
5509 INVALID_EXCEPTION);
5510 check_isnan_exc ("fma(+Inf, -Inf, +Inf) = NaN",
5511 FUNC(fma) (plus_infty, minus_infty, plus_infty),
5512 INVALID_EXCEPTION);
5513 check_isnan_exc ("fma(-Inf, -Inf, -Inf) = NaN",
5514 FUNC(fma) (minus_infty, minus_infty, minus_infty),
5515 INVALID_EXCEPTION);
5518 static void
5519 j0_test (void)
5521 errno = 0;
5522 FUNC(j0) (0);
5523 if (errno == ENOSYS)
5524 /* Function not implemented. */
5525 return;
5527 /* j0 is the Bessel function of the first kind of order 0 */
5528 check_isnan ("j0 (NaN) = NaN", FUNC(j0) (nan_value));
5529 check ("j0 (+Inf) = 0", FUNC(j0) (plus_infty), 0);
5530 check ("j0 (-1.0) = 0.76519...", FUNC(j0) (-1.0), 0.76519768655796655145);
5531 check ("j0 (0) = 1", FUNC(j0) (0.0), 1.0);
5532 check ("j0 (0.1) = 0.99750...", FUNC(j0) (0.1), 0.99750156206604003228);
5533 check ("j0 (0.7) = 0.88120...", FUNC(j0) (0.7), 0.88120088860740528084);
5534 check ("j0 (1.0) = 0.76519...", FUNC(j0) (1.0), 0.76519768655796655145);
5535 check_eps ("j0 (1.5) = 0.51182...", FUNC(j0) (1.5), 0.51182767173591812875,
5536 CHOOSE (0, 0, 6e-8));
5537 check_eps ("j0 (2.0) = 0.22389...", FUNC(j0) (2.0), 0.22389077914123566805,
5538 CHOOSE(0, 3e-17, 3e-8));
5539 check_eps ("j0 (8.0) = 0.17165...", FUNC(j0) (8.0), 0.17165080713755390609,
5540 CHOOSE(0, 0, 1.5e-8));
5541 check_eps ("j0 (10.0) = -0.24593...", FUNC(j0) (10.0), -0.24593576445134833520,
5542 CHOOSE(0, 6e-17, 5e-8));
5545 static void
5546 j1_test (void)
5548 errno = 0;
5549 FUNC(j1) (0);
5550 if (errno == ENOSYS)
5551 /* Function not implemented. */
5552 return;
5554 /* j1 is the Bessel function of the first kind of order 1 */
5555 check_isnan ("j1 (NaN) = NaN", FUNC(j1) (nan_value));
5556 check ("j1 (+Inf) = 0", FUNC(j1) (plus_infty), 0);
5558 check_eps ("j1 (-1.0) = -0.44005...", FUNC(j1) (-1.0),
5559 -0.44005058574493351596, CHOOSE (0, 0, 3e-8));
5560 check ("j1 (0) = 0", FUNC(j1) (0.0), 0.0);
5561 check ("j1 (0.1) = 0.049937...", FUNC(j1) (0.1), 0.049937526036241997556);
5562 check ("j1 (0.7) = 0.32899...", FUNC(j1) (0.7), 0.32899574154005894785);
5563 check_eps ("j1 (1.0) = 0.44005...", FUNC(j1) (1.0), 0.44005058574493351596,
5564 CHOOSE (0, 0, 3e-8));
5565 check_eps ("j1 (1.5) = 0.55793...", FUNC(j1) (1.5), 0.55793650791009964199,
5566 CHOOSE (0, 0, 6e-8));
5567 check_eps ("j1 (2.0) = 0.57672...", FUNC(j1) (2.0), 0.57672480775687338720,
5568 CHOOSE(0, 2e-16, 0));
5569 check_eps ("j1 (8.0) = 0.23463...", FUNC(j1) (8.0), 0.23463634685391462438,
5570 CHOOSE(0, 3e-17, 1.5e-8));
5571 check_eps ("j1 (10.0) = 0.04347...", FUNC(j1) (10.0), 0.043472746168861436670,
5572 CHOOSE(0, 2e-17, 7.5e-9));
5575 static void
5576 jn_test (void)
5578 errno = 0;
5579 FUNC(jn) (1, 1);
5580 if (errno == ENOSYS)
5581 /* Function not implemented. */
5582 return;
5584 /* jn is the Bessel function of the first kind of order n. */
5586 /* jn (0, x) == j0 (x) */
5587 check_isnan ("jn (0, NaN) = NaN", FUNC(jn) (0, nan_value));
5588 check ("jn (0, +Inf) = 0", FUNC(jn) (0, plus_infty), 0);
5589 check ("jn (0, -1.0) = 0.76519...", FUNC(jn) (0, -1.0), 0.76519768655796655145);
5590 check ("jn (0, 0.0) = 1", FUNC(jn) (0, 0.0), 1.0);
5591 check ("jn (0, 0.1) = 0.99750...", FUNC(jn) (0, 0.1), 0.99750156206604003228);
5592 check ("jn (0, 0.7) = 0.88120...", FUNC(jn) (0, 0.7), 0.88120088860740528084);
5593 check ("jn (0, 1.0) = 0.76519...", FUNC(jn) (0, 1.0), 0.76519768655796655145);
5594 check_eps ("jn (0, 1.5) = 0.51182...", FUNC(jn) (0, 1.5),
5595 0.51182767173591812875, CHOOSE (0, 0, 6e-8));
5596 check_eps ("jn (0, 2.0) = 0.22389...", FUNC(jn) (0, 2.0), 0.22389077914123566805,
5597 CHOOSE(0, 3e-17, 3e-8));
5598 check_eps ("jn (0, 8.0) = 0.17165...", FUNC(jn) (0, 8.0), 0.17165080713755390609,
5599 CHOOSE(0, 0, 1.5e-8));
5600 check_eps ("jn (0, 10.0) = -0.24593...", FUNC(jn) (0, 10.0), -0.24593576445134833520,
5601 CHOOSE(0, 6e-17, 4.5e-8));
5603 /* jn (1, x) == j1 (x) */
5604 check_isnan ("jn (1, NaN) = NaN", FUNC(jn) (1, nan_value));
5605 check ("jn (1, +Inf) = 0", FUNC(jn) (1, plus_infty), 0);
5607 check_eps ("jn (1, -1.0) = -0.44005...", FUNC(jn) (1, -1.0),
5608 -0.44005058574493351596, CHOOSE (0, 0, 3e-8));
5609 check ("jn (1, 0.0) = 0", FUNC(jn) (1, 0.0), 0.0);
5610 check ("jn (1, 0.1) = 0.049937...", FUNC(jn) (1, 0.1), 0.049937526036241997556);
5611 check ("jn (1, 0.7) = 0.32899...", FUNC(jn) (1, 0.7), 0.32899574154005894785);
5612 check_eps ("jn (1, 1.0) = 0.44005...", FUNC(jn) (1, 1.0),
5613 0.44005058574493351596, CHOOSE (0, 0, 3e-8));
5614 check_eps ("jn (1, 1.5) = 0.55793...", FUNC(jn) (1, 1.5),
5615 0.55793650791009964199, CHOOSE (0, 0, 6e-8));
5616 check_eps ("jn (1, 2.0) = 0.57672...", FUNC(jn) (1, 2.0), 0.57672480775687338720,
5617 CHOOSE(0, 2e-16, 0));
5618 check_eps ("jn (1, 8.0) = 0.23463...", FUNC(jn) (1, 8.0), 0.23463634685391462438,
5619 CHOOSE(0, 3e-17, 1.5e-8));
5620 check_eps ("jn (1, 10.0) = 0.04347...", FUNC(jn) (1, 10.0), 0.043472746168861436670,
5621 CHOOSE(0, 2e-17, 7.5e-9));
5623 /* jn (3, x) */
5624 check_isnan ("jn (3, NaN) = NaN", FUNC(jn) (3, nan_value));
5625 check ("jn (3, +Inf) = 0", FUNC(jn) (3, plus_infty), 0);
5627 check_eps ("jn (3, -1.0) = -0.01956...", FUNC(jn) (3, -1.0),
5628 -0.019563353982668405919, CHOOSE (0, 0, 1.9e-9));
5629 check ("jn (3, 0.0) = 0", FUNC(jn) (3, 0.0), 0.0);
5630 check_eps ("jn (3, 0.1) = 2.082...*10^-6", FUNC(jn) (3, 0.1), 0.000020820315754756261429,
5631 CHOOSE(0, 4e-21, 0));
5632 check_eps ("jn (3, 0.7) = 0.00692...", FUNC(jn) (3, 0.7), 0.0069296548267508408077,
5633 CHOOSE(0, 2e-18, 5e-10));
5634 check_eps ("jn (3, 1.0) = 0.01956...", FUNC(jn) (3, 1.0),
5635 0.019563353982668405919, CHOOSE (0, 0, 1.9e-9));
5636 check_eps ("jn (3, 2.0) = 0.12894...", FUNC(jn) (3, 2.0), 0.12894324947440205110,
5637 CHOOSE(0, 3e-17, 3e-8));
5638 check_eps ("jn (3, 10.0) = 0.05837...", FUNC(jn) (3, 10.0), 0.058379379305186812343,
5639 CHOOSE(0, 3e-17, 1.9e-8));
5641 /* jn (10, x) */
5642 check_isnan ("jn (10, NaN) = NaN", FUNC(jn) (10, nan_value));
5643 check ("jn (10, +Inf) = 0", FUNC(jn) (10, plus_infty), 0);
5645 check_eps ("jn (10, -1.0) = 2.6306...*10^-10", FUNC(jn) (10, -1.0), 0.26306151236874532070e-9,
5646 CHOOSE(0, 0, 5.6e-17));
5647 check ("jn (10, 0) = 0", FUNC(jn) (10, 0.0), 0.0);
5648 check_eps ("jn (10, 0.1) = 2.6905...*10^-20", FUNC(jn) (10, 0.1), 0.26905328954342155795e-19,
5649 CHOOSE(0, 2e-35, 9.7e-27));
5650 check_eps ("jn (10, 0.7) = 7.517...*10^-12", FUNC(jn) (10, 0.7), 0.75175911502153953928e-11,
5651 CHOOSE(0, 7e-27, 1.8e-18));
5652 check_eps ("jn (10, 1.0) = 2.630...*10^-10", FUNC(jn) (10, 1.0), 0.26306151236874532070e-9,
5653 CHOOSE(0, 0, 5.6e-17));
5654 check_eps ("jn (10, 2.0) = 2.515...*10^-7", FUNC(jn) (10, 2.0), 0.25153862827167367096e-6,
5655 CHOOSE(0, 2e-22, 1.2e-13));
5656 check_eps ("jn (10, 10.0) = 0.20748...", FUNC(jn) (10, 10.0), 0.20748610663335885770,
5657 CHOOSE(0, 2e-16, 1.4e-7));
5660 static void
5661 y0_test (void)
5663 errno = 0;
5664 FUNC(y0) (1);
5665 if (errno == ENOSYS)
5666 /* Function not implemented. */
5667 return;
5669 /* y0 is the Bessel function of the second kind of order 0 */
5670 check_isinfn ("y0 (-1.0) = -inf", FUNC(y0) (-1.0));
5671 check_isinfn ("y0 (0) = -inf", FUNC(y0) (0.0));
5672 check_isnan ("y0 (NaN) = NaN", FUNC(y0) (nan_value));
5673 check ("y0 (+Inf) = 0", FUNC(y0) (plus_infty), 0);
5675 check_eps ("y0 (0.1) = -1.53423...", FUNC(y0) (0.1), -1.5342386513503668441,
5676 CHOOSE(0, 3e-16, 2.4e-7));
5677 check_eps ("y0 (0.7) = -0.19066...", FUNC(y0) (0.7), -0.19066492933739506743,
5678 CHOOSE(0, 6e-17, 1.5e-8));
5679 check_eps ("y0 (1.0) = 0.08825...", FUNC(y0) (1.0), 0.088256964215676957983,
5680 CHOOSE(0, 3e-17, 7.5e-9));
5681 check_eps ("y0 (1.5) = 0.38244...", FUNC(y0) (1.5), 0.38244892379775884396,
5682 CHOOSE(0, 1.2e-16, 3.0e-8));
5683 check_eps ("y0 (2.0) = 0.51037...", FUNC(y0) (2.0), 0.51037567264974511960,
5684 CHOOSE(0, 2e-16, 6e-8));
5685 check_eps ("y0 (8.0) = 0.22352...", FUNC(y0) (8.0), 0.22352148938756622053,
5686 CHOOSE(0, 3e-17, 1.5e-8));
5687 check_eps ("y0 (10.0) = 0.05567...", FUNC(y0) (10.0), 0.055671167283599391424,
5688 CHOOSE(0, 2e-17, 3.8e-9));
5692 static void
5693 y1_test (void)
5695 errno = 0;
5696 FUNC(y1) (1);
5697 if (errno == ENOSYS)
5698 /* Function not implemented. */
5699 return;
5701 /* y1 is the Bessel function of the second kind of order 1 */
5702 check_isinfn ("y1 (-1.0) = -inf", FUNC(y1) (-1.0));
5703 check_isinfn ("y1 (0) = -inf", FUNC(y1) (0.0));
5704 check ("y1 (+Inf) = 0", FUNC(y1) (plus_infty), 0);
5705 check_isnan ("y1 (NaN) = NaN", FUNC(y1) (nan_value));
5707 check_eps ("y1 (0.1) = -6.45895...", FUNC(y1) (0.1), -6.4589510947020269877,
5708 CHOOSE(0, 9e-16, 9.6e-7));
5709 check_eps ("y1 (0.7) = -1.10324...", FUNC(y1) (0.7), -1.1032498719076333697,
5710 CHOOSE(0, 3e-16, 1.2e-7));
5711 check_eps ("y1 (1.0) = -0.78121...", FUNC(y1) (1.0), -0.78121282130028871655,
5712 CHOOSE(0, 2e-16, 0));
5713 check_eps ("y1 (1.5) = -0.41230...", FUNC(y1) (1.5), -0.41230862697391129595,
5714 CHOOSE (0, 0, 6e-8));
5715 check_eps ("y1 (2.0) = -0.10703...", FUNC(y1) (2.0), -0.10703243154093754689,
5716 CHOOSE(0, 2e-17, 1.5e-8));
5717 check_eps ("y1 (8.0) = -0.15806...", FUNC(y1) (8.0), -0.15806046173124749426,
5718 CHOOSE(0, 3e-17, 3.0e-8));
5719 check_eps ("y1 (10.0) = 0.24901...", FUNC(y1) (10.0), 0.24901542420695388392,
5720 CHOOSE(0, 9e-17, 3.0e-8));
5723 static void
5724 yn_test (void)
5726 errno = 0;
5727 FUNC(yn) (1, 1);
5728 if (errno == ENOSYS)
5729 /* Function not implemented. */
5730 return;
5732 /* yn is the Bessel function of the second kind of order n */
5734 /* yn (0, x) == y0 (x) */
5735 check_isinfn ("yn (0, -1.0) = -inf", FUNC(yn) (0, -1.0));
5736 check_isinfn ("yn (0, 0) = -inf", FUNC(yn) (0, 0.0));
5737 check_isnan ("yn (0, NaN) = NaN", FUNC(yn) (0, nan_value));
5738 check ("yn (0, +Inf) = 0", FUNC(yn) (0, plus_infty), 0);
5740 check_eps ("yn (0, 0.1) = -1.53423...", FUNC(yn) (0, 0.1), -1.5342386513503668441,
5741 CHOOSE(0, 3e-16, 9.6e-7));
5742 check_eps ("yn (0, 0.7) = -0.19066...", FUNC(yn) (0, 0.7), -0.19066492933739506743,
5743 CHOOSE(0, 6e-17, 1.2e-7));
5744 check_eps ("yn (0, 1.0) = 0.08825...", FUNC(yn) (0, 1.0), 0.088256964215676957983,
5745 CHOOSE(0, 3e-17, 3e-8));
5746 check_eps ("yn (0, 1.5) = 0.38244...", FUNC(yn) (0, 1.5), 0.38244892379775884396,
5747 CHOOSE(0, 1.2e-16, 3e-8));
5748 check_eps ("yn (0, 2.0) = 0.51037...", FUNC(yn) (0, 2.0), 0.51037567264974511960,
5749 CHOOSE(0, 2e-16, 6e-8));
5750 check_eps ("yn (0, 8.0) = 0.22352...", FUNC(yn) (0, 8.0), 0.22352148938756622053,
5751 CHOOSE(0, 3e-17, 1.5e-8));
5752 check_eps ("yn (0, 10.0) = 0.05567...", FUNC(yn) (0, 10.0), 0.055671167283599391424,
5753 CHOOSE(0, 2e-17, 3.8e-8));
5755 /* yn (1, x) == y1 (x) */
5756 check_isinfn ("yn (1, -1.0) = -inf", FUNC(yn) (1, -1.0));
5757 check_isinfn ("yn (1, 0) = -inf", FUNC(yn) (1, 0.0));
5758 check ("yn (1, +Inf) = 0", FUNC(yn) (1, plus_infty), 0);
5759 check_isnan ("yn (1, NaN) = NaN", FUNC(yn) (1, nan_value));
5761 check_eps ("yn (1, 0.1) = -6.45895...", FUNC(yn) (1, 0.1), -6.4589510947020269877,
5762 CHOOSE(0, 9e-16, 9.6e-7));
5763 check_eps ("yn (1, 0.7) = -1.10324...", FUNC(yn) (1, 0.7), -1.1032498719076333697,
5764 CHOOSE(0, 3e-16, 1.2e-7));
5765 check_eps ("yn (1, 1.0) = -0.78121...", FUNC(yn) (1, 1.0), -0.78121282130028871655,
5766 CHOOSE(0, 2e-16, 0));
5767 check_eps ("yn (1, 1.5) = -0.41230...", FUNC(yn) (1, 1.5), -0.41230862697391129595,
5768 CHOOSE (0, 0, 3e-8));
5769 check_eps ("yn (1, 2.0) = -0.10703...", FUNC(yn) (1, 2.0), -0.10703243154093754689,
5770 CHOOSE(0, 2e-17, 2e-8));
5771 check_eps ("yn (1, 8.0) = -0.15806...", FUNC(yn) (1, 8.0), -0.15806046173124749426,
5772 CHOOSE(0, 3e-17, 3e-8));
5773 check_eps ("yn (1, 10.0) = 0.24901...", FUNC(yn) (1, 10.0), 0.24901542420695388392,
5774 CHOOSE(0, 9e-17, 3e-8));
5776 /* yn (3, x) */
5777 check ("yn (3, +Inf) = 0", FUNC(yn) (3, plus_infty), 0);
5778 check_isnan ("yn (3, NaN) = NaN", FUNC(yn) (3, nan_value));
5780 check_eps ("yn (3, 0.1) = -5099.3...", FUNC(yn) (3, 0.1), -5099.3323786129048894,
5781 CHOOSE(0, 1e-12, 9.8e-4));
5782 check_eps ("yn (3, 0.7) = -15.819...", FUNC(yn) (3, 0.7), -15.819479052819633505,
5783 CHOOSE(0, 6e-15, 9.6e-7));
5784 check ("yn (3, 1.0) = -5.8215...", FUNC(yn) (3, 1.0), -5.8215176059647288478);
5785 check_eps ("yn (3, 2.0) = -1.1277...", FUNC(yn) (3, 2.0), -1.1277837768404277861,
5786 CHOOSE(0, 3e-16, 1.2e-7));
5787 check_eps ("yn (3, 10.0) = -0.25136...", FUNC(yn) (3, 10.0), -0.25136265718383732978,
5788 CHOOSE(0, 6e-17, 3e-8));
5790 /* yn (10, x) */
5791 check ("yn (10, +Inf) = 0", FUNC(yn) (10, plus_infty), 0);
5792 check_isnan ("yn (10, NaN) = NaN", FUNC(yn) (10, nan_value));
5794 check_eps ("yn (10, 0.1) = -1.183...*10^18", FUNC(yn) (10, 0.1), -0.11831335132045197885e19,
5795 CHOOSE(0, 6e2, 2.8e11));
5796 check_eps ("yn (10, 0.7) = -4.244...*10^9", FUNC(yn) (10, 0.7), -0.42447194260703866924e10,
5797 CHOOSE(0, 3e-6, 8e2));
5798 check_eps ("yn (10, 1.0) = -1.216...*10^8", FUNC(yn) (10, 1.0), -0.12161801427868918929e9,
5799 CHOOSE(0, 2e-8, 20));
5800 check_eps ("yn (10, 2.0) = -129184.5...", FUNC(yn) (10, 2.0), -129184.54220803928264,
5801 CHOOSE(0, 4.4e-11, 3e-2));
5802 check_eps ("yn (10, 10.0) = -0.35981...", FUNC(yn) (10, 10.0), -0.35981415218340272205,
5803 CHOOSE(0, 1.2e-16, 3e-8));
5808 /* Tests for the comparison macros */
5809 typedef enum { is_less, is_equal, is_greater, is_unordered } comp_result;
5812 static void
5813 comparison2_test (MATHTYPE x, MATHTYPE y, comp_result comp)
5815 char buf[255];
5816 int result;
5817 int expected;
5819 expected = (comp == is_greater);
5820 sprintf (buf, "isgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5821 expected);
5822 result = (isgreater (x, y) == expected);
5823 check_bool (buf, result);
5825 expected = (comp == is_greater || comp == is_equal);
5826 sprintf (buf, "isgreaterequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5827 expected);
5828 result = (isgreaterequal (x, y) == expected);
5829 check_bool (buf, result);
5831 expected = (comp == is_less);
5832 sprintf (buf, "isless (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5833 expected);
5834 result = (isless (x, y) == expected);
5835 check_bool (buf, result);
5837 expected = (comp == is_less || comp == is_equal);
5838 sprintf (buf, "islessequal (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5839 expected);
5840 result = (islessequal (x, y) == expected);
5841 check_bool (buf, result);
5843 expected = (comp == is_greater || comp == is_less);
5844 sprintf (buf, "islessgreater (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5845 expected);
5846 result = (islessgreater (x, y) == expected);
5847 check_bool (buf, result);
5849 expected = (comp == is_unordered);
5850 sprintf (buf, "isunordered (%" PRINTF_EXPR ", %" PRINTF_EXPR ") == %d", x, y,
5851 expected);
5852 result = (isunordered (x, y) == expected);
5853 check_bool (buf, result);
5857 static void
5858 comparison1_test (MATHTYPE x, MATHTYPE y, comp_result comp)
5860 comp_result comp_swap;
5861 switch (comp)
5863 case is_less:
5864 comp_swap = is_greater;
5865 break;
5866 case is_greater:
5867 comp_swap = is_less;
5868 break;
5869 default:
5870 comp_swap = comp;
5871 break;
5873 comparison2_test (x, y, comp);
5874 comparison2_test (y, x, comp_swap);
5878 static void
5879 comparisons_test (void)
5881 comparison1_test (1, 2, is_less);
5882 comparison1_test (-30, 30, is_less);
5883 comparison1_test (42, 42, is_equal);
5884 comparison1_test (1, plus_infty, is_less);
5885 comparison1_test (35, minus_infty, is_greater);
5886 comparison1_test (1, nan_value, is_unordered);
5887 comparison1_test (nan_value, nan_value, is_unordered);
5888 comparison1_test (plus_infty, nan_value, is_unordered);
5889 comparison1_test (minus_infty, nan_value, is_unordered);
5890 comparison1_test (plus_infty, minus_infty, is_greater);
5894 static void
5895 inverse_func_pair_test (const char *test_name,
5896 mathfunc f1, mathfunc inverse,
5897 MATHTYPE x, MATHTYPE epsilon)
5899 MATHTYPE a, b, difference;
5900 int result;
5902 a = f1 (x);
5903 (void) &a;
5904 b = inverse (a);
5905 (void) &b;
5907 output_new_test (test_name);
5908 result = check_equal (b, x, epsilon, &difference);
5909 output_result (test_name, result,
5910 b, x, difference, PRINT, PRINT);
5914 static void
5915 inverse_functions (void)
5917 inverse_func_pair_test ("asin(sin(x)) == x",
5918 FUNC(sin), FUNC(asin), 1.0,
5919 CHOOSE (2e-18L, 0, 3e-7L));
5920 inverse_func_pair_test ("sin(asin(x)) == x",
5921 FUNC(asin), FUNC(sin), 1.0, 0.0);
5923 inverse_func_pair_test ("acos(cos(x)) == x",
5924 FUNC(cos), FUNC(acos), 1.0,
5925 CHOOSE (4e-18L, 1e-15L, 0));
5926 inverse_func_pair_test ("cos(acos(x)) == x",
5927 FUNC(acos), FUNC(cos), 1.0, 0.0);
5928 inverse_func_pair_test ("atan(tan(x)) == x",
5929 FUNC(tan), FUNC(atan), 1.0,
5930 CHOOSE (2e-18L, 0, 0));
5931 inverse_func_pair_test ("tan(atan(x)) == x",
5932 FUNC(atan), FUNC(tan), 1.0,
5933 CHOOSE (2e-18L, 1e-15L, 2e-7));
5935 inverse_func_pair_test ("asinh(sinh(x)) == x",
5936 FUNC(sinh), FUNC(asinh), 1.0,
5937 CHOOSE (1e-18L, 0, 1e-7));
5938 inverse_func_pair_test ("sinh(asinh(x)) == x",
5939 FUNC(asinh), FUNC(sinh), 1.0,
5940 CHOOSE (2e-18L, 2e-16L, 2e-7));
5942 inverse_func_pair_test ("acosh(cosh(x)) == x",
5943 FUNC(cosh), FUNC(acosh), 1.0,
5944 CHOOSE (1e-18L, 1e-15L, 6e-8));
5945 inverse_func_pair_test ("cosh(acosh(x)) == x",
5946 FUNC(acosh), FUNC(cosh), 1.0, 0.0);
5948 inverse_func_pair_test ("atanh(tanh(x)) == x",
5949 FUNC(tanh), FUNC(atanh), 1.0,
5950 CHOOSE (1e-18L, 1e-15L, 0));
5951 inverse_func_pair_test ("tanh(atanh(x)) == x",
5952 FUNC(atanh), FUNC(tanh), 1.0, 0.0);
5956 /* Test sin and cos with the identity: sin(x)^2 + cos(x)^2 = 1. */
5957 static void
5958 identities1_test (MATHTYPE x, MATHTYPE epsilon)
5960 MATHTYPE res1, res2, res3, diff;
5961 int result;
5963 res1 = FUNC(sin) (x);
5964 (void) &res1;
5965 res2 = FUNC(cos) (x);
5966 (void) &res2;
5967 res3 = res1 * res1 + res2 * res2;
5968 (void) &res3;
5970 output_new_test ("sin^2 + cos^2 == 1");
5971 result = check_equal (res3, 1.0, epsilon, &diff);
5972 output_result_ext ("sin^2 + cos^2 == 1", result,
5973 res3, 1.0, diff, x, PRINT, PRINT);
5977 /* Test sin, cos, tan with the following relation: tan = sin/cos. */
5978 static void
5979 identities2_test (MATHTYPE x, MATHTYPE epsilon)
5981 #ifndef TEST_INLINE
5982 MATHTYPE res1, res2, res3, res4, diff;
5983 int result;
5985 res1 = FUNC(sin) (x);
5986 (void) &res1;
5987 res2 = FUNC(cos) (x);
5988 (void) &res2;
5989 res3 = FUNC(tan) (x);
5990 (void) &res3;
5991 res4 = res1 / res2;
5992 (void) &res4;
5994 output_new_test ("sin/cos == tan");
5995 result = check_equal (res4, res3, epsilon, &diff);
5996 output_result_ext ("sin/cos == tan", result,
5997 res4, res3, diff, x, PRINT, PRINT);
5998 #endif
6002 /* Test cosh and sinh with the identity cosh^2 - sinh^2 = 1. */
6003 static void
6004 identities3_test (MATHTYPE x, MATHTYPE epsilon)
6006 MATHTYPE res1, res2, res3, diff;
6007 int result;
6009 res1 = FUNC(sinh) (x);
6010 (void) &res1;
6011 res2 = FUNC(cosh) (x);
6012 (void) &res2;
6013 res3 = res2 * res2 - res1 * res1;
6014 (void) &res3;
6016 output_new_test ("cosh^2 - sinh^2 == 1");
6017 result = check_equal (res3, 1.0, epsilon, &diff);
6018 output_result_ext ("cosh^2 - sinh^2 == 1", result,
6019 res3, 1.0, diff, x, PRINT, PRINT);
6023 static void
6024 identities (void)
6026 identities1_test (0.2L, CHOOSE (1e-18L, 0, 2e-7));
6027 identities1_test (0.9L, CHOOSE (1e-18L, 2e-16, 2e-7));
6028 identities1_test (0, 0);
6029 identities1_test (-1, CHOOSE (1e-18L, 0, 1e-7));
6031 identities2_test (0.2L, CHOOSE (1e-19L, 1e-16, 0));
6032 identities2_test (0.9L, CHOOSE (3e-19L, 1e-15, 2e-7));
6033 identities2_test (0, 0);
6034 identities2_test (-1, CHOOSE (1e-18L, 1e-15, 2e-7));
6036 identities3_test (0.2L, CHOOSE (1e-18L, 0, 1e-7));
6037 identities3_test (0.9L, CHOOSE (1e-18L, 1e-15, 1e-6));
6038 identities3_test (0, CHOOSE (0, 0, 1e-6));
6039 identities3_test (-1, CHOOSE (1e-18L, 7e-16, 1e-6));
6044 Let's test that basic arithmetic is working
6045 tests: Infinity and NaN
6047 static void
6048 basic_tests (void)
6050 /* variables are declared volatile to forbid some compiler
6051 optimizations */
6052 volatile MATHTYPE Inf_var, NaN_var, zero_var, one_var;
6053 MATHTYPE x1, x2;
6055 zero_var = 0.0;
6056 one_var = 1.0;
6057 NaN_var = nan_value;
6058 Inf_var = one_var / zero_var;
6060 (void) &zero_var;
6061 (void) &one_var;
6062 (void) &NaN_var;
6063 (void) &Inf_var;
6065 /* Clear all exceptions. The previous computations raised exceptions. */
6066 feclearexcept (FE_ALL_EXCEPT);
6068 check_isinfp ("isinf (inf) == +1", Inf_var);
6069 check_isinfn ("isinf (-inf) == -1", -Inf_var);
6070 check_bool ("!isinf (1)", !(FUNC(isinf) (one_var)));
6071 check_bool ("!isinf (NaN)", !(FUNC(isinf) (NaN_var)));
6073 check_isnan ("isnan (NaN)", NaN_var);
6074 check_isnan ("isnan (-NaN)", -NaN_var);
6075 check_bool ("!isnan (1)", !(FUNC(isnan) (one_var)));
6076 check_bool ("!isnan (inf)", !(FUNC(isnan) (Inf_var)));
6078 check_bool ("inf == inf", Inf_var == Inf_var);
6079 check_bool ("-inf == -inf", -Inf_var == -Inf_var);
6080 check_bool ("inf != -inf", Inf_var != -Inf_var);
6081 check_bool ("NaN != NaN", NaN_var != NaN_var);
6084 the same tests but this time with NAN from <bits/nan.h>
6085 NAN is a double const
6087 check_bool ("isnan (NAN)", isnan (NAN));
6088 check_bool ("isnan (-NAN)", isnan (-NAN));
6089 check_bool ("!isinf (NAN)", !(isinf (NAN)));
6090 check_bool ("!isinf (-NAN)", !(isinf (-NAN)));
6091 check_bool ("NAN != NAN", NAN != NAN);
6094 And again with the value returned by the `nan' function.
6096 check_bool ("isnan (NAN)", FUNC(isnan) (FUNC(nan) ("")));
6097 check_bool ("isnan (-NAN)", FUNC(isnan) (-FUNC(nan) ("")));
6098 check_bool ("!isinf (NAN)", !(FUNC(isinf) (FUNC(nan) (""))));
6099 check_bool ("!isinf (-NAN)", !(FUNC(isinf) (-FUNC(nan) (""))));
6100 check_bool ("NAN != NAN", FUNC(nan) ("") != FUNC(nan) (""));
6102 /* test if EPSILON is ok */
6103 x1 = MATHCONST (1.0);
6104 x2 = x1 + CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
6105 check_bool ("1 != 1+EPSILON", x1 != x2);
6107 x1 = MATHCONST (1.0);
6108 x2 = x1 - CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
6109 check_bool ("1 != 1-EPSILON", x1 != x2);
6111 /* test if HUGE_VALx is ok */
6112 x1 = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
6113 check_bool ("isinf (HUGE_VALx) == +1", isinf (x1) == +1);
6114 x1 = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
6115 check_bool ("isinf (-HUGE_VALx) == -1", isinf (x1) == -1);
6119 static void
6120 initialize (void)
6122 fpstack_test ("start *init*");
6123 plus_zero = 0.0;
6124 nan_value = plus_zero / plus_zero; /* Suppress GCC warning */
6126 minus_zero = FUNC(copysign) (0.0, -1.0);
6127 plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
6128 minus_infty = CHOOSE (-HUGE_VALL, -HUGE_VAL, -HUGE_VALF);
6130 (void) &plus_zero;
6131 (void) &nan_value;
6132 (void) &minus_zero;
6133 (void) &plus_infty;
6134 (void) &minus_infty;
6136 /* Clear all exceptions. From now on we must not get random exceptions. */
6137 feclearexcept (FE_ALL_EXCEPT);
6139 /* Test to make sure we start correctly. */
6140 fpstack_test ("end *init*");
6144 static struct option long_options[] =
6146 {"verbose", optional_argument, NULL, 'v'},
6147 {"silent", no_argument, NULL, 's'},
6148 {0, 0, 0, 0}
6152 static void
6153 parse_options (int argc, char *argv[])
6155 int c;
6156 int option_index;
6158 verbose = 1;
6160 while (1)
6162 c = getopt_long (argc, argv, "v::s",
6163 long_options, &option_index);
6165 /* Detect the end of the options. */
6166 if (c == -1)
6167 break;
6169 switch (c)
6171 case 'v':
6172 if (optarg)
6173 verbose = (unsigned int) strtoul (optarg, NULL, 0);
6174 else
6175 verbose = 4;
6176 break;
6177 case 's':
6178 verbose = 0;
6179 default:
6180 break;
6187 main (int argc, char *argv[])
6190 parse_options (argc, argv);
6192 initialize ();
6193 printf (TEST_MSG);
6195 basic_tests ();
6197 /* keep the tests a wee bit ordered (according to ISO 9X) */
6198 /* classification functions */
6199 fpclassify_test ();
6200 isfinite_test ();
6201 isnormal_test ();
6202 signbit_test ();
6204 comparisons_test ();
6206 /* trigonometric functions */
6207 acos_test ();
6208 asin_test ();
6209 atan_test ();
6210 atan2_test ();
6211 cos_test ();
6212 sin_test ();
6213 sincos_test ();
6214 tan_test ();
6216 /* hyperbolic functions */
6217 acosh_test ();
6218 asinh_test ();
6219 atanh_test ();
6220 cosh_test ();
6221 sinh_test ();
6222 tanh_test ();
6224 /* exponential and logarithmic functions */
6225 exp_test ();
6226 exp10_test ();
6227 exp2_test ();
6228 expm1_test ();
6229 frexp_test ();
6230 ldexp_test ();
6231 log_test ();
6232 log10_test ();
6233 log1p_test ();
6234 log2_test ();
6235 logb_test ();
6236 modf_test ();
6237 ilogb_test ();
6238 scalb_test ();
6239 scalbn_test ();
6241 /* power and absolute value functions */
6242 cbrt_test ();
6243 fabs_test ();
6244 hypot_test ();
6245 pow_test ();
6246 sqrt_test ();
6248 /* error and gamma functions */
6249 erf_test ();
6250 erfc_test ();
6251 gamma_test ();
6252 tgamma_test ();
6253 lgamma_test ();
6255 /* nearest integer functions */
6256 ceil_test ();
6257 floor_test ();
6258 nearbyint_test ();
6259 rint_test ();
6260 lrint_test ();
6261 llrint_test ();
6262 round_test ();
6263 lround_test ();
6264 llround_test ();
6265 trunc_test ();
6267 /* remainder functions */
6268 fmod_test ();
6269 remainder_test ();
6270 remquo_test ();
6272 /* manipulation functions */
6273 copysign_test ();
6274 nextafter_test ();
6276 /* maximum, minimum and positive difference functions */
6277 fdim_test ();
6278 fmin_test ();
6279 fmax_test ();
6281 /* complex functions */
6282 cabs_test ();
6283 carg_test ();
6284 cexp_test ();
6285 csin_test ();
6286 csinh_test ();
6287 ccos_test ();
6288 ccosh_test ();
6289 clog_test ();
6290 clog10_test ();
6291 cacos_test ();
6292 cacosh_test ();
6293 casin_test ();
6294 casinh_test ();
6295 catan_test ();
6296 catanh_test ();
6297 ctan_test ();
6298 ctanh_test ();
6299 csqrt_test ();
6300 cpow_test ();
6302 /* multiply and add */
6303 fma_test ();
6305 /* Bessel functions */
6306 j0_test ();
6307 j1_test ();
6308 jn_test ();
6309 y0_test ();
6310 y1_test ();
6311 yn_test ();
6313 /* special tests */
6314 identities ();
6315 inverse_functions ();
6317 printf ("\nTest suite completed:\n");
6318 printf (" %d test cases plus %d tests for exception flags executed.\n",
6319 noTests, noExcTests);
6320 if (noErrors)
6322 printf (" %d errors occured.\n", noErrors);
6323 exit (1);
6325 printf (" All tests passed successfully.\n");
6326 exit (0);