Update.
[glibc.git] / math / libm-test.c
blob5171d0fc5e3895fd47239c6fd071601fb308ebaa
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Andreas Jaeger <aj@arthur.pfalz.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
22 Part of testsuite for libm.
24 This file has to be included by a master file that defines:
26 Makros:
27 FUNC(function): converts general function name (like cos) to
28 name with correct suffix (e.g. cosl or cosf)
29 MATHCONST(x): like FUNC but for constants (e.g convert 0.0 to 0.0L)
30 MATHTYPE: floating point type to test
31 TEST_MSG: informal message to be displayed
32 CHOOSE(Clongdouble,Cdouble,Cfloat):
33 chooses one of the parameters as epsilon for testing
34 equality
35 PRINTF_EXPR Floating point conversion specification to print a variable
36 of type MATHTYPE with printf. PRINTF_EXPR just contains
37 the specifier, not the percent and width arguments,
38 e.g. "f"
41 /* This program isn't finished yet.
42 It has tests for acos, acosh, asin, asinh, atan, atan2, atanh,
43 cbrt, ceil, copysign, cos, cosh, exp, exp2, expm1,
44 fabs, fdim, floor, fmin, fmax, fpclassify,
45 frexp, hypot, ilogb, ldexp,
46 log, log10, log1p, log2, logb, modf, nextafter,
47 pow, scalb, scalbn, sin, sinh, sqrt, tan, tanh, trunc.
48 Tests for the other libm-functions will come later.
50 The routines using random variables are still under construction. I don't
51 like it the way it's working now and will change it.
53 Exception handling has not been implemented so far so don't get fooled
54 that these tests pass.
56 Parameter handling is primitive in the moment:
57 --verbose=[0..3] for different levels of output:
58 0: only error count
59 1: basic report on failed tests
60 2: full report on failed tests
61 3: full report on failed and passed tests (default)
62 -v for full output (equals --verbose=3)
63 -s,--silent outputs only the error count (equals --verbose=0)
66 #ifndef _GNU_SOURCE
67 # define _GNU_SOURCE
68 #endif
70 #include <complex.h>
71 #include <math.h>
72 #include <float.h>
74 #include <errno.h>
75 #include <stdlib.h>
76 #include <stdio.h>
77 #include <time.h>
78 #include <getopt.h>
80 /* TEST_EXCEPTION: tests if an exception as occured */
81 /* for the moment: does nothing */
82 /* Possible exceptions */
83 #define NO_EXCEPTION 0x0
84 #define INVALID_EXCEPTION 0x1
85 #define DIVIDE_BY_ZERO_EXCEPTION 0x2
87 #define PRINT 1
88 #define NO_PRINT 0
90 #define TEST_EXCEPTION(test) do {} while (0);
91 /* As long as no exception code is available prevent warnings. */
92 #define UNUSED __attribute__ ((unused))
94 static int noErrors;
96 static int verbose = 3;
97 static MATHTYPE minus_zero, plus_zero;
98 static MATHTYPE plus_infty, minus_infty, nan_value;
100 typedef MATHTYPE (*mathfunc) (MATHTYPE);
102 #define BUILD_COMPLEX(real, imag) \
103 ({ __complex__ MATHTYPE __retval; \
104 __real__ __retval = (real); \
105 __imag__ __retval = (imag); \
106 __retval; })
109 #define ISINF(x) \
110 (sizeof (x) == sizeof (float) ? \
111 isinff (x) \
112 : sizeof (x) == sizeof (double) ? \
113 isinf (x) : isinfl (x))
117 Test if Floating-Point stack hasn't changed
119 static void
120 fpstack_test (const char *test_name)
122 #ifdef i386
123 static int old_stack;
124 int sw;
125 asm ("fnstsw":"=a" (sw));
126 sw >>= 11;
127 sw &= 7;
128 if (sw != old_stack)
130 printf ("FP-Stack wrong after test %s\n", test_name);
131 if (verbose > 2)
132 printf ("=======> stack = %d\n", sw);
133 ++noErrors;
134 old_stack = sw;
136 #endif
141 Get a random value x with min_value < x < max_value
142 and min_value, max_value finite,
143 max_value and min_value shouldn't be too close together
145 static MATHTYPE
146 random_value (MATHTYPE min_value, MATHTYPE max_value)
148 int r;
149 MATHTYPE x;
151 r = rand ();
153 x = (max_value - min_value) / RAND_MAX * (MATHTYPE) r + min_value;
155 if ((x <= min_value) || (x >= max_value) || !isfinite (x))
156 x = (max_value - min_value) / 2 + min_value;
158 return x;
161 /* Get a random value x with x > min_value. */
162 static MATHTYPE
163 random_greater (MATHTYPE min_value)
165 return random_value (min_value, 1e6); /* CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX) */
168 /* Get a random value x with x < max_value. */
169 static MATHTYPE
170 random_less (MATHTYPE max_value)
172 return random_value (-1e6, max_value);
176 /* Test if two floating point numbers are equal. */
177 static int
178 check_equal (MATHTYPE computed, MATHTYPE supplied, MATHTYPE eps, MATHTYPE * diff)
180 /* Both plus Infinity or both minus infinity. */
181 if (ISINF (computed) && (ISINF (computed) == ISINF (supplied)))
182 return 1;
184 if (isnan (computed) && isnan (supplied)) /* isnan works for all types */
185 return 1;
187 *diff = FUNC(fabs) (computed - supplied);
189 if (*diff <= eps && (signbit (computed) == signbit (supplied) || eps != 0.0))
190 return 1;
192 return 0;
196 static void
197 output_result_bool (const char *test_name, int result)
199 if (result)
201 if (verbose > 2)
202 printf ("Pass: %s\n", test_name);
204 else
206 if (verbose)
207 printf ("Fail: %s\n", test_name);
208 ++noErrors;
211 fpstack_test (test_name);
215 static void
216 output_isvalue (const char *test_name, int result,
217 MATHTYPE value)
219 if (result)
221 if (verbose > 2)
222 printf ("Pass: %s\n", test_name);
224 else
226 if (verbose)
227 printf ("Fail: %s\n", test_name);
228 if (verbose > 1)
229 printf (" Value: %.20" PRINTF_EXPR "\n", value);
230 noErrors++;
233 fpstack_test (test_name);
237 static void
238 output_isvalue_ext (const char *test_name, int result,
239 MATHTYPE value, MATHTYPE parameter)
241 if (result)
243 if (verbose > 2)
244 printf ("Pass: %s\n", test_name);
246 else
248 if (verbose)
249 printf ("Fail: %s\n", test_name);
250 if (verbose > 1)
252 printf (" Value: %.20" PRINTF_EXPR "\n", value);
253 printf (" Parameter: %.20" PRINTF_EXPR "\n", parameter);
255 noErrors++;
258 fpstack_test (test_name);
262 static void
263 output_result (const char *test_name, int result,
264 MATHTYPE computed, MATHTYPE expected,
265 MATHTYPE difference,
266 int print_values, int print_diff)
268 if (result)
270 if (verbose > 2)
271 printf ("Pass: %s\n", test_name);
273 else
275 if (verbose)
276 printf ("Fail: %s\n", test_name);
277 if (verbose > 1 && print_values)
279 printf ("Result:\n");
280 printf (" is: %.20" PRINTF_EXPR "\n", computed);
281 printf (" should be: %.20" PRINTF_EXPR "\n", expected);
282 if (print_diff)
283 printf (" difference: %.20" PRINTF_EXPR "\n", difference);
285 noErrors++;
288 fpstack_test (test_name);
292 static void
293 output_result_ext (const char *test_name, int result,
294 MATHTYPE computed, MATHTYPE expected,
295 MATHTYPE difference,
296 MATHTYPE parameter,
297 int print_values, int print_diff)
299 if (result)
301 if (verbose > 2)
302 printf ("Pass: %s\n", test_name);
304 else
306 if (verbose)
307 printf ("Fail: %s\n", test_name);
308 if (verbose > 1 && print_values)
310 printf ("Result:\n");
311 printf (" is: %.20" PRINTF_EXPR "\n", computed);
312 printf (" should be: %.20" PRINTF_EXPR "\n", expected);
313 if (print_diff)
314 printf (" difference: %.20" PRINTF_EXPR "\n", difference);
315 printf ("Parameter: %.20" PRINTF_EXPR "\n", parameter);
317 noErrors++;
320 fpstack_test (test_name);
324 static void
325 check (const char *test_name, MATHTYPE computed, MATHTYPE expected)
327 MATHTYPE diff;
328 int result;
330 result = check_equal (computed, expected, 0, &diff);
331 output_result (test_name, result,
332 computed, expected, diff, PRINT, PRINT);
336 static void
337 check_ext (const char *test_name, MATHTYPE computed, MATHTYPE expected,
338 MATHTYPE parameter)
340 MATHTYPE diff;
341 int result;
343 result = check_equal (computed, expected, 0, &diff);
344 output_result_ext (test_name, result,
345 computed, expected, diff, parameter, PRINT, PRINT);
349 static void
350 check_eps (const char *test_name, MATHTYPE computed, MATHTYPE expected,
351 MATHTYPE epsilon)
353 MATHTYPE diff;
354 int result;
356 result = check_equal (computed, expected, epsilon, &diff);
357 output_result (test_name, result,
358 computed, expected, diff, PRINT, PRINT);
362 static void
363 check_bool (const char *test_name, int computed)
365 output_result_bool (test_name, computed);
369 static void
370 check_long (const char *test_name, long int computed, long int expected)
372 long int diff = computed - expected;
373 int result = diff == 0;
375 if (result)
377 if (verbose > 2)
378 printf ("Pass: %s\n", test_name);
380 else
382 if (verbose)
383 printf ("Fail: %s\n", test_name);
384 if (verbose > 1)
386 printf ("Result:\n");
387 printf (" is: %ld\n", computed);
388 printf (" should be: %ld\n", expected);
390 noErrors++;
393 fpstack_test (test_name);
397 static void
398 check_longlong (const char *test_name, long long int computed,
399 long long int expected)
401 long long int diff = computed - expected;
402 int result = diff == 0;
404 if (result)
406 if (verbose > 2)
407 printf ("Pass: %s\n", test_name);
409 else
411 if (verbose)
412 printf ("Fail: %s\n", test_name);
413 if (verbose > 1)
415 printf ("Result:\n");
416 printf (" is: %lld\n", computed);
417 printf (" should be: %lld\n", expected);
419 noErrors++;
422 fpstack_test (test_name);
426 static void
427 check_isnan (const char *test_name, MATHTYPE computed)
429 output_isvalue (test_name, isnan (computed), computed);
433 static void
434 check_isnan_exc (const char *test_name, MATHTYPE computed,
435 short exception UNUSED)
437 output_isvalue (test_name, isnan (computed), computed);
441 static void
442 check_isnan_ext (const char *test_name, MATHTYPE computed,
443 MATHTYPE parameter)
445 output_isvalue_ext (test_name, isnan (computed), computed, parameter);
449 /* Tests if computed is +Inf */
450 static void
451 check_isinfp (const char *test_name, MATHTYPE computed)
453 output_isvalue (test_name, (ISINF (computed) == +1), computed);
457 static void
458 check_isinfp_ext (const char *test_name, MATHTYPE computed,
459 MATHTYPE parameter)
461 output_isvalue_ext (test_name, (ISINF (computed) == +1), computed, parameter);
465 /* Tests if computed is +Inf */
466 static void
467 check_isinfp_exc (const char *test_name, MATHTYPE computed,
468 int exception UNUSED)
470 output_isvalue (test_name, (ISINF (computed) == +1), computed);
473 /* Tests if computed is -Inf */
474 static void
475 check_isinfn (const char *test_name, MATHTYPE computed)
477 output_isvalue (test_name, (ISINF (computed) == -1), computed);
481 static void
482 check_isinfn_ext (const char *test_name, MATHTYPE computed,
483 MATHTYPE parameter)
485 output_isvalue_ext (test_name, (ISINF (computed) == -1), computed, parameter);
489 /* Tests if computed is -Inf */
490 static void
491 check_isinfn_exc (const char *test_name, MATHTYPE computed,
492 int exception UNUSED)
494 output_isvalue (test_name, (ISINF (computed) == -1), computed);
498 /****************************************************************************
499 Test for single functions of libm
500 ****************************************************************************/
502 static void
503 acos_test (void)
505 MATHTYPE x;
507 check ("acos (1) == 0", FUNC(acos) (1), 0);
509 x = random_greater (1);
510 check_isnan_exc ("acos (x) == NaN + invalid exception for |x| > 1",
511 FUNC(acos) (x),
512 INVALID_EXCEPTION);
515 static void
516 acosh_test (void)
518 MATHTYPE x;
520 check ("acosh(1) == 0", FUNC(acosh) (1), 0);
521 check_isinfp ("acosh(+inf) == +inf", FUNC(acosh) (plus_infty));
523 x = random_less (1);
524 check_isnan_exc ("acosh(x) == NaN plus invalid exception if x < 1",
525 FUNC(acosh) (x), INVALID_EXCEPTION);
529 static void
530 asin_test (void)
532 MATHTYPE x;
533 check ("asin (0) == 0", FUNC(asin) (0), 0);
535 x = random_greater (1);
536 check_isnan_exc ("asin x == NaN + invalid exception for |x| > 1",
537 FUNC(asin) (x),
538 INVALID_EXCEPTION);
541 static void
542 asinh_test (void)
545 check ("asinh(+0) == +0", FUNC(asinh) (0), 0);
546 check ("asinh(-0) == -0", FUNC(asinh) (minus_zero), minus_zero);
550 static void
551 atan_test (void)
553 check ("atan (0) == 0", FUNC(atan) (0), 0);
554 check ("atan (-0) == -0", FUNC(atan) (minus_zero), minus_zero);
556 check ("atan (+inf) == pi/2", FUNC(atan) (plus_infty), M_PI_2);
557 check ("atan (-inf) == -pi/2", FUNC(atan) (minus_infty), -M_PI_2);
561 static void
562 atan2_test (void)
564 MATHTYPE x;
566 x = random_greater (0);
567 check ("atan2 (0,x) == 0 for x > 0",
568 FUNC(atan2) (0, x), 0);
569 x = random_greater (0);
570 check ("atan2 (-0,x) == -0 for x > 0",
571 FUNC(atan2) (minus_zero, x), minus_zero);
573 check ("atan2 (+0,+0) == +0", FUNC(atan2) (0, 0), 0);
574 check ("atan2 (-0,+0) == -0", FUNC(atan2) (minus_zero, 0), minus_zero);
576 x = -random_greater (0);
577 check ("atan2 (+0,x) == +pi for x < 0", FUNC(atan2) (0, x), M_PI);
579 x = -random_greater (0);
580 check ("atan2 (-0,x) == -pi for x < 0", FUNC(atan2) (minus_zero, x), -M_PI);
582 check ("atan2 (+0,-0) == +pi", FUNC(atan2) (0, minus_zero), M_PI);
583 check ("atan2 (-0,-0) == -pi", FUNC(atan2) (minus_zero, minus_zero), -M_PI);
585 x = random_greater (0);
586 check ("atan2 (y,+0) == pi/2 for y > 0", FUNC(atan2) (x, 0), M_PI_2);
588 x = random_greater (0);
589 check ("atan2 (y,-0) == pi/2 for y > 0", FUNC(atan2) (x, minus_zero), M_PI_2);
591 x = random_greater (0);
592 check ("atan2 (y,-inf) == +pi for finite y > 0",
593 FUNC(atan2) (x, minus_infty), M_PI);
595 x = -random_greater (0);
596 check ("atan2 (y,-inf) == -pi for finite y < 0",
597 FUNC(atan2) (x, minus_infty), -M_PI);
599 check ("atan2 (+inf,+inf) == +pi/4",
600 FUNC(atan2) (plus_infty, plus_infty), M_PI_4);
602 check ("atan2 (-inf,+inf) == -pi/4",
603 FUNC(atan2) (minus_infty, plus_infty), -M_PI_4);
605 check ("atan2 (+inf,-inf) == +3*pi/4",
606 FUNC(atan2) (plus_infty, minus_infty), 3 * M_PI_4);
608 check ("atan2 (-inf,-inf) == -3*pi/4",
609 FUNC(atan2) (minus_infty, minus_infty), -3 * M_PI_4);
613 static void
614 atanh_test (void)
617 check ("atanh(+0) == +0", FUNC(atanh) (0), 0);
618 check ("atanh(-0) == -0", FUNC(atanh) (minus_zero), minus_zero);
619 check_isinfp_exc ("atanh(+1) == +inf plus divide-by-zero exception",
620 FUNC(atanh) (1), DIVIDE_BY_ZERO_EXCEPTION);
621 check_isinfn_exc ("atanh(-1) == -inf plus divide-by-zero exception",
622 FUNC(atanh) (-1), DIVIDE_BY_ZERO_EXCEPTION);
626 static void
627 cbrt_test (void)
629 check ("cbrt (+0) == +0", FUNC(cbrt) (0.0), 0.0);
630 check ("cbrt (-0) == -0", FUNC(cbrt) (minus_zero), minus_zero);
632 check_isinfp ("cbrt (+inf) == +inf", FUNC(cbrt) (plus_infty));
633 check_isinfn ("cbrt (-inf) == -inf", FUNC(cbrt) (minus_infty));
634 check_isnan ("cbrt (NaN) == NaN", FUNC(cbrt) (nan_value));
636 check ("cbrt (8) == 2", FUNC(cbrt) (8), 2);
637 check ("cbrt (-27) == -3", FUNC(cbrt) (-27.0), -3.0);
641 static void
642 ceil_test (void)
644 check ("ceil (+0) == +0", FUNC(ceil) (0.0), 0.0);
645 check ("ceil (-0) == -0", FUNC(ceil) (minus_zero), minus_zero);
646 check_isinfp ("ceil (+inf) == +inf", FUNC(ceil) (plus_infty));
647 check_isinfn ("ceil (-inf) == -inf", FUNC(ceil) (minus_infty));
649 check ("ceil (pi) == 4", FUNC(ceil) (M_PI), 4.0);
650 check ("ceil (-pi) == -3", FUNC(ceil) (-M_PI), -3.0);
654 static void
655 cos_test (void)
658 check ("cos (+0) == 1", FUNC(cos) (0), 1);
659 check ("cos (-0) == 1", FUNC(cos) (minus_zero), 1);
660 check_isnan_exc ("cos (+inf) == NaN plus invalid exception",
661 FUNC(cos) (plus_infty),
662 INVALID_EXCEPTION);
663 check_isnan_exc ("cos (-inf) == NaN plus invalid exception",
664 FUNC(cos) (minus_infty),
665 INVALID_EXCEPTION);
667 check_eps ("cos (pi/3) == 0.5", FUNC(cos) (M_PI / 3.0),
668 0.5, CHOOSE (4e-18L, 1e-15L, 1e-7L));
669 check_eps ("cos (pi/2) == 0", FUNC(cos) (M_PI_2),
670 0, CHOOSE (1e-19L, 1e-16L, 1e-7L));
674 static void
675 cosh_test (void)
677 check ("cosh (+0) == 1", FUNC(cosh) (0), 1);
678 check ("cosh (-0) == 1", FUNC(cosh) (minus_zero), 1);
680 check_isinfp ("cosh (+inf) == +inf", FUNC(cosh) (plus_infty));
681 check_isinfp ("cosh (-inf) == +inf", FUNC(cosh) (minus_infty));
685 static void
686 exp_test (void)
688 check ("exp (+0) == 1", FUNC(exp) (0), 1);
689 check ("exp (-0) == 1", FUNC(exp) (minus_zero), 1);
691 check_isinfp ("exp (+inf) == +inf", FUNC(exp) (plus_infty));
692 check ("exp (-inf) == 0", FUNC(exp) (minus_infty), 0);
694 check_eps ("exp (1) == e", FUNC(exp) (1), M_E, CHOOSE (4e-18L, 0, 0));
698 static void
699 exp2_test (void)
701 errno = 0;
702 exp2(0);
703 if (errno == ENOSYS)
704 /* Function not implemented. */
705 return;
707 check ("exp2 (+0) == 1", FUNC(exp2) (0), 1);
708 check ("exp2 (-0) == 1", FUNC(exp2) (minus_zero), 1);
710 check_isinfp ("exp2 (+inf) == +inf", FUNC(exp2) (plus_infty));
711 check ("exp2 (-inf) == 0", FUNC(exp2) (minus_infty), 0);
712 check ("exp2 (10) == 1024", FUNC(exp2) (10), 1024);
716 static void
717 expm1_test (void)
719 check ("expm1 (+0) == 0", FUNC(expm1) (0), 0);
720 check ("expm1 (-0) == -0", FUNC(expm1) (minus_zero), minus_zero);
722 check_isinfp ("expm1 (+inf) == +inf", FUNC(expm1) (plus_infty));
723 check ("expm1 (-inf) == -1", FUNC(expm1) (minus_infty), -1);
725 check_eps ("expm1 (1) == e-1", FUNC(expm1) (1), M_E - 1.0,
726 CHOOSE (4e-18L, 0, 0));
732 static void
733 check_frexp (const char *test_name, MATHTYPE computed, MATHTYPE expected,
734 int comp_int, int exp_int)
736 MATHTYPE diff;
737 int result;
739 result = (check_equal (computed, expected, 0, &diff)
740 && (comp_int == exp_int));
742 if (result)
744 if (verbose > 2)
745 printf ("Pass: %s\n", test_name);
747 else
749 if (verbose)
750 printf ("Fail: %s\n", test_name);
751 if (verbose > 1)
753 printf ("Result:\n");
754 printf (" is: %.20" PRINTF_EXPR " *2^%d\n", computed, comp_int);
755 printf (" should be: %.20" PRINTF_EXPR " *2^%d\n", expected, exp_int);
756 printf (" difference: %.20" PRINTF_EXPR "\n", diff);
758 noErrors++;
760 fpstack_test (test_name);
761 output_result (test_name, result,
762 computed, expected, diff, PRINT, PRINT);
766 static void
767 frexp_test (void)
769 int x_int;
770 MATHTYPE result;
772 result = FUNC(frexp) (plus_infty, &x_int);
773 check_isinfp ("frexp (+inf, expr) == +inf", result);
775 result = FUNC(frexp) (minus_infty, &x_int);
776 check_isinfn ("frexp (-inf, expr) == -inf", result);
778 result = FUNC(frexp) (nan_value, &x_int);
779 check_isnan ("frexp (Nan, expr) == NaN", result);
781 result = FUNC(frexp) (0, &x_int);
782 check_frexp ("frexp: +0 == 0 * 2^0", result, 0, x_int, 0);
784 result = FUNC(frexp) (minus_zero, &x_int);
785 check_frexp ("frexp: -0 == -0 * 2^0", result, minus_zero, x_int, 0);
787 result = FUNC(frexp) (12.8L, &x_int);
788 check_frexp ("frexp: 12.8 == 0.8 * 2^4", result, 0.8L, x_int, 4);
790 result = FUNC(frexp) (-27.34L, &x_int);
791 check_frexp ("frexp: -27.34 == -0.854375 * 2^5", result, -0.854375L, x_int, 5);
796 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)
797 /* All floating-point numbers can be put in one of these categories. */
798 enum
800 FP_NAN,
801 #define FP_NAN FP_NAN
802 FP_INFINITE,
803 #define FP_INFINITE FP_INFINITE
804 FP_ZERO,
805 #define FP_ZERO FP_ZERO
806 FP_SUBNORMAL,
807 #define FP_SUBNORMAL FP_SUBNORMAL
808 FP_NORMAL
809 #define FP_NORMAL FP_NORMAL
811 #endif
814 static void
815 fpclassify_test (void)
817 MATHTYPE x;
819 /* fpclassify is a macro, don't give it constants as parameter */
820 check_bool ("fpclassify (NaN) == FP_NAN", fpclassify (nan_value) == FP_NAN);
821 check_bool ("fpclassify (+inf) == FP_INFINITE",
822 fpclassify (plus_infty) == FP_INFINITE);
823 check_bool ("fpclassify (-inf) == FP_INFINITE",
824 fpclassify (minus_infty) == FP_INFINITE);
825 check_bool ("fpclassify (+0) == FP_ZERO",
826 fpclassify (plus_zero) == FP_ZERO);
827 check_bool ("fpclassify (-0) == FP_ZERO",
828 fpclassify (minus_zero) == FP_ZERO);
830 x = 1000.0;
831 check_bool ("fpclassify (1000) == FP_NORMAL",
832 fpclassify (x) == FP_NORMAL);
836 static void
837 ilogb_test (void)
840 /* XXX Are these tests correct? I couldn't find any specification */
841 #if 0
842 /* the source suggests that the following calls should fail -
843 but shall we test these special cases or just ignore them? */
844 check_isinfp ("ilogb (+inf) == +inf", FUNC(ilogb) (plus_infty));
845 check_isinfp ("ilogb (-inf) == +inf", FUNC(ilogb) (minus_infty));
847 check_isinfn_exc ("ilogb (+0) == -inf plus divide-by-zero exception",
848 FUNC(ilogb) (0), DIVIDE_BY_ZERO_EXCEPTION);
850 check_isinfn_exc ("ilogb (-0) == -inf plus divide-by-zero exception",
851 FUNC(ilogb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
852 #endif
853 check ("ilogb (1) == 0", FUNC(ilogb) (1), 0);
854 check ("ilogb (e) == 1", FUNC(ilogb) (M_E), 1);
855 check ("ilogb (1024) == 10", FUNC(ilogb) (1024), 10);
856 check ("ilogb (-2000) == 10", FUNC(ilogb) (-2000), 10);
861 static void
862 ldexp_test (void)
864 MATHTYPE x;
866 check ("ldexp (0, 0) == 0", FUNC(ldexp) (0, 0), 0);
868 check_isinfp ("ldexp (+inf, 1) == +inf", FUNC(ldexp) (plus_infty, 1));
869 check_isinfn ("ldexp (-inf, 1) == -inf", FUNC(ldexp) (minus_infty, 1));
870 check_isnan ("ldexp (NaN, 1) == NaN", FUNC(ldexp) (nan_value, 1));
872 check ("ldexp (0.8, 4) == 12.8", FUNC(ldexp) (0.8L, 4), 12.8L);
873 check ("ldexp (-0.854375, 5) == -27.34", FUNC(ldexp) (-0.854375L, 5), -27.34L);
875 x = random_greater (0.0);
876 check_ext ("ldexp (x, 0) == x", FUNC(ldexp) (x, 0L), x, x);
881 static void
882 log_test (void)
884 check_isinfn_exc ("log (+0) == -inf", FUNC(log) (0),
885 DIVIDE_BY_ZERO_EXCEPTION);
886 check_isinfn_exc ("log (-0) == -inf", FUNC(log) (minus_zero),
887 DIVIDE_BY_ZERO_EXCEPTION);
889 check ("log (1) == 0", FUNC(log) (1), 0);
891 check_isnan_exc ("log (x) == NaN plus divide-by-zero exception if x < 0",
892 FUNC(log) (-1), INVALID_EXCEPTION);
893 check_isinfp ("log (+inf) == +inf", FUNC(log) (plus_infty));
895 check_eps ("log (e) == 1", FUNC(log) (M_E), 1, CHOOSE (1e-18L, 0, 9e-8L));
896 check_eps ("log (1/e) == -1", FUNC(log) (1.0 / M_E), -1,
897 CHOOSE (2e-18L, 0, 0));
898 check ("log (2) == M_LN2", FUNC(log) (2), M_LN2);
899 check_eps ("log (10) == M_LN10", FUNC(log) (10), M_LN10,
900 CHOOSE (1e-18L, 0, 0));
904 static void
905 log10_test (void)
907 check_isinfn_exc ("log10 (+0) == -inf", FUNC(log10) (0),
908 DIVIDE_BY_ZERO_EXCEPTION);
909 check_isinfn_exc ("log10 (-0) == -inf", FUNC(log10) (minus_zero),
910 DIVIDE_BY_ZERO_EXCEPTION);
912 check ("log10 (1) == +0", FUNC(log10) (1), 0);
914 check_isnan_exc ("log10 (x) == NaN plus divide-by-zero exception if x < 0",
915 FUNC(log10) (-1), INVALID_EXCEPTION);
917 check_isinfp ("log10 (+inf) == +inf", FUNC(log10) (plus_infty));
919 check_eps ("log10 (0.1) == -1", FUNC(log10) (0.1L), -1,
920 CHOOSE (1e-18L, 0, 0));
921 check_eps ("log10 (10) == 1", FUNC(log10) (10.0), 1,
922 CHOOSE (1e-18L, 0, 0));
923 check_eps ("log10 (100) == 2", FUNC(log10) (100.0), 2,
924 CHOOSE (1e-18L, 0, 0));
925 check ("log10 (10000) == 4", FUNC(log10) (10000.0), 4);
926 check_eps ("log10 (e) == M_LOG10E", FUNC(log10) (M_E), M_LOG10E,
927 CHOOSE (1e-18, 0, 9e-8));
931 static void
932 log1p_test (void)
934 check ("log1p (+0) == +0", FUNC(log1p) (0), 0);
935 check ("log1p (-0) == -0", FUNC(log1p) (minus_zero), minus_zero);
937 check_isinfn_exc ("log1p (-1) == -inf", FUNC(log1p) (-1),
938 DIVIDE_BY_ZERO_EXCEPTION);
939 check_isnan_exc ("log1p (x) == NaN plus divide-by-zero exception if x < -1",
940 FUNC(log1p) (-2), INVALID_EXCEPTION);
942 check_isinfp ("log1p (+inf) == +inf", FUNC(log1p) (plus_infty));
944 check_eps ("log1p (e-1) == 1", FUNC(log1p) (M_E - 1.0), 1,
945 CHOOSE (1e-18L, 0, 0));
950 static void
951 log2_test (void)
953 check_isinfn_exc ("log2 (+0) == -inf", FUNC(log2) (0),
954 DIVIDE_BY_ZERO_EXCEPTION);
955 check_isinfn_exc ("log2 (-0) == -inf", FUNC(log2) (minus_zero),
956 DIVIDE_BY_ZERO_EXCEPTION);
958 check ("log2 (1) == +0", FUNC(log2) (1), 0);
960 check_isnan_exc ("log2 (x) == NaN plus divide-by-zero exception if x < 0",
961 FUNC(log2) (-1), INVALID_EXCEPTION);
963 check_isinfp ("log2 (+inf) == +inf", FUNC(log2) (plus_infty));
965 check_eps ("log2 (e) == M_LOG2E", FUNC(log2) (M_E), M_LOG2E,
966 CHOOSE (1e-18L, 0, 0));
967 check ("log2 (2) == 1", FUNC(log2) (2.0), 1);
968 check_eps ("log2 (16) == 4", FUNC(log2) (16.0), 4, CHOOSE (1e-18L, 0, 0));
969 check ("log2 (256) == 8", FUNC(log2) (256.0), 8);
974 static void
975 logb_test (void)
977 check_isinfp ("logb (+inf) == +inf", FUNC(logb) (plus_infty));
978 check_isinfp ("logb (-inf) == +inf", FUNC(logb) (minus_infty));
980 check_isinfn_exc ("logb (+0) == -inf plus divide-by-zero exception",
981 FUNC(logb) (0), DIVIDE_BY_ZERO_EXCEPTION);
983 check_isinfn_exc ("logb (-0) == -inf plus divide-by-zero exception",
984 FUNC(logb) (minus_zero), DIVIDE_BY_ZERO_EXCEPTION);
986 check ("logb (1) == 0", FUNC(logb) (1), 0);
987 check ("logb (e) == 1", FUNC(logb) (M_E), 1);
988 check ("logb (1024) == 10", FUNC(logb) (1024), 10);
989 check ("logb (-2000) == 10", FUNC(logb) (-2000), 10);
994 static void
995 modf_test (void)
997 MATHTYPE result, intpart;
999 result = FUNC(modf) (plus_infty, &intpart);
1000 check ("modf (+inf, &x) returns +0", result, 0);
1001 check_isinfp ("modf (+inf, &x) set x to +inf", intpart);
1003 result = FUNC(modf) (minus_infty, &intpart);
1004 check ("modf (-inf, &x) returns -0", result, minus_zero);
1005 check_isinfn ("modf (-inf, &x) sets x to -inf", intpart);
1007 result = FUNC(modf) (nan_value, &intpart);
1008 check_isnan ("modf (NaN, &x) returns NaN", result);
1009 check_isnan ("modf (NaN, &x) sets x to NaN", intpart);
1011 result = FUNC(modf) (0, &intpart);
1012 check ("modf (0, &x) returns 0", result, 0);
1013 check ("modf (0, &x) sets x to 0", intpart, 0);
1015 result = FUNC(modf) (minus_zero, &intpart);
1016 check ("modf (-0, &x) returns -0", result, minus_zero);
1017 check ("modf (-0, &x) sets x to -0", intpart, minus_zero);
1019 result = FUNC(modf) (2.5, &intpart);
1020 check ("modf (2.5, &x) returns 0.5", result, 0.5);
1021 check ("modf (2.5, &x) sets x to 2", intpart, 2);
1023 result = FUNC(modf) (-2.5, &intpart);
1024 check ("modf (-2.5, &x) returns -0.5", result, -0.5);
1025 check ("modf (-2.5, &x) sets x to -2", intpart, -2);
1030 static void
1031 scalb_test (void)
1033 MATHTYPE x;
1035 check ("scalb (0, 0) == 0", FUNC(scalb) (0, 0), 0);
1037 check_isinfp ("scalb (+inf, 1) == +inf", FUNC(scalb) (plus_infty, 1));
1038 check_isinfn ("scalb (-inf, 1) == -inf", FUNC(scalb) (minus_infty, 1));
1039 check_isnan ("scalb (NaN, 1) == NaN", FUNC(scalb) (nan_value, 1));
1041 check ("scalb (0.8, 4) == 12.8", FUNC(scalb) (0.8L, 4), 12.8L);
1042 check ("scalb (-0.854375, 5) == -27.34", FUNC(scalb) (-0.854375L, 5), -27.34L);
1044 x = random_greater (0.0);
1045 check_ext ("scalb (x, 0) == x", FUNC(scalb) (x, 0L), x, x);
1049 static void
1050 scalbn_test (void)
1052 MATHTYPE x;
1054 check ("scalbn (0, 0) == 0", FUNC(scalbn) (0, 0), 0);
1056 check_isinfp ("scalbn (+inf, 1) == +inf", FUNC(scalbn) (plus_infty, 1));
1057 check_isinfn ("scalbn (-inf, 1) == -inf", FUNC(scalbn) (minus_infty, 1));
1058 check_isnan ("scalbn (NaN, 1) == NaN", FUNC(scalbn) (nan_value, 1));
1060 check ("scalbn (0.8, 4) == 12.8", FUNC(scalbn) (0.8L, 4), 12.8L);
1061 check ("scalbn (-0.854375, 5) == -27.34", FUNC(scalbn) (-0.854375L, 5), -27.34L);
1063 x = random_greater (0.0);
1064 check_ext ("scalbn (x, 0) == x", FUNC(scalbn) (x, 0L), x, x);
1068 static void
1069 sin_test (void)
1071 check ("sin (+0) == +0", FUNC(sin) (0), 0);
1072 check ("sin (-0) == -0", FUNC(sin) (minus_zero), minus_zero);
1073 check_isnan_exc ("sin (+inf) == NaN plus invalid exception",
1074 FUNC(sin) (plus_infty),
1075 INVALID_EXCEPTION);
1076 check_isnan_exc ("sin (-inf) == NaN plus invalid exception",
1077 FUNC(sin) (minus_infty),
1078 INVALID_EXCEPTION);
1080 check_eps ("sin (pi/6) == 0.5", FUNC(sin) (M_PI / 6.0), 0.5,
1081 CHOOSE (4e-18L, 0, 0));
1082 check ("sin (pi/2) == 1", FUNC(sin) (M_PI_2), 1);
1086 static void
1087 sinh_test (void)
1089 check ("sinh (+0) == +0", FUNC(sinh) (0), 0);
1090 check ("sinh (-0) == -0", FUNC(sinh) (minus_zero), minus_zero);
1092 check_isinfp ("sinh (+inf) == +inf", FUNC(sinh) (plus_infty));
1093 check_isinfn ("sinh (-inf) == -inf", FUNC(sinh) (minus_infty));
1097 static void
1098 tan_test (void)
1100 check ("tan (+0) == +0", FUNC(tan) (0), 0);
1101 check ("tan (-0) == -0", FUNC(tan) (minus_zero), minus_zero);
1102 check_isnan_exc ("tan (+inf) == NaN plus invalid exception",
1103 FUNC(tan) (plus_infty), INVALID_EXCEPTION);
1104 check_isnan_exc ("tan (-inf) == NaN plus invalid exception",
1105 FUNC(tan) (minus_infty), INVALID_EXCEPTION);
1107 check_eps ("tan (pi/4) == 1", FUNC(tan) (M_PI_4), 1,
1108 CHOOSE (2e-18L, 1e-15L, 0));
1112 static void
1113 tanh_test (void)
1115 check ("tanh (+0) == +0", FUNC(tanh) (0), 0);
1116 check ("tanh (-0) == -0", FUNC(tanh) (minus_zero), minus_zero);
1118 check ("tanh (+inf) == +1", FUNC(tanh) (plus_infty), 1);
1119 check ("tanh (-inf) == -1", FUNC(tanh) (minus_infty), -1);
1123 static void
1124 fabs_test (void)
1126 check ("fabs (+0) == +0", FUNC(fabs) (0), 0);
1127 check ("fabs (-0) == +0", FUNC(fabs) (minus_zero), 0);
1129 check_isinfp ("fabs (+inf) == +inf", FUNC(fabs) (plus_infty));
1130 check_isinfp ("fabs (-inf) == +inf", FUNC(fabs) (minus_infty));
1132 check ("fabs (+38) == 38", FUNC(fabs) (38.0), 38.0);
1133 check ("fabs (-e) == e", FUNC(fabs) (-M_E), M_E);
1137 static void
1138 floor_test (void)
1140 check ("floor (+0) == +0", FUNC(floor) (0.0), 0.0);
1141 check ("floor (-0) == -0", FUNC(floor) (minus_zero), minus_zero);
1142 check_isinfp ("floor (+inf) == +inf", FUNC(floor) (plus_infty));
1143 check_isinfn ("floor (-inf) == -inf", FUNC(floor) (minus_infty));
1145 check ("floor (pi) == 3", FUNC(floor) (M_PI), 3.0);
1146 check ("floor (-pi) == -4", FUNC(floor) (-M_PI), -4.0);
1150 static void
1151 hypot_test (void)
1153 MATHTYPE a;
1155 a = random_greater (0);
1156 check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot) (plus_infty, a), a);
1157 check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot) (minus_infty, a), a);
1159 check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot) (nan_value, nan_value));
1161 a = FUNC(hypot) (12.4L, 0.7L);
1162 check ("hypot (x,y) == hypot (y,x)", FUNC(hypot) (0.7L, 12.4L), a);
1163 check ("hypot (x,y) == hypot (-x,y)", FUNC(hypot) (-12.4L, 0.7L), a);
1164 check ("hypot (x,y) == hypot (-y,x)", FUNC(hypot) (-0.7L, 12.4L), a);
1165 check ("hypot (x,y) == hypot (-x,-y)", FUNC(hypot) (-12.4L, -0.7L), a);
1166 check ("hypot (x,y) == hypot (-y,-x)", FUNC(hypot) (-0.7L, -12.4L), a);
1167 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-0.7L, 0), 0.7L);
1168 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (0.7L, 0), 0.7L);
1169 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-1.0L, 0), 1.0L);
1170 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (1.0L, 0), 1.0L);
1171 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (-5.7e7L, 0), 5.7e7L);
1172 check ("hypot (x,0) == fabs (x)", FUNC(hypot) (5.7e7L, 0), 5.7e7L);
1176 static void
1177 pow_test (void)
1179 MATHTYPE x;
1181 check ("pow (+0, +0) == 1", FUNC(pow) (0, 0), 1);
1182 check ("pow (+0, -0) == 1", FUNC(pow) (0, minus_zero), 1);
1183 check ("pow (-0, +0) == 1", FUNC(pow) (minus_zero, 0), 1);
1184 check ("pow (-0, -0) == 1", FUNC(pow) (minus_zero, minus_zero), 1);
1186 check ("pow (+10, +0) == 1", FUNC(pow) (10, 0), 1);
1187 check ("pow (+10, -0) == 1", FUNC(pow) (10, minus_zero), 1);
1188 check ("pow (-10, +0) == 1", FUNC(pow) (-10, 0), 1);
1189 check ("pow (-10, -0) == 1", FUNC(pow) (-10, minus_zero), 1);
1191 check ("pow (NaN, +0) == 1", FUNC(pow) (nan_value, 0), 1);
1192 check ("pow (NaN, -0) == 1", FUNC(pow) (nan_value, minus_zero), 1);
1194 check_isinfp ("pow (+1.1, +inf) == +inf", FUNC(pow) (1.1, plus_infty));
1195 check_isinfp ("pow (+inf, +inf) == +inf", FUNC(pow) (plus_infty, plus_infty));
1196 check_isinfp ("pow (-1.1, +inf) == +inf", FUNC(pow) (-1.1, plus_infty));
1197 check_isinfp ("pow (-inf, +inf) == +inf", FUNC(pow) (minus_infty, plus_infty));
1199 check ("pow (0.9, +inf) == +0", FUNC(pow) (0.9L, plus_infty), 0);
1200 check ("pow (1e-7, +inf) == +0", FUNC(pow) (1e-7L, plus_infty), 0);
1201 check ("pow (-0.9, +inf) == +0", FUNC(pow) (-0.9L, plus_infty), 0);
1202 check ("pow (-1e-7, +inf) == +0", FUNC(pow) (-1e-7L, plus_infty), 0);
1204 check ("pow (+1.1, -inf) == 0", FUNC(pow) (1.1, minus_infty), 0);
1205 check ("pow (+inf, -inf) == 0", FUNC(pow) (plus_infty, minus_infty), 0);
1206 check ("pow (-1.1, -inf) == 0", FUNC(pow) (-1.1, minus_infty), 0);
1207 check ("pow (-inf, -inf) == 0", FUNC(pow) (minus_infty, minus_infty), 0);
1209 check_isinfp ("pow (0.9, -inf) == +inf", FUNC(pow) (0.9L, minus_infty));
1210 check_isinfp ("pow (1e-7, -inf) == +inf", FUNC(pow) (1e-7L, minus_infty));
1211 check_isinfp ("pow (-0.9, -inf) == +inf", FUNC(pow) (-0.9L, minus_infty));
1212 check_isinfp ("pow (-1e-7, -inf) == +inf", FUNC(pow) (-1e-7L, minus_infty));
1214 check_isinfp ("pow (+inf, 1e-7) == +inf", FUNC(pow) (plus_infty, 1e-7L));
1215 check_isinfp ("pow (+inf, 1) == +inf", FUNC(pow) (plus_infty, 1));
1216 check_isinfp ("pow (+inf, 1e7) == +inf", FUNC(pow) (plus_infty, 1e7L));
1218 check ("pow (+inf, -1e-7) == 0", FUNC(pow) (plus_infty, -1e-7L), 0);
1219 check ("pow (+inf, -1) == 0", FUNC(pow) (plus_infty, -1), 0);
1220 check ("pow (+inf, -1e7) == 0", FUNC(pow) (plus_infty, -1e7L), 0);
1222 check_isinfn ("pow (-inf, 1) == -inf", FUNC(pow) (minus_infty, 1));
1223 check_isinfn ("pow (-inf, 11) == -inf", FUNC(pow) (minus_infty, 11));
1224 check_isinfn ("pow (-inf, 1001) == -inf", FUNC(pow) (minus_infty, 1001));
1226 check_isinfp ("pow (-inf, 2) == +inf", FUNC(pow) (minus_infty, 2));
1227 check_isinfp ("pow (-inf, 12) == +inf", FUNC(pow) (minus_infty, 12));
1228 check_isinfp ("pow (-inf, 1002) == +inf", FUNC(pow) (minus_infty, 1002));
1229 check_isinfp ("pow (-inf, 0.1) == +inf", FUNC(pow) (minus_infty, 0.1));
1230 check_isinfp ("pow (-inf, 1.1) == +inf", FUNC(pow) (minus_infty, 1.1));
1231 check_isinfp ("pow (-inf, 11.1) == +inf", FUNC(pow) (minus_infty, 11.1));
1232 check_isinfp ("pow (-inf, 1001.1) == +inf", FUNC(pow) (minus_infty, 1001.1));
1234 check ("pow (-inf, -1) == -0", FUNC(pow) (minus_infty, -1), minus_zero);
1235 check ("pow (-inf, -11) == -0", FUNC(pow) (minus_infty, -11), minus_zero);
1236 check ("pow (-inf, -1001) == -0", FUNC(pow) (minus_infty, -1001), minus_zero);
1238 check ("pow (-inf, -2) == +0", FUNC(pow) (minus_infty, -2), 0);
1239 check ("pow (-inf, -12) == +0", FUNC(pow) (minus_infty, -12), 0);
1240 check ("pow (-inf, -1002) == +0", FUNC(pow) (minus_infty, -1002), 0);
1241 check ("pow (-inf, -0.1) == +0", FUNC(pow) (minus_infty, -0.1), 0);
1242 check ("pow (-inf, -1.1) == +0", FUNC(pow) (minus_infty, -1.1), 0);
1243 check ("pow (-inf, -11.1) == +0", FUNC(pow) (minus_infty, -11.1), 0);
1244 check ("pow (-inf, -1001.1) == +0", FUNC(pow) (minus_infty, -1001.1), 0);
1246 check_isnan ("pow (NaN, NaN) == NaN", FUNC(pow) (nan_value, nan_value));
1247 check_isnan ("pow (0, NaN) == NaN", FUNC(pow) (0, nan_value));
1248 check_isnan ("pow (1, NaN) == NaN", FUNC(pow) (1, nan_value));
1249 check_isnan ("pow (-1, NaN) == NaN", FUNC(pow) (-1, nan_value));
1250 check_isnan ("pow (NaN, 1) == NaN", FUNC(pow) (nan_value, 1));
1251 check_isnan ("pow (NaN, -1) == NaN", FUNC(pow) (nan_value, -1));
1253 x = random_greater (0.0);
1254 check_isnan_ext ("pow (x, NaN) == NaN", FUNC(pow) (x, nan_value), x);
1256 check_isnan_exc ("pow (+1, +inf) == NaN", FUNC(pow) (1, plus_infty),
1257 INVALID_EXCEPTION);
1258 check_isnan_exc ("pow (-1, +inf) == NaN", FUNC(pow) (-1, plus_infty),
1259 INVALID_EXCEPTION);
1260 check_isnan_exc ("pow (+1, -inf) == NaN", FUNC(pow) (1, minus_infty),
1261 INVALID_EXCEPTION);
1262 check_isnan_exc ("pow (-1, -inf) == NaN", FUNC(pow) (-1, minus_infty),
1263 INVALID_EXCEPTION);
1265 check_isnan_exc ("pow (-0.1, 1.1) == NaN", FUNC(pow) (-0.1, 1.1),
1266 INVALID_EXCEPTION);
1267 check_isnan_exc ("pow (-0.1, -1.1) == NaN", FUNC(pow) (-0.1, -1.1),
1268 INVALID_EXCEPTION);
1269 check_isnan_exc ("pow (-10.1, 1.1) == NaN", FUNC(pow) (-10.1, 1.1),
1270 INVALID_EXCEPTION);
1271 check_isnan_exc ("pow (-10.1, -1.1) == NaN", FUNC(pow) (-10.1, -1.1),
1272 INVALID_EXCEPTION);
1274 check_isinfp_exc ("pow (+0, -1) == +inf", FUNC(pow) (0, -1),
1275 DIVIDE_BY_ZERO_EXCEPTION);
1276 check_isinfp_exc ("pow (+0, -11) == +inf", FUNC(pow) (0, -11),
1277 DIVIDE_BY_ZERO_EXCEPTION);
1278 check_isinfn_exc ("pow (-0, -1) == -inf", FUNC(pow) (minus_zero, -1),
1279 DIVIDE_BY_ZERO_EXCEPTION);
1280 check_isinfn_exc ("pow (-0, -11) == -inf", FUNC(pow) (minus_zero, -11),
1281 DIVIDE_BY_ZERO_EXCEPTION);
1283 check_isinfp_exc ("pow (+0, -2) == +inf", FUNC(pow) (0, -2),
1284 DIVIDE_BY_ZERO_EXCEPTION);
1285 check_isinfp_exc ("pow (+0, -11.1) == +inf", FUNC(pow) (0, -11.1),
1286 DIVIDE_BY_ZERO_EXCEPTION);
1287 check_isinfp_exc ("pow (-0, -2) == +inf", FUNC(pow) (minus_zero, -2),
1288 DIVIDE_BY_ZERO_EXCEPTION);
1289 check_isinfp_exc ("pow (-0, -11.1) == +inf", FUNC(pow) (minus_zero, -11.1),
1290 DIVIDE_BY_ZERO_EXCEPTION);
1292 check ("pow (+0, 1) == +0", FUNC(pow) (0, 1), 0);
1293 check ("pow (+0, 11) == +0", FUNC(pow) (0, 11), 0);
1294 check ("pow (-0, 1) == -0", FUNC(pow) (minus_zero, 1), minus_zero);
1295 check ("pow (-0, 11) == -0", FUNC(pow) (minus_zero, 11), minus_zero);
1297 check ("pow (+0, 2) == +0", FUNC(pow) (0, 2), 0);
1298 check ("pow (+0, 11.1) == +0", FUNC(pow) (0, 11.1), 0);
1299 check ("pow (-0, 2) == +0", FUNC(pow) (minus_zero, 2), 0);
1300 check ("pow (-0, 11.1) == +0", FUNC(pow) (minus_zero, 11.1), 0);
1302 x = random_greater (1.0);
1303 check_isinfp_ext ("pow (x, +inf) == +inf for |x| > 1",
1304 FUNC(pow) (x, plus_infty), x);
1306 x = random_value (-1.0, 1.0);
1307 check_ext ("pow (x, +inf) == +0 for |x| < 1",
1308 FUNC(pow) (x, plus_infty), 0.0, x);
1310 x = random_greater (1.0);
1311 check_ext ("pow (x, -inf) == +0 for |x| > 1",
1312 FUNC(pow) (x, minus_infty), 0.0, x);
1314 x = random_value (-1.0, 1.0);
1315 check_isinfp_ext ("pow (x, -inf) == +inf for |x| < 1",
1316 FUNC(pow) (x, minus_infty), x);
1318 x = random_greater (0.0);
1319 check_isinfp_ext ("pow (+inf, y) == +inf for y > 0",
1320 FUNC(pow) (plus_infty, x), x);
1322 x = random_less (0.0);
1323 check_ext ("pow (+inf, y) == +0 for y < 0",
1324 FUNC(pow) (plus_infty, x), 0.0, x);
1326 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
1327 check_isinfn_ext ("pow (-inf, y) == -inf for y an odd integer > 0",
1328 FUNC(pow) (minus_infty, x), x);
1330 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
1331 check_isinfp_ext ("pow (-inf, y) == +inf for y > 0 and not an odd integer",
1332 FUNC(pow) (minus_infty, x), x);
1334 x = -((rand () % 1000000) * 2.0 + 1); /* Get random odd integer < 0 */
1335 check_ext ("pow (-inf, y) == -0 for y an odd integer < 0",
1336 FUNC(pow) (minus_infty, x), minus_zero, x);
1338 x = ((rand () % 1000000) + 1) * -2.0; /* Get random even integer < 0 */
1339 check_ext ("pow (-inf, y) == +0 for y < 0 and not an odd integer",
1340 FUNC(pow) (minus_infty, x), 0.0, x);
1342 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
1343 check_ext ("pow (+0, y) == +0 for y an odd integer > 0",
1344 FUNC(pow) (0.0, x), 0.0, x);
1345 x = (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
1346 check_ext ("pow (-0, y) == -0 for y an odd integer > 0",
1347 FUNC(pow) (minus_zero, x), minus_zero, x);
1349 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
1350 check_ext ("pow (+0, y) == +0 for y > 0 and not an odd integer",
1351 FUNC(pow) (0.0, x), 0.0, x);
1353 x = ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
1354 check_ext ("pow (-0, y) == +0 for y > 0 and not an odd integer",
1355 FUNC(pow) (minus_zero, x), 0.0, x);
1359 static void
1360 fdim_test (void)
1362 check ("fdim (+0, +0) = +0", FUNC(fdim) (0, 0), 0);
1363 check ("fdim (9, 0) = 9", FUNC(fdim) (9, 0), 9);
1364 check ("fdim (0, 9) = 0", FUNC(fdim) (0, 9), 0);
1365 check ("fdim (-9, 0) = 9", FUNC(fdim) (-9, 0), 0);
1366 check ("fdim (0, -9) = 9", FUNC(fdim) (0, -9), 9);
1368 check_isinfp ("fdim (+inf, 9) = +inf", FUNC(fdim) (plus_infty, 9));
1369 check_isinfp ("fdim (+inf, -9) = +inf", FUNC(fdim) (plus_infty, -9));
1370 check ("fdim (-inf, 9) = 0", FUNC(fdim) (minus_infty, 9), 0);
1371 check ("fdim (-inf, -9) = 0", FUNC(fdim) (minus_infty, -9), 0);
1372 check_isinfp ("fdim (+9, -inf) = +inf", FUNC(fdim) (9, minus_infty));
1373 check_isinfp ("fdim (-9, -inf) = +inf", FUNC(fdim) (-9, minus_infty));
1374 check ("fdim (9, inf) = 0", FUNC(fdim) (9, plus_infty), 0);
1375 check ("fdim (-9, inf) = 0", FUNC(fdim) (-9, plus_infty), 0);
1377 check_isnan ("fdim (0, NaN) = NaN", FUNC(fdim) (0, nan_value));
1378 check_isnan ("fdim (9, NaN) = NaN", FUNC(fdim) (9, nan_value));
1379 check_isnan ("fdim (-9, NaN) = NaN", FUNC(fdim) (-9, nan_value));
1380 check_isnan ("fdim (NaN, 9) = NaN", FUNC(fdim) (nan_value, 9));
1381 check_isnan ("fdim (NaN, -9) = NaN", FUNC(fdim) (nan_value, -9));
1382 check_isnan ("fdim (+inf, NaN) = NaN", FUNC(fdim) (plus_infty, nan_value));
1383 check_isnan ("fdim (-inf, NaN) = NaN", FUNC(fdim) (minus_infty, nan_value));
1384 check_isnan ("fdim (NaN, +inf) = NaN", FUNC(fdim) (nan_value, plus_infty));
1385 check_isnan ("fdim (NaN, -inf) = NaN", FUNC(fdim) (nan_value, minus_infty));
1386 check_isnan ("fdim (NaN, NaN) = NaN", FUNC(fdim) (nan_value, nan_value));
1390 static void
1391 fmin_test (void)
1393 check ("fmin (+0, +0) = +0", FUNC(fmin) (0, 0), 0);
1394 check ("fmin (9, 0) = 0", FUNC(fmin) (9, 0), 0);
1395 check ("fmin (0, 9) = 0", FUNC(fmin) (0, 9), 0);
1396 check ("fmin (-9, 0) = -9", FUNC(fmin) (-9, 0), -9);
1397 check ("fmin (0, -9) = -9", FUNC(fmin) (0, -9), -9);
1399 check ("fmin (+inf, 9) = 9", FUNC(fmin) (plus_infty, 9), 9);
1400 check ("fmin (9, +inf) = 9", FUNC(fmin) (9, plus_infty), 9);
1401 check ("fmin (+inf, -9) = -9", FUNC(fmin) (plus_infty, -9), -9);
1402 check ("fmin (-9, +inf) = -9", FUNC(fmin) (-9, plus_infty), -9);
1403 check_isinfn ("fmin (-inf, 9) = -inf", FUNC(fmin) (minus_infty, 9));
1404 check_isinfn ("fmin (-inf, -9) = -inf", FUNC(fmin) (minus_infty, -9));
1405 check_isinfn ("fmin (+9, -inf) = -inf", FUNC(fmin) (9, minus_infty));
1406 check_isinfn ("fmin (-9, -inf) = -inf", FUNC(fmin) (-9, minus_infty));
1408 check ("fmin (0, NaN) = 0", FUNC(fmin) (0, nan_value), 0);
1409 check ("fmin (9, NaN) = 9", FUNC(fmin) (9, nan_value), 9);
1410 check ("fmin (-9, NaN) = 9", FUNC(fmin) (-9, nan_value), -9);
1411 check ("fmin (NaN, 0) = 0", FUNC(fmin) (nan_value, 0), 0);
1412 check ("fmin (NaN, 9) = NaN", FUNC(fmin) (nan_value, 9), 9);
1413 check ("fmin (NaN, -9) = NaN", FUNC(fmin) (nan_value, -9), -9);
1414 check_isinfp ("fmin (+inf, NaN) = +inf", FUNC(fmin) (plus_infty, nan_value));
1415 check_isinfn ("fmin (-inf, NaN) = -inf", FUNC(fmin) (minus_infty, nan_value));
1416 check_isinfp ("fmin (NaN, +inf) = +inf", FUNC(fmin) (nan_value, plus_infty));
1417 check_isinfn ("fmin (NaN, -inf) = -inf", FUNC(fmin) (nan_value, minus_infty));
1418 check_isnan ("fmin (NaN, NaN) = NaN", FUNC(fmin) (nan_value, nan_value));
1422 static void
1423 fmax_test (void)
1425 check ("fmax (+0, +0) = +0", FUNC(fmax) (0, 0), 0);
1426 check ("fmax (9, 0) = 9", FUNC(fmax) (9, 0), 9);
1427 check ("fmax (0, 9) = 9", FUNC(fmax) (0, 9), 9);
1428 check ("fmax (-9, 0) = 0", FUNC(fmax) (-9, 0), 0);
1429 check ("fmax (0, -9) = 0", FUNC(fmax) (0, -9), 0);
1431 check_isinfp ("fmax (+inf, 9) = +inf", FUNC(fmax) (plus_infty, 9));
1432 check_isinfp ("fmax (9, +inf) = +inf", FUNC(fmax) (0, plus_infty));
1433 check_isinfp ("fmax (-9, +inf) = +inf", FUNC(fmax) (-9, plus_infty));
1434 check_isinfp ("fmax (+inf, -9) = +inf", FUNC(fmax) (plus_infty, -9));
1435 check ("fmax (-inf, 9) = 9", FUNC(fmax) (minus_infty, 9), 9);
1436 check ("fmax (-inf, -9) = -9", FUNC(fmax) (minus_infty, -9), -9);
1437 check ("fmax (+9, -inf) = 9", FUNC(fmax) (9, minus_infty), 9);
1438 check ("fmax (-9, -inf) = -9", FUNC(fmax) (-9, minus_infty), -9);
1440 check ("fmax (0, NaN) = 0", FUNC(fmax) (0, nan_value), 0);
1441 check ("fmax (9, NaN) = 9", FUNC(fmax) (9, nan_value), 9);
1442 check ("fmax (-9, NaN) = 9", FUNC(fmax) (-9, nan_value), -9);
1443 check ("fmax (NaN, 0) = 0", FUNC(fmax) (nan_value, 0), 0);
1444 check ("fmax (NaN, 9) = NaN", FUNC(fmax) (nan_value, 9), 9);
1445 check ("fmax (NaN, -9) = NaN", FUNC(fmax) (nan_value, -9), -9);
1446 check_isinfp ("fmax (+inf, NaN) = +inf", FUNC(fmax) (plus_infty, nan_value));
1447 check_isinfn ("fmax (-inf, NaN) = -inf", FUNC(fmax) (minus_infty, nan_value));
1448 check_isinfp ("fmax (NaN, +inf) = +inf", FUNC(fmax) (nan_value, plus_infty));
1449 check_isinfn ("fmax (NaN, -inf) = -inf", FUNC(fmax) (nan_value, minus_infty));
1450 check_isnan ("fmax (NaN, NaN) = NaN", FUNC(fmax) (nan_value, nan_value));
1454 static void
1455 nextafter_test (void)
1457 MATHTYPE x;
1459 check ("nextafter (+0, +0) = +0", FUNC(nextafter) (0, 0), 0);
1460 check ("nextafter (-0, +0) = +0", FUNC(nextafter) (minus_zero, 0), 0);
1461 check ("nextafter (+0, -0) = -0", FUNC(nextafter) (0, minus_zero),
1462 minus_zero);
1463 check ("nextafter (-0, -0) = -0", FUNC(nextafter) (minus_zero, minus_zero),
1464 minus_zero);
1466 check ("nextafter (9, 9) = 9", FUNC(nextafter) (9, 9), 9);
1467 check ("nextafter (-9, -9) = -9", FUNC(nextafter) (-9, -9), -9);
1468 check_isinfp ("nextafter (+inf, +inf) = +inf",
1469 FUNC(nextafter) (plus_infty, plus_infty));
1470 check_isinfn ("nextafter (-inf, -inf) = -inf",
1471 FUNC(nextafter) (minus_infty, minus_infty));
1473 x = rand () * 1.1;
1474 check_isnan ("nextafter (NaN, x) = NaN", FUNC(nextafter) (nan_value, x));
1475 check_isnan ("nextafter (x, NaN) = NaN", FUNC(nextafter) (x, nan_value));
1476 check_isnan ("nextafter (NaN, NaN) = NaN", FUNC(nextafter) (nan_value,
1477 nan_value));
1479 /* XXX We need the hexadecimal FP number representation here for further
1480 tests. */
1484 static void
1485 copysign_test (void)
1487 check ("copysign (0, 4) = 0", FUNC(copysign) (0, 4), 0);
1488 check ("copysign (0, -4) = -0", FUNC(copysign) (0, -4), minus_zero);
1489 check ("copysign (-0, 4) = 0", FUNC(copysign) (minus_zero, 4), 0);
1490 check ("copysign (-0, -4) = -0", FUNC(copysign) (minus_zero, -4),
1491 minus_zero);
1493 check_isinfp ("copysign (+inf, 0) = +inf", FUNC(copysign) (plus_infty, 0));
1494 check_isinfn ("copysign (+inf, -0) = -inf", FUNC(copysign) (plus_infty,
1495 minus_zero));
1496 check_isinfp ("copysign (-inf, 0) = +inf", FUNC(copysign) (minus_infty, 0));
1497 check_isinfn ("copysign (-inf, -0) = -inf", FUNC(copysign) (minus_infty,
1498 minus_zero));
1500 check ("copysign (0, +inf) = 0", FUNC(copysign) (0, plus_infty), 0);
1501 check ("copysign (0, -inf) = -0", FUNC(copysign) (0, minus_zero),
1502 minus_zero);
1503 check ("copysign (-0, +inf) = 0", FUNC(copysign) (minus_zero, plus_infty),
1505 check ("copysign (-0, -inf) = -0", FUNC(copysign) (minus_zero, minus_zero),
1506 minus_zero);
1508 /* XXX More correctly we would have to check the sign of the NaN. */
1509 check_isnan ("copysign (+NaN, 0) = +NaN", FUNC(copysign) (nan_value, 0));
1510 check_isnan ("copysign (+NaN, -0) = -NaN", FUNC(copysign) (nan_value,
1511 minus_zero));
1512 check_isnan ("copysign (-NaN, 0) = +NaN", FUNC(copysign) (-nan_value, 0));
1513 check_isnan ("copysign (-NaN, -0) = -NaN", FUNC(copysign) (-nan_value,
1514 minus_zero));
1518 static void
1519 trunc_test (void)
1521 check ("trunc(0) = 0", FUNC(trunc) (0), 0);
1522 check ("trunc(-0) = -0", FUNC(trunc) (minus_zero), minus_zero);
1523 check ("trunc(0.625) = 0", FUNC(trunc) (0.625), 0);
1524 check ("trunc(-0.625) = -0", FUNC(trunc) (-0.625), minus_zero);
1525 check ("trunc(1) = 1", FUNC(trunc) (1), 1);
1526 check ("trunc(-1) = -1", FUNC(trunc) (-1), -1);
1527 check ("trunc(1.625) = 1", FUNC(trunc) (1.625), 1);
1528 check ("trunc(-1.625) = -1", FUNC(trunc) (-1.625), -1);
1530 check ("trunc(1048580.625) = 1048580", FUNC(trunc) (1048580.625L),
1531 1048580L);
1532 check ("trunc(-1048580.625) = -1048580", FUNC(trunc) (-1048580.625L),
1533 -1048580L);
1535 check ("trunc(8388610.125) = 8388610", FUNC(trunc) (8388610.125L),
1536 8388610.0L);
1537 check ("trunc(-8388610.125) = -8388610", FUNC(trunc) (-8388610.125L),
1538 -8388610.0L);
1540 check ("trunc(4294967296.625) = 4294967296", FUNC(trunc) (4294967296.625L),
1541 4294967296.0L);
1542 check ("trunc(-4294967296.625) = -4294967296",
1543 FUNC(trunc) (-4294967296.625L), -4294967296.0L);
1545 check_isinfp ("trunc(+inf) = +inf", FUNC(trunc) (plus_infty));
1546 check_isinfn ("trunc(-inf) = -inf", FUNC(trunc) (minus_infty));
1547 check_isnan ("trunc(NaN) = NaN", FUNC(trunc) (nan_value));
1551 static void
1552 sqrt_test (void)
1554 MATHTYPE x;
1557 /* XXX Tests fuer negative x are missing */
1558 check ("sqrt (0) == 0", FUNC(sqrt) (0), 0);
1559 check_isnan ("sqrt (NaN) == NaN", FUNC(sqrt) (nan_value));
1560 check_isinfp ("sqrt (+inf) == +inf", FUNC(sqrt) (plus_infty));
1562 x = random_value (0, 10000);
1563 check_ext ("sqrt (x*x) == x", FUNC(sqrt) (x*x), x, x);
1564 check ("sqrt (4) == 2", FUNC(sqrt) (4), 2);
1568 static void
1569 remquo_test (void)
1571 int quo;
1572 MATHTYPE result;
1574 result = FUNC(remquo) (1.625, 1.0, &quo);
1575 check ("remquo(1.625, 1.0, &x) == -0.375", result, -0.375);
1576 check ("remquo(1.625, 1.0, &x) puts 1 in x", quo, 1);
1578 result = FUNC(remquo) (-1.625, 1.0, &quo);
1579 check ("remquo(-1.625, 1.0, &x) == 0.375", result, 0.375);
1580 check ("remquo(-1.625, 1.0, &x) puts -1 in x", quo, -1);
1582 result = FUNC(remquo) (1.625, -1.0, &quo);
1583 check ("remquo(1.125, -1.0, &x) == 0.125", result, 0.125);
1584 check ("remquo(1.125, -1.0, &x) puts -1 in x", quo, -1);
1586 result = FUNC(remquo) (-1.625, -1.0, &quo);
1587 check ("remquo(-1.125, -1.0, &x) == 0.125", result, 0.125);
1588 check ("remquo(-1.125, -1.0, &x) puts 1 in x", quo, 1);
1592 static void
1593 cexp_test (void)
1595 __complex__ MATHTYPE result;
1597 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, plus_zero));
1598 check ("real(cexp(0 + 0i)) = 1", __real__ result, 1);
1599 check ("imag(cexp(0 + 0i)) = 0", __imag__ result, 0);
1600 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, plus_zero));
1601 check ("real(cexp(-0 + 0i)) = 1", __real__ result, 1);
1602 check ("imag(cexp(-0 + 0i)) = 0", __imag__ result, 0);
1603 result = FUNC(cexp) (BUILD_COMPLEX (plus_zero, minus_zero));
1604 check ("real(cexp(0 - 0i)) = 1", __real__ result, 1);
1605 check ("imag(cexp(0 - 0i)) = -0", __imag__ result, minus_zero);
1606 result = FUNC(cexp) (BUILD_COMPLEX (minus_zero, minus_zero));
1607 check ("real(cexp(-0 - 0i)) = 1", __real__ result, 1);
1608 check ("imag(cexp(-0 - 0i)) = -0", __imag__ result, minus_zero);
1610 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_zero));
1611 check_isinfp ("real(cexp(+inf + 0i)) = +inf", __real__ result);
1612 check ("imag(cexp(+inf + 0i)) = 0", __imag__ result, 0);
1613 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_zero));
1614 check_isinfp ("real(cexp(+inf - 0i)) = +inf", __real__ result);
1615 check ("imag(cexp(+inf - 0i)) = -0", __imag__ result, minus_zero);
1617 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_zero));
1618 check ("real(cexp(-inf + 0i)) = 0", __real__ result, 0);
1619 check ("imag(cexp(-inf + 0i)) = 0", __imag__ result, 0);
1620 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_zero));
1621 check ("real(cexp(-inf - 0i)) = 0", __real__ result, 0);
1622 check ("imag(cexp(-inf - 0i)) = -0", __imag__ result, minus_zero);
1624 result = FUNC(cexp) (BUILD_COMPLEX (100.0, plus_infty));
1625 check_isnan ("real(cexp(x + i inf)) = NaN", __real__ result);
1626 check_isnan ("imag(cexp(x + i inf)) = NaN", __imag__ result);
1627 result = FUNC(cexp) (BUILD_COMPLEX (100.0, minus_infty));
1628 check_isnan ("real(cexp(x - i inf)) = NaN", __real__ result);
1629 check_isnan ("imag(cexp(x - i inf)) = NaN", __imag__ result);
1631 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 2.0));
1632 check ("real(cexp(-inf + 2.0i)) = -0", __real__ result, minus_zero);
1633 check ("imag(cexp(-inf + 2.0i)) = 0", __imag__ result, 0);
1634 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, 4.0));
1635 check ("real(cexp(-inf + 4.0i)) = -0", __real__ result, minus_zero);
1636 check ("imag(cexp(-inf + 4.0i)) = -0", __imag__ result, minus_zero);
1638 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 2.0));
1639 check_isinfn ("real(cexp(+inf + 2.0i)) = -inf", __real__ result);
1640 check_isinfp ("imag(cexp(+inf + 2.0i)) = +inf", __imag__ result);
1641 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, 4.0));
1642 check_isinfn ("real(cexp(+inf + 4.0i)) = -inf", __real__ result);
1643 check_isinfn ("imag(cexp(+inf + 4.0i)) = -inf", __imag__ result);
1645 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, plus_infty));
1646 check_isinfp ("real(cexp(+inf + i inf)) = +inf", __real__ result);
1647 check_isnan ("imag(cexp(+inf + i inf)) = NaN", __imag__ result);
1648 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, minus_infty));
1649 check_isinfp ("real(cexp(+inf - i inf)) = +inf", __real__ result);
1650 check_isnan ("imag(cexp(+inf - i inf)) = NaN", __imag__ result);
1652 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, plus_infty));
1653 check ("real(cexp(-inf + i inf)) = 0", __real__ result, 0);
1654 check ("imag(cexp(-inf + i inf)) = 0", __imag__ result, 0);
1655 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, minus_infty));
1656 check ("real(cexp(-inf - i inf)) = 0", __real__ result, 0);
1657 check ("imag(cexp(-inf - i inf)) = -0", __imag__ result, minus_zero);
1659 result = FUNC(cexp) (BUILD_COMPLEX (minus_infty, nan_value));
1660 check ("real(cexp(-inf + i NaN)) = 0", __real__ result, 0);
1661 check ("imag(cexp(-inf + i NaN)) = 0", fabs (__imag__ result), 0);
1663 result = FUNC(cexp) (BUILD_COMPLEX (plus_infty, nan_value));
1664 check_isinfp ("real(cexp(+inf + i NaN)) = +inf", __real__ result);
1665 check_isnan ("imag(cexp(+inf + i NaN)) = NaN", __imag__ result);
1667 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
1668 check_isnan ("real(cexp(NaN + 1i)) = NaN", __real__ result);
1669 check_isnan ("imag(cexp(NaN + 1i)) = NaN", __imag__ result);
1670 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
1671 check_isnan ("real(cexp(NaN + i inf)) = NaN", __real__ result);
1672 check_isnan ("imag(cexp(NaN + i inf)) = NaN", __imag__ result);
1673 result = FUNC(cexp) (BUILD_COMPLEX (nan_value, 1.0));
1674 check_isnan ("real(cexp(NaN + i NaN)) = NaN", __real__ result);
1675 check_isnan ("imag(cexp(NaN + i NaN)) = NaN", __imag__ result);
1677 result = FUNC(cexp) (BUILD_COMPLEX (0, nan_value));
1678 check_isnan ("real(cexp(0 + i NaN)) = NaN", __real__ result);
1679 check_isnan ("imag(cexp(0 + i NaN)) = NaN", __imag__ result);
1680 result = FUNC(cexp) (BUILD_COMPLEX (1, nan_value));
1681 check_isnan ("real(cexp(1 + i NaN)) = NaN", __real__ result);
1682 check_isnan ("imag(cexp(1 + i NaN)) = NaN", __imag__ result);
1686 static void
1687 csinh_test (void)
1689 __complex__ MATHTYPE result;
1691 result = FUNC(csinh) (BUILD_COMPLEX (0.0, 0.0));
1692 check ("real(csinh(0 + 0i)) = 0", __real__ result, 0);
1693 check ("imag(csinh(0 + 0i)) = 0", __imag__ result, 0);
1694 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, 0.0));
1695 check ("real(csinh(-0 + 0i)) = -0", __real__ result, minus_zero);
1696 check ("imag(csinh(-0 + 0i)) = 0", __imag__ result, 0);
1697 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_zero));
1698 check ("real(csinh(0 - 0i)) = 0", __real__ result, 0);
1699 check ("imag(csinh(0 - 0i)) = -0", __imag__ result, minus_zero);
1700 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_zero));
1701 check ("real(csinh(-0 - 0i)) = -0", __real__ result, minus_zero);
1702 check ("imag(csinh(-0 - 0i)) = -0", __imag__ result, minus_zero);
1704 result = FUNC(csinh) (BUILD_COMPLEX (0.0, plus_infty));
1705 check ("real(csinh(0 + i Inf)) = 0", FUNC(fabs) (__real__ result), 0);
1706 check_isnan ("imag(csinh(0 + i Inf)) = NaN", __imag__ result);
1707 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, plus_infty));
1708 check ("real(csinh(-0 + i Inf)) = -0", FUNC(fabs) (__real__ result), 0);
1709 check_isnan ("imag(csinh(-0 + i Inf)) = NaN", __imag__ result);
1710 result = FUNC(csinh) (BUILD_COMPLEX (0.0, minus_infty));
1711 check ("real(csinh(0 - i Inf)) = 0", FUNC(fabs) (__real__ result), 0);
1712 check_isnan ("imag(csinh(0 - i Inf)) = NaN", __imag__ result);
1713 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, minus_infty));
1714 check ("real(csinh(-0 - i Inf)) = -0", FUNC(fabs) (__real__ result), 0);
1715 check_isnan ("imag(csinh(-0 - i Inf)) = NaN", __imag__ result);
1717 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 0.0));
1718 check_isinfp ("real(csinh(+Inf + 0i)) = +Inf", __real__ result);
1719 check ("imag(csinh(+Inf + 0i)) = 0", __imag__ result, 0);
1720 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 0.0));
1721 check_isinfn ("real(csinh(-Inf + 0i)) = -Inf", __real__ result);
1722 check ("imag(csinh(-Inf + 0i)) = 0", __imag__ result, 0);
1723 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_zero));
1724 check_isinfp ("real(csinh(+Inf - 0i)) = +Inf", __real__ result);
1725 check ("imag(csinh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
1726 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_zero));
1727 check_isinfn ("real(csinh(-Inf - 0i)) = -Inf", __real__ result);
1728 check ("imag(csinh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
1730 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, plus_infty));
1731 check_isinfp ("real(csinh(+Inf + i Inf)) = +-Inf",
1732 FUNC(fabs) (__real__ result));
1733 check_isnan ("imag(csinh(+Inf + i Inf)) = NaN", __imag__ result);
1734 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, plus_infty));
1735 check_isinfp ("real(csinh(-Inf + i Inf)) = +-Inf",
1736 FUNC(fabs) (__real__ result));
1737 check_isnan ("imag(csinh(-Inf + i Inf)) = NaN", __imag__ result);
1738 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, minus_infty));
1739 check_isinfp ("real(csinh(Inf - i Inf)) = +-Inf",
1740 FUNC(fabs) (__real__ result));
1741 check_isnan ("imag(csinh(Inf - i Inf)) = NaN", __imag__ result);
1742 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, minus_infty));
1743 check_isinfp ("real(csinh(-Inf - i Inf)) = -Inf",
1744 FUNC(fabs) (__real__ result));
1745 check_isnan ("imag(csinh(-Inf - i Inf)) = NaN", __imag__ result);
1747 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, 4.625));
1748 check_isinfn ("real(csinh(+Inf + i4.625)) = -Inf", __real__ result);
1749 check_isinfn ("imag(csinh(+Inf + i4.625)) = -Inf", __imag__ result);
1750 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, 4.625));
1751 check_isinfp ("real(csinh(-Inf + i4.625)) = +Inf", __real__ result);
1752 check_isinfn ("imag(csinh(-Inf + i4.625)) = -Inf", __imag__ result);
1753 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, -4.625));
1754 check_isinfn ("real(csinh(+Inf - i4.625)) = -Inf", __real__ result);
1755 check_isinfp ("imag(csinh(+Inf - i4.625)) = +Inf", __imag__ result);
1756 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, -4.625));
1757 check_isinfp ("real(csinh(-Inf - i4.625)) = +Inf", __real__ result);
1758 check_isinfp ("imag(csinh(-Inf - i4.625)) = +Inf", __imag__ result);
1760 result = FUNC(csinh) (BUILD_COMPLEX (6.75, plus_infty));
1761 check_isnan ("real(csinh(6.75 + i Inf)) = NaN", __real__ result);
1762 check_isnan ("imag(csinh(6.75 + i Inf)) = NaN", __imag__ result);
1763 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, plus_infty));
1764 check_isnan ("real(csinh(-6.75 + i Inf)) = NaN", __real__ result);
1765 check_isnan ("imag(csinh(-6.75 + i Inf)) = NaN", __imag__ result);
1766 result = FUNC(csinh) (BUILD_COMPLEX (6.75, minus_infty));
1767 check_isnan ("real(csinh(6.75 - i Inf)) = NaN", __real__ result);
1768 check_isnan ("imag(csinh(6.75 - i Inf)) = NaN", __imag__ result);
1769 result = FUNC(csinh) (BUILD_COMPLEX (-6.75, minus_infty));
1770 check_isnan ("real(csinh(-6.75 - i Inf)) = NaN", __real__ result);
1771 check_isnan ("imag(csinh(-6.75 - i Inf)) = NaN", __imag__ result);
1773 result = FUNC(csinh) (BUILD_COMPLEX (0.0, nan_value));
1774 check ("real(csinh(0 + i NaN)) = 0", FUNC(fabs) (__real__ result), 0);
1775 check_isnan ("imag(csinh(0 + i NaN)) = NaN", __imag__ result);
1776 result = FUNC(csinh) (BUILD_COMPLEX (minus_zero, nan_value));
1777 check ("real(csinh(-0 + i NaN)) = -0", FUNC(fabs) (__real__ result), 0);
1778 check_isnan ("imag(csinh(-0 + i NaN)) = NaN", __imag__ result);
1780 result = FUNC(csinh) (BUILD_COMPLEX (plus_infty, nan_value));
1781 check_isinfp ("real(csinh(+Inf + i NaN)) = +-Inf",
1782 FUNC(fabs) (__real__ result));
1783 check_isnan ("imag(csinh(+Inf + i NaN)) = NaN", __imag__ result);
1784 result = FUNC(csinh) (BUILD_COMPLEX (minus_infty, nan_value));
1785 check_isinfp ("real(csinh(-Inf + i NaN)) = +-Inf",
1786 FUNC(fabs) (__real__ result));
1787 check_isnan ("imag(csinh(-0 + i NaN)) = NaN", __imag__ result);
1789 result = FUNC(csinh) (BUILD_COMPLEX (9.0, nan_value));
1790 check_isnan ("real(csinh(9.0 + i NaN)) = NaN", __real__ result);
1791 check_isnan ("imag(csinh(9.0 + i NaN)) = NaN", __imag__ result);
1792 result = FUNC(csinh) (BUILD_COMPLEX (-9.0, nan_value));
1793 check_isnan ("real(csinh(-9.0 + i NaN)) = NaN", __real__ result);
1794 check_isnan ("imag(csinh(-9.0 + i NaN)) = NaN", __imag__ result);
1796 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 0.0));
1797 check_isnan ("real(csinh(NaN + i0)) = NaN", __real__ result);
1798 check ("imag(csinh(NaN + i0)) = NaN", __imag__ result, 0.0);
1799 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_zero));
1800 check_isnan ("real(csinh(NaN - i0)) = NaN", __real__ result);
1801 check ("imag(csinh(NaN - i0)) = NaN", __imag__ result, minus_zero);
1803 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, 10.0));
1804 check_isnan ("real(csinh(NaN + i10)) = NaN", __real__ result);
1805 check_isnan ("imag(csinh(NaN + i10)) = NaN", __imag__ result);
1806 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, -10.0));
1807 check_isnan ("real(csinh(NaN - i10)) = NaN", __real__ result);
1808 check_isnan ("imag(csinh(NaN - i10)) = NaN", __imag__ result);
1810 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, plus_infty));
1811 check_isnan ("real(csinh(NaN + i Inf)) = NaN", __real__ result);
1812 check_isnan ("imag(csinh(NaN + i Inf)) = NaN", __imag__ result);
1813 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, minus_infty));
1814 check_isnan ("real(csinh(NaN - i Inf)) = NaN", __real__ result);
1815 check_isnan ("imag(csinh(NaN - i Inf)) = NaN", __imag__ result);
1817 result = FUNC(csinh) (BUILD_COMPLEX (nan_value, nan_value));
1818 check_isnan ("real(csinh(NaN + i NaN)) = NaN", __real__ result);
1819 check_isnan ("imag(csinh(NaN + i NaN)) = NaN", __imag__ result);
1823 static void
1824 ccosh_test (void)
1826 __complex__ MATHTYPE result;
1828 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, 0.0));
1829 check ("real(ccosh(0 + 0i)) = 0", __real__ result, 1.0);
1830 check ("imag(ccosh(0 + 0i)) = 0", __imag__ result, 0);
1831 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, 0.0));
1832 check ("real(ccosh(-0 + 0i)) = -0", __real__ result, 1.0);
1833 check ("imag(ccosh(-0 + 0i)) = 0", __imag__ result, 0);
1834 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_zero));
1835 check ("real(ccosh(0 - 0i)) = 0", __real__ result, 1.0);
1836 check ("imag(ccosh(0 - 0i)) = -0", __imag__ result, minus_zero);
1837 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_zero));
1838 check ("real(ccosh(-0 - 0i)) = -0", __real__ result, 1.0);
1839 check ("imag(ccosh(-0 - 0i)) = -0", __imag__ result, minus_zero);
1841 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, plus_infty));
1842 check_isnan ("real(ccosh(0 + i Inf)) = NaN", __real__ result);
1843 check ("imag(ccosh(0 + i Inf)) = +-0", FUNC(fabs) (__imag__ result), 0);
1844 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, plus_infty));
1845 check_isnan ("real(ccosh(-0 + i Inf)) = NaN", __real__ result);
1846 check ("imag(ccosh(-0 + i Inf)) = -0", FUNC(fabs) (__imag__ result), 0);
1847 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, minus_infty));
1848 check_isnan ("real(ccosh(0 - i Inf)) = NaN", __real__ result);
1849 check ("imag(ccosh(0 - i Inf)) = 0", FUNC(fabs) (__imag__ result), 0);
1850 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, minus_infty));
1851 check_isnan ("real(ccosh(-0 - i Inf)) = NaN", __real__ result);
1852 check ("imag(ccosh(-0 - i Inf)) = -0", FUNC(fabs) (__imag__ result), 0);
1854 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 0.0));
1855 check_isinfp ("real(ccosh(+Inf + 0i)) = +Inf", __real__ result);
1856 check ("imag(ccosh(+Inf + 0i)) = 0", __imag__ result, 0);
1857 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 0.0));
1858 check_isinfp ("real(ccosh(-Inf + 0i)) = +Inf", __real__ result);
1859 check ("imag(ccosh(-Inf + 0i)) = 0", __imag__ result, 0);
1860 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_zero));
1861 check_isinfp ("real(ccosh(+Inf - 0i)) = +Inf", __real__ result);
1862 check ("imag(ccosh(+Inf - 0i)) = -0", __imag__ result, minus_zero);
1863 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_zero));
1864 check_isinfp ("real(ccosh(-Inf - 0i)) = +Inf", __real__ result);
1865 check ("imag(ccosh(-Inf - 0i)) = -0", __imag__ result, minus_zero);
1867 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, plus_infty));
1868 check_isinfp ("real(ccosh(+Inf + i Inf)) = +Inf", __real__ result);
1869 check_isnan ("imag(ccosh(+Inf + i Inf)) = NaN", __imag__ result);
1870 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, plus_infty));
1871 check_isinfp ("real(ccosh(-Inf + i Inf)) = +Inf", __real__ result);
1872 check_isnan ("imag(ccosh(-Inf + i Inf)) = NaN", __imag__ result);
1873 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, minus_infty));
1874 check_isinfp ("real(ccosh(Inf - i Inf)) = +Inf", __real__ result);
1875 check_isnan ("imag(ccosh(Inf - i Inf)) = NaN", __imag__ result);
1876 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, minus_infty));
1877 check_isinfp ("real(ccosh(-Inf - i Inf)) = +Inf", __real__ result);
1878 check_isnan ("imag(ccosh(-Inf - i Inf)) = NaN", __imag__ result);
1880 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, 4.625));
1881 check_isinfn ("real(ccosh(+Inf + i4.625)) = -Inf", __real__ result);
1882 check_isinfn ("imag(ccosh(+Inf + i4.625)) = -Inf", __imag__ result);
1883 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, 4.625));
1884 check_isinfn ("real(ccosh(-Inf + i4.625)) = -Inf", __real__ result);
1885 check_isinfn ("imag(ccosh(-Inf + i4.625)) = -Inf", __imag__ result);
1886 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, -4.625));
1887 check_isinfn ("real(ccosh(+Inf - i4.625)) = -Inf", __real__ result);
1888 check_isinfp ("imag(ccosh(+Inf - i4.625)) = +Inf", __imag__ result);
1889 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, -4.625));
1890 check_isinfn ("real(ccosh(-Inf - i4.625)) = -Inf", __real__ result);
1891 check_isinfp ("imag(ccosh(-Inf - i4.625)) = +Inf", __imag__ result);
1893 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, plus_infty));
1894 check_isnan ("real(ccosh(6.75 + i Inf)) = NaN", __real__ result);
1895 check_isnan ("imag(ccosh(6.75 + i Inf)) = NaN", __imag__ result);
1896 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, plus_infty));
1897 check_isnan ("real(ccosh(-6.75 + i Inf)) = NaN", __real__ result);
1898 check_isnan ("imag(ccosh(-6.75 + i Inf)) = NaN", __imag__ result);
1899 result = FUNC(ccosh) (BUILD_COMPLEX (6.75, minus_infty));
1900 check_isnan ("real(ccosh(6.75 - i Inf)) = NaN", __real__ result);
1901 check_isnan ("imag(ccosh(6.75 - i Inf)) = NaN", __imag__ result);
1902 result = FUNC(ccosh) (BUILD_COMPLEX (-6.75, minus_infty));
1903 check_isnan ("real(ccosh(-6.75 - i Inf)) = NaN", __real__ result);
1904 check_isnan ("imag(ccosh(-6.75 - i Inf)) = NaN", __imag__ result);
1906 result = FUNC(ccosh) (BUILD_COMPLEX (0.0, nan_value));
1907 check_isnan ("real(ccosh(0 + i NaN)) = NaN", __real__ result);
1908 check ("imag(ccosh(0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
1909 result = FUNC(ccosh) (BUILD_COMPLEX (minus_zero, nan_value));
1910 check_isnan ("real(ccosh(-0 + i NaN)) = NaN", __real__ result);
1911 check ("imag(ccosh(-0 + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
1913 result = FUNC(ccosh) (BUILD_COMPLEX (plus_infty, nan_value));
1914 check_isinfp ("real(ccosh(+Inf + i NaN)) = +Inf", __real__ result);
1915 check_isnan ("imag(ccosh(+Inf + i NaN)) = NaN", __imag__ result);
1916 result = FUNC(ccosh) (BUILD_COMPLEX (minus_infty, nan_value));
1917 check_isinfp ("real(ccosh(-Inf + i NaN)) = +Inf", __real__ result);
1918 check_isnan ("imag(ccosh(-0 + i NaN)) = NaN", __imag__ result);
1920 result = FUNC(ccosh) (BUILD_COMPLEX (9.0, nan_value));
1921 check_isnan ("real(ccosh(9.0 + i NaN)) = NaN", __real__ result);
1922 check_isnan ("imag(ccosh(9.0 + i NaN)) = NaN", __imag__ result);
1923 result = FUNC(ccosh) (BUILD_COMPLEX (-9.0, nan_value));
1924 check_isnan ("real(ccosh(-9.0 + i NaN)) = NaN", __real__ result);
1925 check_isnan ("imag(ccosh(-9.0 + i NaN)) = NaN", __imag__ result);
1927 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 0.0));
1928 check_isnan ("real(ccosh(NaN + i0)) = NaN", __real__ result);
1929 check ("imag(ccosh(NaN + i0)) = NaN", __imag__ result, 0.0);
1930 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_zero));
1931 check_isnan ("real(ccosh(NaN - i0)) = NaN", __real__ result);
1932 check ("imag(ccosh(NaN - i0)) = NaN", __imag__ result, minus_zero);
1934 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, 10.0));
1935 check_isnan ("real(ccosh(NaN + i10)) = NaN", __real__ result);
1936 check_isnan ("imag(ccosh(NaN + i10)) = NaN", __imag__ result);
1937 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, -10.0));
1938 check_isnan ("real(ccosh(NaN - i10)) = NaN", __real__ result);
1939 check_isnan ("imag(ccosh(NaN - i10)) = NaN", __imag__ result);
1941 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, plus_infty));
1942 check_isnan ("real(ccosh(NaN + i Inf)) = NaN", __real__ result);
1943 check_isnan ("imag(ccosh(NaN + i Inf)) = NaN", __imag__ result);
1944 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, minus_infty));
1945 check_isnan ("real(ccosh(NaN - i Inf)) = NaN", __real__ result);
1946 check_isnan ("imag(ccosh(NaN - i Inf)) = NaN", __imag__ result);
1948 result = FUNC(ccosh) (BUILD_COMPLEX (nan_value, nan_value));
1949 check_isnan ("real(ccosh(NaN + i NaN)) = NaN", __real__ result);
1950 check_isnan ("imag(ccosh(NaN + i NaN)) = NaN", __imag__ result);
1954 #if 0
1955 /* Enable these tests as soon as the functions are available. */
1956 static void
1957 cacos_test (void)
1959 __complex__ MATHTYPE result;
1961 result = FUNC(cacos) (BUILD_COMPLEX (0, 0));
1962 check ("real(cacos(0 + i0)) = pi/2", __real__ result, M_PI_2);
1963 check ("imag(cacos(0 + i0)) = -0", __imag__ result, minus_zero);
1964 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, 0));
1965 check ("real(cacos(-0 + i0)) = pi/2", __real__ result, M_PI_2);
1966 check ("imag(cacos(-0 + i0)) = -0", __imag__ result, minus_zero);
1967 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_zero));
1968 check ("real(cacos(0 - i0)) = pi/2", __real__ result, M_PI_2);
1969 check ("imag(cacos(0 - i0)) = 0", __imag__ result, 0);
1970 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, minus_zero));
1971 check ("real(cacos(-0 - i0)) = pi/2", __real__ result, M_PI_2);
1972 check ("imag(cacos(-0 - i0)) = 0", __imag__ result, 0);
1974 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, plus_infty));
1975 check ("real(cacos(-Inf + i Inf)) = 3*pi/4", __real__ result, M_PI - M_PI_4);
1976 check_isinfn ("imag(cacos(-Inf + i Inf)) = -Inf", __imag__ result);
1977 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_infty));
1978 check ("real(cacos(-Inf - i Inf)) = 3*pi/4", __real__ result, M_PI - M_PI_4);
1979 check_isinfp ("imag(cacos(-Inf - i Inf)) = +Inf", __imag__ result);
1981 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, plus_infty));
1982 check ("real(cacos(+Inf + i Inf)) = pi/4", __real__ result, M_PI_4);
1983 check_isinfn ("imag(cacos(+Inf + i Inf)) = -Inf", __imag__ result);
1984 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_infty));
1985 check ("real(cacos(+Inf - i Inf)) = pi/4", __real__ result, M_PI_4);
1986 check_isinfp ("imag(cacos(+Inf - i Inf)) = +Inf", __imag__ result);
1988 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, plus_infty));
1989 check ("real(cacos(-10.0 + i Inf)) = pi/2", __real__ result, M_PI_2);
1990 check_isinfn ("imag(cacos(-10.0 + i Inf)) = -Inf", __imag__ result);
1991 result = FUNC(cacos) (BUILD_COMPLEX (-10.0, minus_infty));
1992 check ("real(cacos(-10.0 - i Inf)) = pi/2", __real__ result, M_PI_2);
1993 check_isinfp ("imag(cacos(-10.0 - i Inf)) = +Inf", __imag__ result);
1994 result = FUNC(cacos) (BUILD_COMPLEX (0, plus_infty));
1995 check ("real(cacos(0 + i Inf)) = pi/2", __real__ result, M_PI_2);
1996 check_isinfn ("imag(cacos(0 + i Inf)) = -Inf", __imag__ result);
1997 result = FUNC(cacos) (BUILD_COMPLEX (0, minus_infty));
1998 check ("real(cacos(0 - i Inf)) = pi/2", __real__ result, M_PI_2);
1999 check_isinfp ("imag(cacos(0 - i Inf)) = +Inf", __imag__ result);
2000 result = FUNC(cacos) (BUILD_COMPLEX (0.1, plus_infty));
2001 check ("real(cacos(0.1 + i Inf)) = pi/2", __real__ result, M_PI_2);
2002 check_isinfn ("imag(cacos(0.1 + i Inf)) = -Inf", __imag__ result);
2003 result = FUNC(cacos) (BUILD_COMPLEX (0.1, minus_infty));
2004 check ("real(cacos(0.1 - i Inf)) = pi/2", __real__ result, M_PI_2);
2005 check_isinfp ("imag(cacos(0.1 - i Inf)) = +Inf", __imag__ result);
2007 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 0));
2008 check ("real(cacos(-Inf + i0)) = pi", __real__ result, M_PI);
2009 check_isinfn ("imag(cacos(-Inf + i0)) = -Inf", __imag__ result);
2010 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, minus_zero));
2011 check ("real(cacos(-Inf - i0)) = pi", __real__ result, M_PI);
2012 check_isinfp ("imag(cacos(-Inf - i0)) = +Inf", __imag__ result);
2013 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, 100));
2014 check ("real(cacos(-Inf + i100)) = pi", __real__ result, M_PI);
2015 check_isinfn ("imag(cacos(-Inf + i100)) = -Inf", __imag__ result);
2016 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, -100));
2017 check ("real(cacos(-Inf - i100)) = pi", __real__ result, M_PI);
2018 check_isinfp ("imag(cacos(-Inf - i100)) = +Inf", __imag__ result);
2020 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0));
2021 check ("real(cacos(+Inf + i0)) = 0", __real__ result, 0);
2022 check_isinfn ("imag(cacos(+Inf + i0)) = -Inf", __imag__ result);
2023 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, minus_zero));
2024 check ("real(cacos(+Inf - i0)) = 0", __real__ result, 0);
2025 check_isinfp ("imag(cacos(+Inf - i0)) = +Inf", __imag__ result);
2026 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, 0.5));
2027 check ("real(cacos(+Inf + i0.5)) = 0", __real__ result, 0);
2028 check_isinfn ("imag(cacos(+Inf + i0.5)) = -Inf", __imag__ result);
2029 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, -0.5));
2030 check ("real(cacos(+Inf - i0.5)) = 0", __real__ result, 0);
2031 check_isinfp ("imag(cacos(+Inf - i0.5)) = +Inf", __imag__ result);
2033 result = FUNC(cacos) (BUILD_COMPLEX (plus_infty, nan_value));
2034 check_isnan ("real(cacos(+Inf + i NaN)) = NaN", __real__ result);
2035 check_isinfp ("imag(cacos(+Inf + i NaN)) = +-Inf",
2036 FUNC(fabs) (__imag__ result));
2037 result = FUNC(cacos) (BUILD_COMPLEX (minus_infty, nan_value));
2038 check_isnan ("real(cacos(-Inf + i NaN)) = NaN", __real__ result);
2039 check_isinfp ("imag(cacos(-Inf + i NaN)) = +-Inf",
2040 FUNC(fabs) (__imag__ result));
2042 result = FUNC(cacos) (BUILD_COMPLEX (0, nan_value));
2043 check ("real(cacos(0 + i NaN)) = pi/2", __real__ result, M_PI_2);
2044 check_isnan ("imag(cacos(0 + i NaN)) = NaN", __imag__ result);
2045 result = FUNC(cacos) (BUILD_COMPLEX (minus_zero, nan_value));
2046 check ("real(cacos(-0 + i NaN)) = pi/2", __real__ result, M_PI_2);
2047 check_isnan ("imag(cacos(-0 + i NaN)) = NaN", __imag__ result);
2049 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, plus_infty));
2050 check_isnan ("real(cacos(NaN + i Inf)) = NaN", __real__ result);
2051 check_isinfn ("imag(cacos(NaN + i Inf)) = -Inf", __imag__ result);
2052 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, minus_infty));
2053 check_isnan ("real(cacos(NaN - i Inf)) = NaN", __real__ result);
2054 check_isinfp ("imag(cacos(NaN - i Inf)) = +Inf", __imag__ result);
2056 result = FUNC(cacos) (BUILD_COMPLEX (10.5, nan_value));
2057 check_isnan ("real(cacos(10.5 + i NaN)) = NaN", __real__ result);
2058 check_isnan ("imag(cacos(10.5 + i NaN)) = NaN", __imag__ result);
2059 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
2060 check_isnan ("real(cacos(-10.5 + i NaN)) = NaN", __real__ result);
2061 check_isnan ("imag(cacos(-10.5 + i NaN)) = NaN", __imag__ result);
2063 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, 0.75));
2064 check_isnan ("real(cacos(NaN + i0.75)) = NaN", __real__ result);
2065 check_isnan ("imag(cacos(NaN + i0.75)) = NaN", __imag__ result);
2066 result = FUNC(cacos) (BUILD_COMPLEX (-10.5, nan_value));
2067 check_isnan ("real(cacos(NaN - i0.75)) = NaN", __real__ result);
2068 check_isnan ("imag(cacos(NaN - i0.75)) = NaN", __imag__ result);
2070 result = FUNC(cacos) (BUILD_COMPLEX (nan_value, nan_value));
2071 check_isnan ("real(cacos(NaN + i NaN)) = NaN", __real__ result);
2072 check_isnan ("imag(cacos(NaN + i NaN)) = NaN", __imag__ result);
2076 static void
2077 cacosh_test (void)
2079 __complex__ MATHTYPE result;
2081 result = FUNC(cacosh) (BUILD_COMPLEX (0, 0));
2082 check ("real(cacosh(0 + i0)) = 0", __real__ result, 0);
2083 check ("imag(cacosh(0 + i0)) = pi/2", __imag__ result, M_PI_2);
2084 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, 0));
2085 check ("real(cacosh(-0 + i0)) = 0", __real__ result, 0);
2086 check ("imag(cacosh(-0 + i0)) = pi/2", __imag__ result, M_PI_2);
2087 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_zero));
2088 check ("real(cacosh(0 - i0)) = 0", __real__ result, 0);
2089 check ("imag(cacosh(0 - i0)) = -pi/2", __imag__ result, -M_PI_2);
2090 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, minus_zero));
2091 check ("real(cacosh(-0 - i0)) = 0", __real__ result, 0);
2092 check ("imag(cacosh(-0 - i0)) = -pi/2", __imag__ result, -M_PI_2);
2094 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, plus_infty));
2095 check_isinfp ("real(cacosh(-Inf + i Inf)) = +Inf", __real__ result);
2096 check ("imag(cacosh(-Inf + i Inf)) = 3*pi/4", __imag__ result,
2097 M_PI - M_PI_4);
2098 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_infty));
2099 check_isinfp ("real(cacosh(-Inf - i Inf)) = +Inf", __real__ result);
2100 check ("imag(cacosh(-Inf - i Inf)) = -3*pi/4", __imag__ result,
2101 M_PI_4 - M_PI);
2103 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, plus_infty));
2104 check_isinfp ("real(cacosh(+Inf + i Inf)) = +Inf", __real__ result);
2105 check ("imag(cacosh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
2106 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_infty));
2107 check_isinfp ("real(cacosh(+Inf - i Inf)) = +Inf", __real__ result);
2108 check ("imag(cacosh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
2110 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, plus_infty));
2111 check_isinfp ("real(cacosh(-10.0 + i Inf)) = +Inf", __real__ result);
2112 check ("imag(cacosh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2113 result = FUNC(cacosh) (BUILD_COMPLEX (-10.0, minus_infty));
2114 check_isinfp ("real(cacosh(-10.0 - i Inf)) = +Inf", __real__ result);
2115 check ("imag(cacosh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2116 result = FUNC(cacosh) (BUILD_COMPLEX (0, plus_infty));
2117 check_isinfp ("real(cacosh(0 + i Inf)) = +Inf", __real__ result);
2118 check ("imag(cacosh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2119 result = FUNC(cacosh) (BUILD_COMPLEX (0, minus_infty));
2120 check_isinfp ("real(cacosh(0 - i Inf)) = +Inf", __real__ result);
2121 check ("imag(cacosh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2122 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, plus_infty));
2123 check_isinfp ("real(cacosh(0.1 + i Inf)) = +Inf", __real__ result);
2124 check ("imag(cacosh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2125 result = FUNC(cacosh) (BUILD_COMPLEX (0.1, minus_infty));
2126 check_isinfp ("real(cacosh(0.1 - i Inf)) = +Inf", __real__ result);
2127 check ("imag(cacosh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2129 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 0));
2130 check_isinfp ("real(cacosh(-Inf + i0)) = +Inf", __real__ result);
2131 check ("imag(cacosh(-Inf + i0)) = pi", __imag__ result, M_PI);
2132 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, minus_zero));
2133 check_isinfp ("real(cacosh(-Inf - i0)) = +Inf", __real__ result);
2134 check ("imag(cacosh(-Inf - i0)) = -pi", __imag__ result, -M_PI);
2135 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, 100));
2136 check_isinfp ("real(cacosh(-Inf + i100)) = +Inf", __real__ result);
2137 check ("imag(cacosh(-Inf + i100)) = pi", __imag__ result, M_PI);
2138 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, -100));
2139 check_isinfp ("real(cacosh(-Inf - i100)) = +Inf", __real__ result);
2140 check ("imag(cacosh(-Inf - i100)) = -pi", __imag__ result, -M_PI);
2142 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0));
2143 check_isinfp ("real(cacosh(+Inf + i0)) = +Inf", __real__ result);
2144 check ("imag(cacosh(+Inf + i0)) = 0", __imag__ result, 0);
2145 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, minus_zero));
2146 check_isinfp ("real(cacosh(+Inf - i0)) = +Inf", __real__ result);
2147 check ("imag(cacosh(+Inf - i0)) = -0", __imag__ result, minus_zero);
2148 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, 0.5));
2149 check_isinfp ("real(cacosh(+Inf + i0.5)) = +Inf", __real__ result);
2150 check ("imag(cacosh(+Inf + i0.5)) = 0", __imag__ result, 0);
2151 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, -0.5));
2152 check_isinfp ("real(cacosh(+Inf - i0.5)) = +Inf", __real__ result);
2153 check ("imag(cacosh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
2155 result = FUNC(cacosh) (BUILD_COMPLEX (plus_infty, nan_value));
2156 check_isinfp ("real(cacosh(+Inf + i NaN)) = +Inf", __real__ result);
2157 check_isnan ("imag(cacosh(+Inf + i NaN)) = NaN", __imag__ result);
2158 result = FUNC(cacosh) (BUILD_COMPLEX (minus_infty, nan_value));
2159 check_isinfp ("real(cacosh(-Inf + i NaN)) = +Inf", __real__ result);
2160 check_isnan ("imag(cacosh(-Inf + i NaN)) = NaN", __imag__ result);
2162 result = FUNC(cacosh) (BUILD_COMPLEX (0, nan_value));
2163 check_isnan ("real(cacosh(0 + i NaN)) = NaN", __real__ result);
2164 check_isnan ("imag(cacosh(0 + i NaN)) = NaN", __imag__ result);
2165 result = FUNC(cacosh) (BUILD_COMPLEX (minus_zero, nan_value));
2166 check_isnan ("real(cacosh(-0 + i NaN)) = NaN", __real__ result);
2167 check_isnan ("imag(cacosh(-0 + i NaN)) = NaN", __imag__ result);
2169 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, plus_infty));
2170 check_isinfp ("real(cacosh(NaN + i Inf)) = +Inf", __real__ result);
2171 check_isnan ("imag(cacosh(NaN + i Inf)) = NaN", __imag__ result);
2172 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, minus_infty));
2173 check_isinfp ("real(cacosh(NaN - i Inf)) = +Inf", __real__ result);
2174 check_isnan ("imag(cacosh(NaN - i Inf)) = NaN", __imag__ result);
2176 result = FUNC(cacosh) (BUILD_COMPLEX (10.5, nan_value));
2177 check_isnan ("real(cacosh(10.5 + i NaN)) = NaN", __real__ result);
2178 check_isnan ("imag(cacosh(10.5 + i NaN)) = NaN", __imag__ result);
2179 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
2180 check_isnan ("real(cacosh(-10.5 + i NaN)) = NaN", __real__ result);
2181 check_isnan ("imag(cacosh(-10.5 + i NaN)) = NaN", __imag__ result);
2183 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, 0.75));
2184 check_isnan ("real(cacosh(NaN + i0.75)) = NaN", __real__ result);
2185 check_isnan ("imag(cacosh(NaN + i0.75)) = NaN", __imag__ result);
2186 result = FUNC(cacosh) (BUILD_COMPLEX (-10.5, nan_value));
2187 check_isnan ("real(cacosh(NaN - i0.75)) = NaN", __real__ result);
2188 check_isnan ("imag(cacosh(NaN - i0.75)) = NaN", __imag__ result);
2190 result = FUNC(cacosh) (BUILD_COMPLEX (nan_value, nan_value));
2191 check_isnan ("real(cacosh(NaN + i NaN)) = NaN", __real__ result);
2192 check_isnan ("imag(cacosh(NaN + i NaN)) = NaN", __imag__ result);
2196 static void
2197 casinh_test (void)
2199 __complex__ MATHTYPE result;
2201 result = FUNC(casinh) (BUILD_COMPLEX (0, 0));
2202 check ("real(casinh(0 + i0)) = 0", __real__ result, 0);
2203 check ("imag(casinh(0 + i0)) = 0", __imag__ result, 0);
2204 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, 0));
2205 check ("real(casinh(-0 + i0)) = -0", __real__ result, minus_zero);
2206 check ("imag(casinh(-0 + i0)) = 0", __imag__ result, 0);
2207 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_zero));
2208 check ("real(casinh(0 - i0)) = 0", __real__ result, 0);
2209 check ("imag(casinh(0 - i0)) = -0", __imag__ result, minus_zero);
2210 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, minus_zero));
2211 check ("real(casinh(-0 - i0)) = -0", __real__ result, minus_zero);
2212 check ("imag(casinh(-0 - i0)) = -0", __imag__ result, minus_zero);
2214 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, plus_infty));
2215 check_isinfp ("real(casinh(+Inf + i Inf)) = +Inf", __real__ result);
2216 check ("imag(casinh(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
2217 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_infty));
2218 check_isinfp ("real(casinh(+Inf - i Inf)) = +Inf", __real__ result);
2219 check ("imag(casinh(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
2220 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, plus_infty));
2221 check_isinfn ("real(casinh(-Inf + i Inf)) = -Inf", __real__ result);
2222 check ("imag(casinh(-Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
2223 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_infty));
2224 check_isinfn ("real(casinh(-Inf - i Inf)) = -Inf", __real__ result);
2225 check ("imag(casinh(-Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
2227 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, plus_infty));
2228 check_isinfn ("real(casinh(-10.0 + i Inf)) = -Inf", __real__ result);
2229 check ("imag(casinh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2230 result = FUNC(casinh) (BUILD_COMPLEX (-10.0, minus_infty));
2231 check_isinfn ("real(casinh(-10.0 - i Inf)) = -Inf", __real__ result);
2232 check ("imag(casinh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2233 result = FUNC(casinh) (BUILD_COMPLEX (0, plus_infty));
2234 check_isinfp ("real(casinh(0 + i Inf)) = +Inf", __real__ result);
2235 check ("imag(casinh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2236 result = FUNC(casinh) (BUILD_COMPLEX (0, minus_infty));
2237 check_isinfp ("real(casinh(0 - i Inf)) = +Inf", __real__ result);
2238 check ("imag(casinh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2239 result = FUNC(casinh) (BUILD_COMPLEX (0.1, plus_infty));
2240 check_isinfp ("real(casinh(0.1 + i Inf)) = +Inf", __real__ result);
2241 check ("imag(casinh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2242 result = FUNC(casinh) (BUILD_COMPLEX (0.1, minus_infty));
2243 check_isinfp ("real(casinh(0.1 - i Inf)) = +Inf", __real__ result);
2244 check ("imag(casinh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2246 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 0));
2247 check_isinfn ("real(casinh(-Inf + i0)) = -Inf", __real__ result);
2248 check ("imag(casinh(-Inf + i0)) = 0", __imag__ result, 0);
2249 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, minus_zero));
2250 check_isinfn ("real(casinh(-Inf - i0)) = -Inf", __real__ result);
2251 check ("imag(casinh(-Inf - i0)) = -0", __imag__ result, minus_zero);
2252 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, 100));
2253 check_isinfn ("real(casinh(-Inf + i100)) = -Inf", __real__ result);
2254 check ("imag(casinh(-Inf + i100)) = 0", __imag__ result, 0);
2255 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, -100));
2256 check_isinfn ("real(casinh(-Inf - i100)) = -Inf", __real__ result);
2257 check ("imag(casinh(-Inf - i100)) = -0", __imag__ result, minus_zero);
2259 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0));
2260 check_isinfp ("real(casinh(+Inf + i0)) = +Inf", __real__ result);
2261 check ("imag(casinh(+Inf + i0)) = 0", __imag__ result, 0);
2262 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, minus_zero));
2263 check_isinfp ("real(casinh(+Inf - i0)) = +Inf", __real__ result);
2264 check ("imag(casinh(+Inf - i0)) = -0", __imag__ result, minus_zero);
2265 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, 0.5));
2266 check_isinfp ("real(casinh(+Inf + i0.5)) = +Inf", __real__ result);
2267 check ("imag(casinh(+Inf + i0.5)) = 0", __imag__ result, 0);
2268 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, -0.5));
2269 check_isinfp ("real(casinh(+Inf - i0.5)) = +Inf", __real__ result);
2270 check ("imag(casinh(+Inf - i0.5)) = -0", __imag__ result, minus_zero);
2272 result = FUNC(casinh) (BUILD_COMPLEX (plus_infty, nan_value));
2273 check_isinfp ("real(casinh(+Inf + i NaN)) = +Inf", __real__ result);
2274 check_isnan ("imag(casinh(+Inf + i NaN)) = NaN", __imag__ result);
2275 result = FUNC(casinh) (BUILD_COMPLEX (minus_infty, nan_value));
2276 check_isinfn ("real(casinh(-Inf + i NaN)) = -Inf", __real__ result);
2277 check_isnan ("imag(casinh(-Inf + i NaN)) = NaN", __imag__ result);
2279 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0));
2280 check_isnan ("real(casinh(NaN + i0)) = NaN", __real__ result);
2281 check ("imag(casinh(NaN + i0)) = 0", __imag__ resul, 0);
2282 result = FUNC(casinh) (BUILD_COMPLEX (minus_zero, nan_value));
2283 check_isnan ("real(casinh(NaN - i0)) = NaN", __real__ result);
2284 check ("imag(casinh(NaN - i0)) = -0", __imag__ result, minus_zero);
2286 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, plus_infty));
2287 check_isinfp ("real(casinh(NaN + i Inf)) = +Inf",
2288 FUNC(fabs) (__real__ result));
2289 check_isnan ("imag(casinh(NaN + i Inf)) = NaN", __imag__ result);
2290 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, minus_infty));
2291 check_isinfp ("real(casinh(NaN - i Inf)) = +Inf",
2292 FUNC(fabs) (__real__ result));
2293 check_isnan ("imag(casinh(NaN - i Inf)) = NaN", __imag__ result);
2295 result = FUNC(casinh) (BUILD_COMPLEX (10.5, nan_value));
2296 check_isnan ("real(casinh(10.5 + i NaN)) = NaN", __real__ result);
2297 check_isnan ("imag(casinh(10.5 + i NaN)) = NaN", __imag__ result);
2298 result = FUNC(casinh) (BUILD_COMPLEX (-10.5, nan_value));
2299 check_isnan ("real(casinh(-10.5 + i NaN)) = NaN", __real__ result);
2300 check_isnan ("imag(casinh(-10.5 + i NaN)) = NaN", __imag__ result);
2302 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, 0.75));
2303 check_isnan ("real(casinh(NaN + i0.75)) = NaN", __real__ result);
2304 check_isnan ("imag(casinh(NaN + i0.75)) = NaN", __imag__ result);
2305 result = FUNC(casinh) (BUILD_COMPLEX (-10.5, nan_value));
2306 check_isnan ("real(casinh(NaN - i0.75)) = NaN", __real__ result);
2307 check_isnan ("imag(casinh(NaN - i0.75)) = NaN", __imag__ result);
2309 result = FUNC(casinh) (BUILD_COMPLEX (nan_value, nan_value));
2310 check_isnan ("real(casinh(NaN + i NaN)) = NaN", __real__ result);
2311 check_isnan ("imag(casinh(NaN + i NaN)) = NaN", __imag__ result);
2315 static void
2316 catanh_test (void)
2318 __complex__ MATHTYPE result;
2320 result = FUNC(catanh) (BUILD_COMPLEX (0, 0));
2321 check ("real(catanh(0 + i0)) = 0", __real__ result, 0);
2322 check ("imag(catanh(0 + i0)) = 0", __imag__ result, 0);
2323 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, 0));
2324 check ("real(catanh(-0 + i0)) = -0", __real__ result, minus_zero);
2325 check ("imag(catanh(-0 + i0)) = 0", __imag__ result, 0);
2326 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_zero));
2327 check ("real(catanh(0 - i0)) = 0", __real__ result, 0);
2328 check ("imag(catanh(0 - i0)) = -0", __imag__ result, minus_zero);
2329 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, minus_zero));
2330 check ("real(catanh(-0 - i0)) = -0", __real__ result, minus_zero);
2331 check ("imag(catanh(-0 - i0)) = -0", __imag__ result, minus_zero);
2333 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, plus_infty));
2334 check ("real(catanh(+Inf + i Inf)) = 0", __real__ result, 0);
2335 check ("imag(catanh(+Inf + i Inf)) = pi/2", __imag__ result, M_PI_2);
2336 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_infty));
2337 check ("real(catanh(+Inf - i Inf)) = 0", __real__ result, 0);
2338 check ("imag(catanh(+Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2339 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, plus_infty));
2340 check ("real(catanh(-Inf + i Inf)) = -0", __real__ result, minus_zero);
2341 check ("imag(catanh(-Inf + i Inf)) = pi/2", __imag__ result, M_PI_2);
2342 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_infty));
2343 check ("real(catanh(-Inf - i Inf)) = -0", __real__ result, minus_zero);
2344 check ("imag(catanh(-Inf - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2346 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, plus_infty));
2347 check ("real(catanh(-10.0 + i Inf)) = -0", __real__ result, -minus_zero);
2348 check ("imag(catanh(-10.0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2349 result = FUNC(catanh) (BUILD_COMPLEX (-10.0, minus_infty));
2350 check ("real(catanh(-10.0 - i Inf)) = -0", __real__ result, minus_infty);
2351 check ("imag(catanh(-10.0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2352 result = FUNC(catanh) (BUILD_COMPLEX (0, plus_infty));
2353 check ("real(catanh(0 + i Inf)) = 0", __real__ result, 0);
2354 check ("imag(catanh(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2355 result = FUNC(catanh) (BUILD_COMPLEX (0, minus_infty));
2356 check ("real(catanh(0 - i Inf)) = 0", __real__ result, 0);
2357 check ("imag(catanh(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2358 result = FUNC(catanh) (BUILD_COMPLEX (0.1, plus_infty));
2359 check ("real(catanh(0.1 + i Inf)) = 0", __real__ result, 0);
2360 check ("imag(catanh(0.1 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2361 result = FUNC(catanh) (BUILD_COMPLEX (0.1, minus_infty));
2362 check ("real(catanh(0.1 - i Inf)) = 0", __real__ result, 0);
2363 check ("imag(catanh(0.1 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2365 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 0));
2366 check ("real(catanh(-Inf + i0)) = -0", __real__ result, minus_zero);
2367 check ("imag(catanh(-Inf + i0)) = pi/2", __imag__ result, M_PI_2);
2368 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, minus_zero));
2369 check ("real(catanh(-Inf - i0)) = -0", __real__ result, minus_zero);
2370 check ("imag(catanh(-Inf - i0)) = -pi/2", __imag__ result, -M_PI_2);
2371 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, 100));
2372 check ("real(catanh(-Inf + i100)) = -0", __real__ result, minus_zero);
2373 check ("imag(catanh(-Inf + i100)) = pi/2", __imag__ result, M_PI_2);
2374 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, -100));
2375 check ("real(catanh(-Inf - i100)) = -0", __real__ result, minus_zero);
2376 check ("imag(catanh(-Inf - i100)) = -pi/2", __imag__ result, -M_PI_2);
2378 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0));
2379 check ("real(catanh(+Inf + i0)) = 0", __real__ result, 0);
2380 check ("imag(catanh(+Inf + i0)) = pi/2", __imag__ result, M_PI_2);
2381 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, minus_zero));
2382 check ("real(catanh(+Inf - i0)) = 0", __real__ result, 0);
2383 check ("imag(catanh(+Inf - i0)) = -pi/2", __imag__ result, -M_PI_2);
2384 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, 0.5));
2385 check ("real(catanh(+Inf + i0.5)) = 0", __real__ result, 0);
2386 check ("imag(catanh(+Inf + i0.5)) = pi/2", __imag__ result, M_PI_2);
2387 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, -0.5));
2388 check ("real(catanh(+Inf - i0.5)) = 0", __real__ result, 0);
2389 check ("imag(catanh(+Inf - i0.5)) = -pi/2", __imag__ result, -M_PI_2);
2391 result = FUNC(catanh) (BUILD_COMPLEX (0, nan_value));
2392 check ("real(catanh(0 + i NaN)) = 0", __real__ result, 0);
2393 check_isnan ("imag(catanh(+Inf + i NaN)) = NaN", __imag__ result);
2394 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, nan_value));
2395 check ("real(catanh(-0 + i NaN)) = -0", __real__ result, minus_zero);
2396 check_isnan ("imag(catanh(-Inf + i NaN)) = NaN", __imag__ result);
2398 result = FUNC(catanh) (BUILD_COMPLEX (plus_infty, nan_value));
2399 check ("real(catanh(+Inf + i NaN)) = 0", __real__ result, 0);
2400 check_isnan ("imag(catanh(+Inf + i NaN)) = NaN", __imag__ result);
2401 result = FUNC(catanh) (BUILD_COMPLEX (minus_infty, nan_value));
2402 check ("real(catanh(-Inf + i NaN)) = -0", __real__ result, minus_zero);
2403 check_isnan ("imag(catanh(-Inf + i NaN)) = NaN", __imag__ result);
2405 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0));
2406 check_isnan ("real(catanh(NaN + i0)) = NaN", __real__ result);
2407 check_isnan ("imag(catanh(NaN + i0)) = NaN", __imag__ resul);
2408 result = FUNC(catanh) (BUILD_COMPLEX (minus_zero, nan_value));
2409 check_isnan ("real(catanh(NaN - i0)) = NaN", __real__ result);
2410 check_isnan ("imag(catanh(NaN - i0)) = NaN", __imag__ result);
2412 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, plus_infty));
2413 check ("real(catanh(NaN + i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
2414 check ("imag(catanh(NaN + i Inf)) = pi/2", __imag__ result, M_PI_2);
2415 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, minus_infty));
2416 check ("real(catanh(NaN - i Inf)) = +-0", FUNC(fabs) (__real__ result), 0);
2417 check ("imag(catanh(NaN - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2419 result = FUNC(catanh) (BUILD_COMPLEX (10.5, nan_value));
2420 check_isnan ("real(catanh(10.5 + i NaN)) = NaN", __real__ result);
2421 check_isnan ("imag(catanh(10.5 + i NaN)) = NaN", __imag__ result);
2422 result = FUNC(catanh) (BUILD_COMPLEX (-10.5, nan_value));
2423 check_isnan ("real(catanh(-10.5 + i NaN)) = NaN", __real__ result);
2424 check_isnan ("imag(catanh(-10.5 + i NaN)) = NaN", __imag__ result);
2426 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, 0.75));
2427 check_isnan ("real(catanh(NaN + i0.75)) = NaN", __real__ result);
2428 check_isnan ("imag(catanh(NaN + i0.75)) = NaN", __imag__ result);
2429 result = FUNC(catanh) (BUILD_COMPLEX (-10.5, nan_value));
2430 check_isnan ("real(catanh(NaN - i0.75)) = NaN", __real__ result);
2431 check_isnan ("imag(catanh(NaN - i0.75)) = NaN", __imag__ result);
2433 result = FUNC(catanh) (BUILD_COMPLEX (nan_value, nan_value));
2434 check_isnan ("real(catanh(NaN + i NaN)) = NaN", __real__ result);
2435 check_isnan ("imag(catanh(NaN + i NaN)) = NaN", __imag__ result);
2439 static void
2440 ctanh_test (void)
2442 __complex__ MATHTYPE result;
2444 result = FUNC(ctanh) (BUILD_COMPLEX (0, 0));
2445 check ("real(ctanh(0 + i0)) = 0", __real__ result, 0);
2446 check ("imag(ctanh(0 + i0)) = 0", __imag__ result, 0);
2447 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_zero));
2448 check ("real(ctanh(0 - i0)) = 0", __real__ result, 0);
2449 check ("imag(ctanh(0 - i0)) = -0", __imag__ result, minus_zero);
2450 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, 0));
2451 check ("real(ctanh(-0 + i0)) = -0", __real__ result, minus_zero);
2452 check ("imag(ctanh(-0 + i0)) = -0", __imag__ result, 0);
2453 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_zero));
2454 check ("real(ctanh(-0 - i0)) = -0", __real__ result, minus_zero);
2455 check ("imag(ctanh(-0 - i0)) = -0", __imag__ result, minus_zero);
2457 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 0));
2458 check ("real(ctanh(+Inf + i0)) = 1", __real__ result, 1);
2459 check ("imag(ctanh(+Inf + i0)) = 0", __imag__ result, 0);
2460 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, 1));
2461 check ("real(ctanh(+Inf + i1)) = 1", __real__ result, 1);
2462 check ("imag(ctanh(+Inf + i1)) = 0", __imag__ result, 0);
2463 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, minus_zero));
2464 check ("real(ctanh(+Inf - i0)) = 1", __real__ result, 1);
2465 check ("imag(ctanh(+Inf - i0)) = -0", __imag__ result, minus_zero);
2466 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, -1));
2467 check ("real(ctanh(+Inf - i1)) = 1", __real__ result, 1);
2468 check ("imag(ctanh(+Inf - i1)) = -0", __imag__ result, minus_zero);
2469 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 0));
2470 check ("real(ctanh(-Inf + i0)) = -1", __real__ result, -1);
2471 check ("imag(ctanh(-Inf + i0)) = 0", __imag__ result, 0);
2472 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, 1));
2473 check ("real(ctanh(-Inf + i1)) = -1", __real__ result, -1);
2474 check ("imag(ctanh(-Inf + i1)) = 0", __imag__ result, 0);
2475 result = FUNC(ctanh) (BUILD_COMPLEX (pminus_infty, minus_zero));
2476 check ("real(ctanh(-Inf - i0)) = -1", __real__ result, -1);
2477 check ("imag(ctanh(-Inf - i0)) = -0", __imag__ result, minus_zero);
2478 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, -1));
2479 check ("real(ctanh(-Inf - i1)) = -1", __real__ result, -1);
2480 check ("imag(ctanh(-Inf - i1)) = -0", __imag__ result, minus_zero);
2482 result = FUNC(ctanh) (BUILD_COMPLEX (0, plus_infty));
2483 check_isnan ("real(ctanh(0 + i Inf)) = NaN", __real__ result);
2484 check_isnan ("imag(ctanh(0 + i Inf)) = NaN", __imag__ result);
2485 result = FUNC(ctanh) (BUILD_COMPLEX (2, plus_infty));
2486 check_isnan ("real(ctanh(2 + i Inf)) = NaN", __real__ result);
2487 check_isnan ("imag(ctanh(2 + i Inf)) = NaN", __imag__ result);
2488 result = FUNC(ctanh) (BUILD_COMPLEX (0, minus_infty));
2489 check_isnan ("real(ctanh(0 - i Inf)) = NaN", __real__ result);
2490 check_isnan ("imag(ctanh(0 - i Inf)) = NaN", __imag__ result);
2491 result = FUNC(ctanh) (BUILD_COMPLEX (2, minus_infty));
2492 check_isnan ("real(ctanh(2 - i Inf)) = NaN", __real__ result);
2493 check_isnan ("imag(ctanh(2 - i Inf)) = NaN", __imag__ result);
2494 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, plus_infty));
2495 check_isnan ("real(ctanh(-0 + i Inf)) = NaN", __real__ result);
2496 check_isnan ("imag(ctanh(-0 + i Inf)) = NaN", __imag__ result);
2497 result = FUNC(ctanh) (BUILD_COMPLEX (-2, plus_infty));
2498 check_isnan ("real(ctanh(-2 + i Inf)) = NaN", __real__ result);
2499 check_isnan ("imag(ctanh(-2 + i Inf)) = NaN", __imag__ result);
2500 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, minus_infty));
2501 check_isnan ("real(ctanh(-0 - i Inf)) = NaN", __real__ result);
2502 check_isnan ("imag(ctanh(-0 - i Inf)) = NaN", __imag__ result);
2503 result = FUNC(ctanh) (BUILD_COMPLEX (-2, minus_infty));
2504 check_isnan ("real(ctanh(-2 - i Inf)) = NaN", __real__ result);
2505 check_isnan ("imag(ctanh(-2 - i Inf)) = NaN", __imag__ result);
2507 result = FUNC(ctanh) (BUILD_COMPLEX (plus_infty, nan_value));
2508 check ("real(ctanh(+Inf + i NaN)) = 1", __real__ result, 1);
2509 check ("imag(ctanh(+Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
2510 result = FUNC(ctanh) (BUILD_COMPLEX (minus_infty, nan_value));
2511 check ("real(ctanh(-Inf + i NaN)) = -1", __real__ result, -1);
2512 check ("imag(ctanh(-Inf + i NaN)) = +-0", FUNC(fabs) (__imag__ result), 0);
2514 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0));
2515 check_isnan ("real(ctanh(NaN + i0)) = NaN", __real__ result);
2516 check ("imag(ctanh(NaN + i0)) = 0", __imag__ result, 0);
2517 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, minus_infty));
2518 check_isnan ("real(ctanh(NaN - i0)) = NaN", __real__ result);
2519 check ("imag(ctanh(NaN - i0)) = -0", __imag__ result, minus_infty);
2521 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, 0.5));
2522 check_isnan ("real(ctanh(NaN + i0.5)) = NaN", __real__ result);
2523 check_isnan ("imag(ctanh(NaN + i0.5)) = NaN", __imag__ result);
2524 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, -4.5));
2525 check_isnan ("real(ctanh(NaN - i4.5)) = NaN", __real__ result);
2526 check_isnan ("imag(ctanh(NaN - i4.5)) = NaN", __imag__ result);
2528 result = FUNC(ctanh) (BUILD_COMPLEX (0, nan_value));
2529 check_isnan ("real(ctanh(0 + i NaN)) = NaN", __real__ result);
2530 check_isnan ("imag(ctanh(0 + i NaN)) = NaN", __imag__ result);
2531 result = FUNC(ctanh) (BUILD_COMPLEX (5, nan_value));
2532 check_isnan ("real(ctanh(5 + i NaN)) = NaN", __real__ result);
2533 check_isnan ("imag(ctanh(5 + i NaN)) = NaN", __imag__ result);
2534 result = FUNC(ctanh) (BUILD_COMPLEX (minus_zero, nan_value));
2535 check_isnan ("real(ctanh(-0 + i NaN)) = NaN", __real__ result);
2536 check_isnan ("imag(ctanh(-0 + i NaN)) = NaN", __imag__ result);
2537 result = FUNC(ctanh) (BUILD_COMPLEX (-0.25, nan_value));
2538 check_isnan ("real(ctanh(-0.25 + i NaN)) = NaN", __real__ result);
2539 check_isnan ("imag(ctanh(-0.25 + i NaN)) = NaN", __imag__ result);
2541 result = FUNC(ctanh) (BUILD_COMPLEX (nan_value, nan_value));
2542 check_isnan ("real(ctanh(NaN + i NaN)) = NaN", __real__ result);
2543 check_isnan ("imag(ctanh(NaN + i NaN)) = NaN", __imag__ result);
2545 #endif
2548 static void
2549 clog_test (void)
2551 __complex__ MATHTYPE result;
2553 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, 0));
2554 check_isinfn ("real(clog(-0 + i0)) = -Inf", __real__ result);
2555 check ("imag(clog(-0 + i0)) = pi", __imag__ result, M_PI);
2556 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_zero));
2557 check_isinfn ("real(clog(-0 - i0)) = -Inf", __real__ result);
2558 check ("imag(clog(-0 - i0)) = -pi", __imag__ result, -M_PI);
2560 result = FUNC(clog) (BUILD_COMPLEX (0, 0));
2561 check_isinfn ("real(clog(0 + i0)) = -Inf", __real__ result);
2562 check ("imag(clog(0 + i0)) = 0", __imag__ result, 0);
2563 result = FUNC(clog) (BUILD_COMPLEX (0, minus_zero));
2564 check_isinfn ("real(clog(0 - i0)) = -Inf", __real__ result);
2565 check ("imag(clog(0 - i0)) = -0", __imag__ result, minus_zero);
2567 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, plus_infty));
2568 check_isinfp ("real(clog(-Inf + i Inf)) = +Inf", __real__ result);
2569 check ("imag(clog(-Inf + i Inf)) = 3*pi/4", __imag__ result, M_PI - M_PI_4);
2570 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_infty));
2571 check_isinfp ("real(clog(-Inf - i Inf)) = +Inf", __real__ result);
2572 check ("imag(clog(-Inf - i Inf)) = -3*pi/4", __imag__ result, M_PI_4 - M_PI);
2574 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, plus_infty));
2575 check_isinfp ("real(clog(+Inf + i Inf)) = +Inf", __real__ result);
2576 check ("imag(clog(+Inf + i Inf)) = pi/4", __imag__ result, M_PI_4);
2577 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_infty));
2578 check_isinfp ("real(clog(+Inf - i Inf)) = +Inf", __real__ result);
2579 check ("imag(clog(+Inf - i Inf)) = -pi/4", __imag__ result, -M_PI_4);
2581 result = FUNC(clog) (BUILD_COMPLEX (0, plus_infty));
2582 check_isinfp ("real(clog(0 + i Inf)) = +Inf", __real__ result);
2583 check ("imag(clog(0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2584 result = FUNC(clog) (BUILD_COMPLEX (3, plus_infty));
2585 check_isinfp ("real(clog(3 + i Inf)) = +Inf", __real__ result);
2586 check ("imag(clog(3 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2587 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, plus_infty));
2588 check_isinfp ("real(clog(-0 + i Inf)) = +Inf", __real__ result);
2589 check ("imag(clog(-0 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2590 result = FUNC(clog) (BUILD_COMPLEX (-3, plus_infty));
2591 check_isinfp ("real(clog(-3 + i Inf)) = +Inf", __real__ result);
2592 check ("imag(clog(-3 + i Inf)) = pi/2", __imag__ result, M_PI_2);
2593 result = FUNC(clog) (BUILD_COMPLEX (0, minus_infty));
2594 check_isinfp ("real(clog(0 - i Inf)) = +Inf", __real__ result);
2595 check ("imag(clog(0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2596 result = FUNC(clog) (BUILD_COMPLEX (3, minus_infty));
2597 check_isinfp ("real(clog(3 - i Inf)) = +Inf", __real__ result);
2598 check ("imag(clog(3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2599 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, minus_infty));
2600 check_isinfp ("real(clog(-0 - i Inf)) = +Inf", __real__ result);
2601 check ("imag(clog(-0 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2602 result = FUNC(clog) (BUILD_COMPLEX (-3, minus_infty));
2603 check_isinfp ("real(clog(-3 - i Inf)) = +Inf", __real__ result);
2604 check ("imag(clog(-3 - i Inf)) = -pi/2", __imag__ result, -M_PI_2);
2606 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 0));
2607 check_isinfp ("real(clog(-Inf + i0)) = +Inf", __real__ result);
2608 check ("imag(clog(-Inf + i0)) = pi", __imag__ result, M_PI);
2609 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, 1));
2610 check_isinfp ("real(clog(-Inf + i1)) = +Inf", __real__ result);
2611 check ("imag(clog(-Inf + i1)) = pi", __imag__ result, M_PI);
2612 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, minus_zero));
2613 check_isinfp ("real(clog(-Inf - i0)) = +Inf", __real__ result);
2614 check ("imag(clog(-Inf - i0)) = -pi", __imag__ result, -M_PI);
2615 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, -1));
2616 check_isinfp ("real(clog(-Inf - i1)) = +Inf", __real__ result);
2617 check ("imag(clog(-Inf - i1)) = -pi", __imag__ result, -M_PI);
2619 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 0));
2620 check_isinfp ("real(clog(+Inf + i0)) = +Inf", __real__ result);
2621 check ("imag(clog(+Inf + i0)) = 0", __imag__ result, 0);
2622 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, 1));
2623 check_isinfp ("real(clog(+Inf + i1)) = +Inf", __real__ result);
2624 check ("imag(clog(+Inf + i1)) = 0", __imag__ result, 0);
2625 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, minus_zero));
2626 check_isinfp ("real(clog(+Inf - i0)) = +Inf", __real__ result);
2627 check ("imag(clog(+Inf - i0)) = -0", __imag__ result, minus_zero);
2628 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, -1));
2629 check_isinfp ("real(clog(+Inf - i1)) = +Inf", __real__ result);
2630 check ("imag(clog(+Inf - i1)) = -0", __imag__ result, minus_zero);
2632 result = FUNC(clog) (BUILD_COMPLEX (plus_infty, nan_value));
2633 check_isinfp ("real(clog(+Inf + i NaN)) = +Inf", __real__ result);
2634 check_isnan ("imag(clog(+Inf + i NaN)) = NaN", __imag__ result);
2635 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, nan_value));
2636 check_isinfp ("real(clog(-Inf + i NaN)) = +Inf", __real__ result);
2637 check_isnan ("imag(clog(-Inf + i NaN)) = NaN", __imag__ result);
2639 result = FUNC(clog) (BUILD_COMPLEX (nan_value, plus_infty));
2640 check_isinfp ("real(clog(NaN + i Inf)) = +Inf", __real__ result);
2641 check_isnan ("imag(clog(NaN + i Inf)) = NaN", __imag__ result);
2642 result = FUNC(clog) (BUILD_COMPLEX (minus_infty, nan_value));
2643 check_isinfp ("real(clog(NaN - i Inf)) = +Inf", __real__ result);
2644 check_isnan ("imag(clog(NaN - i Inf)) = NaN", __imag__ result);
2646 result = FUNC(clog) (BUILD_COMPLEX (0, nan_value));
2647 check_isnan ("real(clog(0 + i NaN)) = NaN", __real__ result);
2648 check_isnan ("imag(clog(0 + i NaN)) = NaN", __imag__ result);
2649 result = FUNC(clog) (BUILD_COMPLEX (3, nan_value));
2650 check_isnan ("real(clog(3 + i NaN)) = NaN", __real__ result);
2651 check_isnan ("imag(clog(3 + i NaN)) = NaN", __imag__ result);
2652 result = FUNC(clog) (BUILD_COMPLEX (minus_zero, nan_value));
2653 check_isnan ("real(clog(-0 + i NaN)) = NaN", __real__ result);
2654 check_isnan ("imag(clog(-0 + i NaN)) = NaN", __imag__ result);
2655 result = FUNC(clog) (BUILD_COMPLEX (-3, nan_value));
2656 check_isnan ("real(clog(-3 + i NaN)) = NaN", __real__ result);
2657 check_isnan ("imag(clog(-3 + i NaN)) = NaN", __imag__ result);
2659 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 0));
2660 check_isnan ("real(clog(NaN + i0)) = NaN", __real__ result);
2661 check_isnan ("imag(clog(NaN + i0)) = NaN", __imag__ result);
2662 result = FUNC(clog) (BUILD_COMPLEX (nan_value, 5));
2663 check_isnan ("real(clog(NaN + i5)) = NaN", __real__ result);
2664 check_isnan ("imag(clog(NaN + i5)) = NaN", __imag__ result);
2665 result = FUNC(clog) (BUILD_COMPLEX (nan_value, minus_zero));
2666 check_isnan ("real(clog(NaN - i0)) = NaN", __real__ result);
2667 check_isnan ("imag(clog(NaN - i0)) = NaN", __imag__ result);
2668 result = FUNC(clog) (BUILD_COMPLEX (nan_value, -5));
2669 check_isnan ("real(clog(NaN - i5)) = NaN", __real__ result);
2670 check_isnan ("imag(clog(NaN - i5)) = NaN", __imag__ result);
2672 result = FUNC(clog) (BUILD_COMPLEX (nan_value, nan_value));
2673 check_isnan ("real(clog(NaN + i NaN)) = NaN", __real__ result);
2674 check_isnan ("imag(clog(NaN + i NaN)) = NaN", __imag__ result);
2678 #if 0
2679 static void
2680 csqrt_test (void)
2682 __complex__ MATHTYPE result;
2684 result = FUNC(csqrt) (BUILD_COMPLEX (0, 0));
2685 check ("real(csqrt(0 + i0)) = 0", __real__ result, 0);
2686 check ("imag(csqrt(0 + i0)) = 0", __imag__ result, 0);
2687 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_zero));
2688 check ("real(csqrt(0 - i0)) = 0", __real__ result, 0);
2689 check ("imag(csqrt(0 - i0)) = -0", __imag__ result, minus_zero);
2690 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, 0));
2691 check ("real(csqrt(-0 + i0)) = 0", __real__ result, 0);
2692 check ("imag(csqrt(-0 + i0)) = 0", __imag__ result, 0);
2693 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_zero));
2694 check ("real(csqrt(-0 - i0)) = 0", __real__ result, 0);
2695 check ("imag(csqrt(-0 - i0)) = -0", __imag__ result, minus_zero);
2697 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 0));
2698 check ("real(csqrt(-Inf + i0)) = 0", __real__ result, 0);
2699 check_isinfp ("imag(csqrt(-Inf + i0)) = +Inf", __imag__ result);
2700 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, 6));
2701 check ("real(csqrt(-Inf + i6)) = 0", __real__ result, 0);
2702 check_isinfp ("imag(csqrt(-Inf + i6)) = +Inf", __imag__ result);
2703 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_zero));
2704 check ("real(csqrt(-Inf - i0)) = 0", __real__ result, 0);
2705 check_isinfn ("imag(csqrt(-Inf - i0)) = -Inf", __imag__ result);
2706 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, -6));
2707 check ("real(csqrt(-Inf - i6)) = 0", __real__ result, 0);
2708 check_isinfn ("imag(csqrt(-Inf - i6)) = -Inf", __imag__ result);
2710 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 0));
2711 check_isinfp ("real(csqrt(+Inf + i0)) = +Inf", __real__ result);
2712 check ("imag(csqrt(-Inf + i0)) = 0", __imag__ result, 0);
2713 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, 6));
2714 check_isinfp ("real(csqrt(+Inf + i6)) = +Inf", __real__ result);
2715 check ("imag(csqrt(-Inf + i6)) = 0", __imag__ result, 0);
2716 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_zero));
2717 check_isinfp ("real(csqrt(+Inf - i0)) = +Inf", __real__ result);
2718 check ("imag(csqrt(-Inf - i0)) = -0", __imag__ result, minus_zero);
2719 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, -6));
2720 check_isinfp ("real(csqrt(+Inf - i6)) = +Inf", __real__ result);
2721 check ("imag(csqrt(-Inf - i6)) = -0", __imag__ result, minus_zero);
2723 result = FUNC(csqrt) (BUILD_COMPLEX (0, plus_infty));
2724 check_isinfp ("real(csqrt(0 + i Inf)) = +Inf", __real__ result);
2725 check_isinfp ("imag(csqrt(0 + i Inf)) = +Inf", __imag__ result);
2726 result = FUNC(csqrt) (BUILD_COMPLEX (4, plus_infty));
2727 check_isinfp ("real(csqrt(4 + i Inf)) = +Inf", __real__ result);
2728 check_isinfp ("imag(csqrt(4 + i Inf)) = +Inf", __imag__ result);
2729 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, plus_infty));
2730 check_isinfp ("real(csqrt(+Inf + i Inf)) = +Inf", __real__ result);
2731 check_isinfp ("imag(csqrt(+Inf + i Inf)) = +Inf", __imag__ result);
2732 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, plus_infty));
2733 check_isinfp ("real(csqrt(-0 + i Inf)) = +Inf", __real__ result);
2734 check_isinfp ("imag(csqrt(-0 + i Inf)) = +Inf", __imag__ result);
2735 result = FUNC(csqrt) (BUILD_COMPLEX (-4, plus_infty));
2736 check_isinfp ("real(csqrt(-4 + i Inf)) = +Inf", __real__ result);
2737 check_isinfp ("imag(csqrt(-4 + i Inf)) = +Inf", __imag__ result);
2738 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, plus_infty));
2739 check_isinfp ("real(csqrt(-Inf + i Inf)) = +Inf", __real__ result);
2740 check_isinfp ("imag(csqrt(-Inf + i Inf)) = +Inf", __imag__ result);
2741 result = FUNC(csqrt) (BUILD_COMPLEX (0, minus_infty));
2742 check_isinfp ("real(csqrt(0 - i Inf)) = +Inf", __real__ result);
2743 check_isinfn ("imag(csqrt(0 - i Inf)) = -Inf", __imag__ result);
2744 result = FUNC(csqrt) (BUILD_COMPLEX (4, minus_infty));
2745 check_isinfp ("real(csqrt(4 - i Inf)) = +Inf", __real__ result);
2746 check_isinfn ("imag(csqrt(4 - i Inf)) = -Inf", __imag__ result);
2747 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, minus_infty));
2748 check_isinfp ("real(csqrt(+Inf - i Inf)) = +Inf", __real__ result);
2749 check_isinfn ("imag(csqrt(+Inf - i Inf)) = -Inf", __imag__ result);
2750 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, minus_infty));
2751 check_isinfp ("real(csqrt(-0 - i Inf)) = +Inf", __real__ result);
2752 check_isinfn ("imag(csqrt(-0 - i Inf)) = -Inf", __imag__ result);
2753 result = FUNC(csqrt) (BUILD_COMPLEX (-4, minus_infty));
2754 check_isinfp ("real(csqrt(-4 - i Inf)) = +Inf", __real__ result);
2755 check_isinfn ("imag(csqrt(-4 - i Inf)) = -Inf", __imag__ result);
2756 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, minus_infty));
2757 check_isinfp ("real(csqrt(-Inf - i Inf)) = +Inf", __real__ result);
2758 check_isinfn ("imag(csqrt(-Inf - i Inf)) = -Inf", __imag__ result);
2760 result = FUNC(csqrt) (BUILD_COMPLEX (minus_infty, nan_value));
2761 check_isnan ("real(csqrt(-Inf + i NaN)) = NaN", __real__ result);
2762 check_isinfp ("imag(csqrt(-Inf + i NaN)) = +-Inf",
2763 FUNC(fabs) (__imag__ result));
2765 result = FUNC(csqrt) (BUILD_COMPLEX (plus_infty, nan_value));
2766 check_isinfp ("real(csqrt(+Inf + i NaN)) = +Inf", __real__ result);
2767 check_isnan ("imag(csqrt(+Inf + i NaN)) = NaN", __imag__ result);
2769 result = FUNC(csqrt) (BUILD_COMPLEX (0, nan_value));
2770 check_isnan ("real(csqrt(0 + i NaN)) = NaN", __real__ result);
2771 check_isnan ("imag(csqrt(0 + i NaN)) = NaN", __imag__ result);
2772 result = FUNC(csqrt) (BUILD_COMPLEX (1, nan_value));
2773 check_isnan ("real(csqrt(1 + i NaN)) = NaN", __real__ result);
2774 check_isnan ("imag(csqrt(1 + i NaN)) = NaN", __imag__ result);
2775 result = FUNC(csqrt) (BUILD_COMPLEX (minus_zero, nan_value));
2776 check_isnan ("real(csqrt(-0 + i NaN)) = NaN", __real__ result);
2777 check_isnan ("imag(csqrt(-0 + i NaN)) = NaN", __imag__ result);
2778 result = FUNC(csqrt) (BUILD_COMPLEX (-1, nan_value));
2779 check_isnan ("real(csqrt(-1 + i NaN)) = NaN", __real__ result);
2780 check_isnan ("imag(csqrt(-1 + i NaN)) = NaN", __imag__ result);
2782 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 0));
2783 check_isnan ("real(csqrt(NaN + i0)) = NaN", __real__ result);
2784 check_isnan ("imag(csqrt(NaN + i0)) = NaN", __imag__ result);
2785 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, 8));
2786 check_isnan ("real(csqrt(NaN + i8)) = NaN", __real__ result);
2787 check_isnan ("imag(csqrt(NaN + i8)) = NaN", __imag__ result);
2788 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, minus_zero));
2789 check_isnan ("real(csqrt(NaN - i0)) = NaN", __real__ result);
2790 check_isnan ("imag(csqrt(NaN - i0)) = NaN", __imag__ result);
2791 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, -8));
2792 check_isnan ("real(csqrt(NaN - i8)) = NaN", __real__ result);
2793 check_isnan ("imag(csqrt(NaN - i8)) = NaN", __imag__ result);
2795 result = FUNC(csqrt) (BUILD_COMPLEX (nan_value, nan_value));
2796 check_isnan ("real(csqrt(NaN + i NaN)) = NaN", __real__ result);
2797 check_isnan ("imag(csqrt(NaN + i NaN)) = NaN", __imag__ result);
2799 #endif
2802 static void
2803 rinttol_test (void)
2805 /* XXX this test is incomplete. We need to have a way to specifiy
2806 the rounding method and test the critical cases. So far, only
2807 unproblematic numbers are tested. */
2809 check_long ("rinttol(0) = 0", 0.0, 0);
2810 check_long ("rinttol(-0) = 0", minus_zero, 0);
2811 check_long ("rinttol(0.2) = 0", 0.2, 0);
2812 check_long ("rinttol(-0.2) = 0", -0.2, 0);
2814 check_long ("rinttol(1.4) = 1", 1.4, 1);
2815 check_long ("rinttol(-1.4) = -1", -1.4, -1);
2817 check_long ("rinttol(8388600.3) = 8388600", 8388600.3, 8388600);
2818 check_long ("rinttol(-8388600.3) = -8388600", -8388600.3, -8388600);
2822 static void
2823 rinttoll_test (void)
2825 /* XXX this test is incomplete. We need to have a way to specifiy
2826 the rounding method and test the critical cases. So far, only
2827 unproblematic numbers are tested. */
2829 check_longlong ("rinttoll(0) = 0", 0.0, 0);
2830 check_longlong ("rinttoll(-0) = 0", minus_zero, 0);
2831 check_longlong ("rinttoll(0.2) = 0", 0.2, 0);
2832 check_longlong ("rinttoll(-0.2) = 0", -0.2, 0);
2834 check_longlong ("rinttoll(1.4) = 1", 1.4, 1);
2835 check_longlong ("rinttoll(-1.4) = -1", -1.4, -1);
2837 check_longlong ("rinttoll(8388600.3) = 8388600", 8388600.3, 8388600);
2838 check_longlong ("rinttoll(-8388600.3) = -8388600", -8388600.3, -8388600);
2842 static void
2843 inverse_func_pair_test (const char *test_name,
2844 mathfunc f1, mathfunc inverse,
2845 MATHTYPE x, MATHTYPE epsilon)
2847 MATHTYPE a, b, difference;
2848 int result;
2850 a = f1 (x);
2851 (void) &a;
2852 b = inverse (a);
2853 (void) &b;
2855 result = check_equal (b, x, epsilon, &difference);
2856 output_result (test_name, result,
2857 b, x, difference, PRINT, PRINT);
2861 static void
2862 inverse_functions (void)
2864 inverse_func_pair_test ("asin(sin(x)) == x",
2865 FUNC(sin), FUNC(asin), 1.0, CHOOSE (2e-18L, 0, 1e-7L));
2866 inverse_func_pair_test ("sin(asin(x)) == x",
2867 FUNC(asin), FUNC(sin), 1.0, 0.0);
2869 inverse_func_pair_test ("acos(cos(x)) == x",
2870 FUNC(cos), FUNC(acos), 1.0, CHOOSE (4e-18L, 1e-15L, 0));
2871 inverse_func_pair_test ("cos(acos(x)) == x",
2872 FUNC(acos), FUNC(cos), 1.0, 0.0);
2873 inverse_func_pair_test ("atan(tan(x)) == x",
2874 FUNC(tan), FUNC(atan), 1.0, CHOOSE (2e-18L, 0, 0));
2875 inverse_func_pair_test ("tan(atan(x)) == x",
2876 FUNC(atan), FUNC(tan), 1.0, CHOOSE (2e-18L, 1e-15L, 0));
2878 inverse_func_pair_test ("asinh(sinh(x)) == x",
2879 FUNC(sinh), FUNC(asinh), 1.0, CHOOSE (1e-18L, 0, 1e-7));
2880 inverse_func_pair_test ("sinh(asinh(x)) == x",
2881 FUNC(asinh), FUNC(sinh), 1.0, CHOOSE (2e-18L, 0, 0));
2883 inverse_func_pair_test ("acosh(cosh(x)) == x",
2884 FUNC(cosh), FUNC(acosh), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
2885 inverse_func_pair_test ("cosh(acosh(x)) == x",
2886 FUNC(acosh), FUNC(cosh), 1.0, 0.0);
2888 inverse_func_pair_test ("atanh(tanh(x)) == x",
2889 FUNC(tanh), FUNC(atanh), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
2890 inverse_func_pair_test ("tanh(atanh(x)) == x",
2891 FUNC(atanh), FUNC(tanh), 1.0, 0.0);
2895 /* Test sin and cos with the identity: sin(x)^2 + cos(x)^2 = 1. */
2896 static void
2897 identities1_test (MATHTYPE x, MATHTYPE epsilon)
2899 MATHTYPE res1, res2, res3, diff;
2900 int result;
2902 res1 = FUNC(sin) (x);
2903 (void) &res1;
2904 res2 = FUNC(cos) (x);
2905 (void) &res2;
2906 res3 = res1 * res1 + res2 * res2;
2907 (void) &res3;
2909 result = check_equal (res3, 1.0, epsilon, &diff);
2910 output_result_ext ("sin^2 + cos^2 == 1", result,
2911 res3, 1.0, diff, x, PRINT, PRINT);
2915 /* Test sin, cos, tan with the following relation: tan = sin/cos. */
2916 static void
2917 identities2_test (MATHTYPE x, MATHTYPE epsilon)
2919 MATHTYPE res1, res2, res3, res4, diff;
2920 int result;
2922 res1 = FUNC(sin) (x);
2923 (void) &res1;
2924 res2 = FUNC(cos) (x);
2925 (void) &res2;
2926 res3 = FUNC(tan) (x);
2927 (void) &res3;
2928 res4 = res1 / res2;
2929 (void) &res4;
2931 result = check_equal (res4, res3, epsilon, &diff);
2932 output_result_ext ("sin/cos == tan", result,
2933 res4, res3, diff, x, PRINT, PRINT);
2937 /* Test cosh and sinh with the identity cosh^2 - sinh^2 = 1. */
2938 static void
2939 identities3_test (MATHTYPE x, MATHTYPE epsilon)
2941 MATHTYPE res1, res2, res3, diff;
2942 int result;
2944 res1 = FUNC(sinh) (x);
2945 (void) &res1;
2946 res2 = FUNC(cosh) (x);
2947 (void) &res2;
2948 res3 = res2 * res2 - res1 * res1;
2949 (void) &res3;
2951 result = check_equal (res3, 1.0, epsilon, &diff);
2952 output_result_ext ("cosh^2 - sinh^2 == 1", result,
2953 res3, 1.0, diff, x, PRINT, PRINT);
2957 static void
2958 identities (void)
2960 identities1_test (0.2L, CHOOSE (1e-18L, 0, 2e-7));
2961 identities1_test (0.9L, CHOOSE (1e-18L, 0, 0));
2962 identities1_test (0, 0);
2963 identities1_test (-1, CHOOSE (1e-18L, 0, 1e-7));
2965 identities2_test (0.2L, CHOOSE (0, 1e-16, 0));
2966 identities2_test (0.9L, CHOOSE (0, 1e-15, 0));
2967 identities2_test (0, 0);
2968 identities2_test (-1, CHOOSE (1e-18L, 1e-15, 0));
2970 identities3_test (0.2L, CHOOSE (1e-18L, 0, 1e-7));
2971 identities3_test (0.9L, CHOOSE (1e-18L, 1e-15, 1e-6));
2972 identities3_test (0, CHOOSE (0, 0, 1e-6));
2973 identities3_test (-1, CHOOSE (1e-18L, 0, 1e-6));
2978 Let's test that basic arithmetic is working
2979 tests: Infinity and NaN
2981 static void
2982 basic_tests (void)
2984 /* variables are declared volatile to forbid some compiler
2985 optimizations */
2986 volatile MATHTYPE Inf_var, NaN_var, zero_var, one_var;
2987 MATHTYPE x1, x2;
2989 zero_var = 0.0;
2990 one_var = 1.0;
2991 NaN_var = nan_value;
2992 Inf_var = one_var / zero_var;
2994 (void) &zero_var;
2995 (void) &one_var;
2996 (void) &NaN_var;
2997 (void) &Inf_var;
2999 check_isinfp ("isinf (inf) == +1", Inf_var);
3000 check_isinfn ("isinf (-inf) == -1", -Inf_var);
3001 check_bool ("!isinf (1)", !(FUNC(isinf) (one_var)));
3002 check_bool ("!isinf (NaN)", !(FUNC(isinf) (NaN_var)));
3004 check_isnan ("isnan (NaN)", NaN_var);
3005 check_isnan ("isnan (-NaN)", -NaN_var);
3006 check_bool ("!isnan (1)", !(FUNC(isnan) (one_var)));
3007 check_bool ("!isnan (inf)", !(FUNC(isnan) (Inf_var)));
3009 check_bool ("inf == inf", Inf_var == Inf_var);
3010 check_bool ("-inf == -inf", -Inf_var == -Inf_var);
3011 check_bool ("inf != -inf", Inf_var != -Inf_var);
3012 check_bool ("NaN != NaN", NaN_var != NaN_var);
3015 the same tests but this time with NAN from <nan.h>
3016 NAN is a double const
3018 check_bool ("isnan (NAN)", isnan (NAN));
3019 check_bool ("isnan (-NAN)", isnan (-NAN));
3020 check_bool ("!isinf (NAN)", !(isinf (NAN)));
3021 check_bool ("!isinf (-NAN)", !(isinf (-NAN)));
3022 check_bool ("NAN != NAN", NAN != NAN);
3025 And again with the value returned by the `nan' function.
3027 check_bool ("isnan (NAN)", isnan (FUNC(nan) ("")));
3028 check_bool ("isnan (-NAN)", isnan (-FUNC(nan) ("")));
3029 check_bool ("!isinf (NAN)", !(isinf (FUNC(nan) (""))));
3030 check_bool ("!isinf (-NAN)", !(isinf (-FUNC(nan) (""))));
3031 check_bool ("NAN != NAN", FUNC(nan) ("") != FUNC(nan) (""));
3033 /* test if EPSILON is ok */
3034 x1 = MATHCONST (1.0);
3035 x2 = x1 + CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
3036 check_bool ("1 != 1+EPSILON", x1 != x2);
3038 x1 = MATHCONST (1.0);
3039 x2 = x1 - CHOOSE (LDBL_EPSILON, DBL_EPSILON, FLT_EPSILON);
3040 check_bool ("1 != 1-EPSILON", x1 != x2);
3042 /* test if HUGE_VALx is ok */
3043 x1 = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
3044 check_bool ("isinf (HUGE_VALx) == +1", ISINF (x1) == +1);
3045 x1 = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
3046 check_bool ("isinf (-HUGE_VALx) == -1", ISINF (x1) == -1);
3051 static void
3052 initialize (void)
3054 fpstack_test ("start *init*");
3055 plus_zero = 0.0;
3056 nan_value = plus_zero / plus_zero; /* Suppress GCC warning */
3058 minus_zero = FUNC (copysign) (0.0, -1.0);
3059 plus_infty = CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
3060 minus_infty = -CHOOSE (HUGE_VALL, HUGE_VAL, HUGE_VALF);
3062 (void) &plus_zero;
3063 (void) &nan_value;
3064 (void) &minus_zero;
3065 (void) &plus_infty;
3066 (void) &minus_infty;
3068 /* Test to make sure we start correctly. */
3069 fpstack_test ("end *init*");
3073 static struct option long_options[] =
3075 {"verbose", optional_argument, NULL, 'v'},
3076 {"silent", no_argument, NULL, 's'},
3077 {0, 0, 0, 0}
3081 static void
3082 parse_options (int argc, char *argv[])
3084 int c;
3085 int option_index;
3087 verbose = 1;
3089 while (1)
3091 c = getopt_long (argc, argv, "v::s",
3092 long_options, &option_index);
3094 /* Detect the end of the options. */
3095 if (c == -1)
3096 break;
3098 switch (c)
3100 case 'v':
3101 if (optarg)
3102 verbose = (unsigned int) strtoul (optarg, NULL, 0);
3103 else
3104 verbose = 3;
3105 break;
3106 case 's':
3107 verbose = 0;
3108 default:
3109 break;
3116 main (int argc, char *argv[])
3118 parse_options (argc, argv);
3120 initialize ();
3121 printf (TEST_MSG);
3122 basic_tests ();
3124 acos_test ();
3125 acosh_test ();
3126 asin_test ();
3127 asinh_test ();
3128 atan_test ();
3129 atanh_test ();
3130 atan2_test ();
3131 cbrt_test ();
3132 ceil_test ();
3133 cos_test ();
3134 cosh_test ();
3135 exp_test ();
3136 exp2_test ();
3137 expm1_test ();
3138 frexp_test ();
3139 ilogb_test ();
3140 ldexp_test ();
3141 log_test ();
3142 log10_test ();
3143 log1p_test ();
3144 log2_test ();
3145 logb_test ();
3146 modf_test ();
3147 scalb_test ();
3148 scalbn_test ();
3149 sin_test ();
3150 sinh_test ();
3151 tan_test ();
3152 tanh_test ();
3153 fabs_test ();
3154 floor_test ();
3155 fpclassify_test ();
3156 hypot_test ();
3157 pow_test ();
3158 fdim_test ();
3159 fmin_test ();
3160 fmax_test ();
3161 nextafter_test ();
3162 copysign_test ();
3163 sqrt_test ();
3164 trunc_test ();
3165 #if 0
3166 /* XXX I'm not sure what is the correct result. */
3167 remquo_test ();
3168 #endif
3169 cexp_test ();
3170 csinh_test ();
3171 ccosh_test ();
3172 clog_test ();
3174 rinttol_test ();
3175 rinttoll_test ();
3177 identities ();
3178 inverse_functions ();
3180 if (noErrors)
3182 printf ("\n%d errors occured.\n", noErrors);
3183 exit (1);
3185 printf ("\n All tests passed sucessfully.\n");
3186 exit (0);