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:
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
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,
41 /* This program isn't finished yet.
42 It has tests for acos, acosh, asin, asinh, atan, atan2, atanh,
43 cbrt, ceil, cos, cosh, exp, exp2, expm1, fabs, floor, fpclassify,
45 log, log10, log1p, log2, logb, modf,
46 pow, sin, sinh, tan, tanh.
47 Tests for the other libm-functions will come later.
49 The routines using random variables are still under construction. I don't
50 like it the way it's working now and will change it.
52 Exception handling has not been implemented so far so don't get fooled
53 that these tests pass.
55 Parameter handling is primitive in the moment:
56 --verbose=[0..3] for different levels of output:
58 1: basic report on failed tests
59 2: full report on failed tests
60 3: full report on failed and passed tests (default)
61 -v for full output (equals --verbose=3)
62 -s,--silent outputs only the error count (equals --verbose=0)
65 /* Define if the following ISO C 9X functions are implemented: exp2,
67 #undef ISO_9X_IMPLEMENTED
82 /* TEST_EXCEPTION: tests if an exception as occured */
83 /* for the moment: does nothing */
84 /* Possible exceptions */
85 #define NO_EXCEPTION 0x0
86 #define INVALID_EXCEPTION 0x1
87 #define DIVIDE_BY_ZERO_EXCEPTION 0x2
92 #define TEST_EXCEPTION(test) do {} while (0);
93 /* As long as no exception code is available prevent warnings. */
94 #define UNUSED __attribute__ ((unused))
98 static int verbose
= 3;
99 static MATHTYPE minus_zero
, plus_zero
;
100 static MATHTYPE plus_infty
, minus_infty
, nan_value
;
102 typedef MATHTYPE (*mathfunc
) (MATHTYPE
);
106 (sizeof (x) == sizeof (float) ? \
108 : sizeof (x) == sizeof (double) ? \
109 isinf (x) : isinfl (x))
113 Test if Floating-Point stack hasn't changed
116 fpstack_test (const char *test_name
)
119 static int old_stack
;
121 asm ("fnstsw":"=a" (sw
));
126 printf ("FP-Stack wrong after test %s\n", test_name
);
128 printf ("=======> stack = %d\n", sw
);
137 Call to an external function so that floating point registers
141 this_does_nothing (void)
149 Get a random value x with min_value < x < max_value
150 and min_value, max_value finite,
151 max_value and min_value shouldn't be too close together
154 random_value (MATHTYPE min_value
, MATHTYPE max_value
)
161 x
= (max_value
- min_value
) / RAND_MAX
* (MATHTYPE
) r
+ min_value
;
163 if ((x
<= min_value
) || (x
>= max_value
) || !isfinite (x
))
164 x
= (max_value
- min_value
) / 2 + min_value
;
169 /* Get a random value x with x > min_value. */
171 random_greater (MATHTYPE min_value
)
173 return random_value (min_value
, 1e6
); /* CHOOSE (LDBL_MAX, DBL_MAX, FLT_MAX) */
176 /* Get a random value x with x < max_value. */
178 random_less (MATHTYPE max_value
)
180 return random_value (-1e6
, max_value
);
184 /* Test if two floating point numbers are equal. */
186 check_equal (MATHTYPE computed
, MATHTYPE supplied
, MATHTYPE eps
, MATHTYPE
* diff
)
188 /* Both plus Infinity or both minus infinity. */
189 if (ISINF (computed
) && (ISINF (computed
) == ISINF (supplied
)))
192 if (isnan (computed
) && isnan (supplied
)) /* isnan works for all types */
195 *diff
= FUNC(fabs
) (computed
- supplied
);
197 if (*diff
<= eps
&& (signbit (computed
) == signbit (supplied
) || eps
!= 0.0))
205 output_result_bool (const char *test_name
, int result
)
210 printf ("Pass: %s\n", test_name
);
215 printf ("Fail: %s\n", test_name
);
219 fpstack_test (test_name
);
224 output_isvalue (const char *test_name
, int result
,
230 printf ("Pass: %s\n", test_name
);
235 printf ("Fail: %s\n", test_name
);
237 printf (" Value: %.20" PRINTF_EXPR
"\n", value
);
241 fpstack_test (test_name
);
246 output_isvalue_ext (const char *test_name
, int result
,
247 MATHTYPE value
, MATHTYPE parameter
)
252 printf ("Pass: %s\n", test_name
);
257 printf ("Fail: %s\n", test_name
);
260 printf (" Value: %.20" PRINTF_EXPR
"\n", value
);
261 printf (" Parameter: %.20" PRINTF_EXPR
"\n", parameter
);
266 fpstack_test (test_name
);
271 output_result (const char *test_name
, int result
,
272 MATHTYPE computed
, MATHTYPE expected
,
274 int print_values
, int print_diff
)
279 printf ("Pass: %s\n", test_name
);
284 printf ("Fail: %s\n", test_name
);
285 if (verbose
> 1 && print_values
)
287 printf ("Result:\n");
288 printf (" is: %.20" PRINTF_EXPR
"\n", computed
);
289 printf (" should be: %.20" PRINTF_EXPR
"\n", expected
);
291 printf (" difference: %.20" PRINTF_EXPR
"\n", difference
);
296 fpstack_test (test_name
);
301 output_result_ext (const char *test_name
, int result
,
302 MATHTYPE computed
, MATHTYPE expected
,
305 int print_values
, int print_diff
)
310 printf ("Pass: %s\n", test_name
);
315 printf ("Fail: %s\n", test_name
);
316 if (verbose
> 1 && print_values
)
318 printf ("Result:\n");
319 printf (" is: %.20" PRINTF_EXPR
"\n", computed
);
320 printf (" should be: %.20" PRINTF_EXPR
"\n", expected
);
322 printf (" difference: %.20" PRINTF_EXPR
"\n", difference
);
323 printf ("Parameter: %.20" PRINTF_EXPR
"\n", parameter
);
328 fpstack_test (test_name
);
333 check (const char *test_name
, MATHTYPE computed
, MATHTYPE expected
)
338 result
= check_equal (computed
, expected
, 0, &diff
);
339 output_result (test_name
, result
,
340 computed
, expected
, diff
, PRINT
, PRINT
);
345 check_ext (const char *test_name
, MATHTYPE computed
, MATHTYPE expected
,
351 result
= check_equal (computed
, expected
, 0, &diff
);
352 output_result_ext (test_name
, result
,
353 computed
, expected
, diff
, parameter
, PRINT
, PRINT
);
358 check_eps (const char *test_name
, MATHTYPE computed
, MATHTYPE expected
,
364 result
= check_equal (computed
, expected
, epsilon
, &diff
);
365 output_result (test_name
, result
,
366 computed
, expected
, diff
, PRINT
, PRINT
);
371 check_bool (const char *test_name
, int computed
)
373 output_result_bool (test_name
, computed
);
378 check_isnan (const char *test_name
, MATHTYPE computed
)
380 output_isvalue (test_name
, isnan (computed
), computed
);
385 check_isnan_exc (const char *test_name
, MATHTYPE computed
,
386 short exception UNUSED
)
388 output_isvalue (test_name
, isnan (computed
), computed
);
393 check_isnan_ext (const char *test_name
, MATHTYPE computed
,
396 output_isvalue_ext (test_name
, isnan (computed
), computed
, parameter
);
400 /* Tests if computed is +Inf */
402 check_isinfp (const char *test_name
, MATHTYPE computed
)
404 output_isvalue (test_name
, (ISINF (computed
) == +1), computed
);
409 check_isinfp_ext (const char *test_name
, MATHTYPE computed
,
412 output_isvalue_ext (test_name
, (ISINF (computed
) == +1), computed
, parameter
);
416 /* Tests if computed is +Inf */
418 check_isinfp_exc (const char *test_name
, MATHTYPE computed
,
419 int exception UNUSED
)
421 output_isvalue (test_name
, (ISINF (computed
) == +1), computed
);
424 /* Tests if computed is -Inf */
426 check_isinfn (const char *test_name
, MATHTYPE computed
)
428 output_isvalue (test_name
, (ISINF (computed
) == -1), computed
);
433 check_isinfn_ext (const char *test_name
, MATHTYPE computed
,
436 output_isvalue_ext (test_name
, (ISINF (computed
) == -1), computed
, parameter
);
440 /* Tests if computed is -Inf */
442 check_isinfn_exc (const char *test_name
, MATHTYPE computed
,
443 int exception UNUSED
)
445 output_isvalue (test_name
, (ISINF (computed
) == -1), computed
);
449 /****************************************************************************
450 Test for single functions of libm
451 ****************************************************************************/
458 check ("acos (1) == 0", FUNC(acos
) (1), 0);
460 x
= random_greater (1);
461 check_isnan_exc ("acos (x) == NaN + invalid exception for |x| > 1",
471 check ("acosh(1) == 0", FUNC(acosh
) (1), 0);
472 check_isinfp ("acosh(+inf) == +inf", FUNC(acosh
) (plus_infty
));
475 check_isnan_exc ("acosh(x) == NaN plus invalid exception if x < 1",
476 FUNC(acosh
) (x
), INVALID_EXCEPTION
);
484 check ("asin (0) == 0", FUNC(asin
) (0), 0);
486 x
= random_greater (1);
487 check_isnan_exc ("asin x == NaN + invalid exception for |x| > 1",
496 check ("asinh(+0) == +0", FUNC(asinh
) (0), 0);
497 check ("asinh(-0) == -0", FUNC(asinh
) (minus_zero
), minus_zero
);
504 check ("atan (0) == 0", FUNC(atan
) (0), 0);
505 check ("atan (-0) == -0", FUNC(atan
) (minus_zero
), minus_zero
);
507 check ("atan (+inf) == pi/2", FUNC(atan
) (plus_infty
), M_PI_2
);
508 check ("atan (-inf) == -pi/2", FUNC(atan
) (minus_infty
), -M_PI_2
);
517 x
= random_greater (0);
518 check ("atan2 (0,x) == 0 for x > 0",
519 FUNC(atan2
) (0, x
), 0);
520 x
= random_greater (0);
521 check ("atan2 (-0,x) == -0 for x > 0",
522 FUNC(atan2
) (minus_zero
, x
), minus_zero
);
524 check ("atan2 (+0,+0) == +0", FUNC(atan2
) (0, 0), 0);
525 check ("atan2 (-0,+0) == -0", FUNC(atan2
) (minus_zero
, 0), minus_zero
);
527 x
= -random_greater (0);
528 check ("atan2 (+0,x) == +pi for x < 0", FUNC(atan2
) (0, x
), M_PI
);
530 x
= -random_greater (0);
531 check ("atan2 (-0,x) == -pi for x < 0", FUNC(atan2
) (minus_zero
, x
), -M_PI
);
533 check ("atan2 (+0,-0) == +pi", FUNC(atan2
) (0, minus_zero
), M_PI
);
534 check ("atan2 (-0,-0) == -pi", FUNC(atan2
) (minus_zero
, minus_zero
), -M_PI
);
536 x
= random_greater (0);
537 check ("atan2 (y,+0) == pi/2 for y > 0", FUNC(atan2
) (x
, 0), M_PI_2
);
539 x
= random_greater (0);
540 check ("atan2 (y,-0) == pi/2 for y > 0", FUNC(atan2
) (x
, minus_zero
), M_PI_2
);
542 x
= random_greater (0);
543 check ("atan2 (y,-inf) == +pi for finite y > 0",
544 FUNC(atan2
) (x
, minus_infty
), M_PI
);
546 x
= -random_greater (0);
547 check ("atan2 (y,-inf) == -pi for finite y < 0",
548 FUNC(atan2
) (x
, minus_infty
), -M_PI
);
550 check ("atan2 (+inf,+inf) == +pi/4",
551 FUNC(atan2
) (plus_infty
, plus_infty
), M_PI_4
);
553 check ("atan2 (-inf,+inf) == -pi/4",
554 FUNC(atan2
) (minus_infty
, plus_infty
), -M_PI_4
);
556 check ("atan2 (+inf,-inf) == +3*pi/4",
557 FUNC(atan2
) (plus_infty
, minus_infty
), 3 * M_PI_4
);
559 check ("atan2 (-inf,-inf) == -3*pi/4",
560 FUNC(atan2
) (minus_infty
, minus_infty
), -3 * M_PI_4
);
568 check ("atanh(+0) == +0", FUNC(atanh
) (0), 0);
569 check ("atanh(-0) == -0", FUNC(atanh
) (minus_zero
), minus_zero
);
570 check_isinfp_exc ("atanh(+1) == +inf plus divide-by-zero exception",
571 FUNC(atanh
) (1), DIVIDE_BY_ZERO_EXCEPTION
);
572 check_isinfn_exc ("atanh(-1) == -inf plus divide-by-zero exception",
573 FUNC(atanh
) (-1), DIVIDE_BY_ZERO_EXCEPTION
);
580 check ("cbrt (+0) == +0", FUNC(cbrt
) (0.0), 0.0);
581 check ("cbrt (-0) == -0", FUNC(cbrt
) (minus_zero
), minus_zero
);
583 check ("cbrt (8) == 2", FUNC(cbrt
) (8), 2);
584 check ("cbrt (-27) == -3", FUNC(cbrt
) (-27.0), -3.0);
591 check ("ceil (+0) == +0", FUNC(ceil
) (0.0), 0.0);
592 check ("ceil (-0) == -0", FUNC(ceil
) (minus_zero
), minus_zero
);
593 check_isinfp ("ceil (+inf) == +inf", FUNC(ceil
) (plus_infty
));
594 check_isinfn ("ceil (-inf) == -inf", FUNC(ceil
) (minus_infty
));
596 check ("ceil (pi) == 4", FUNC(ceil
) (M_PI
), 4.0);
597 check ("ceil (-pi) == -3", FUNC(ceil
) (-M_PI
), -3.0);
605 check ("cos (+0) == 1", FUNC(cos
) (0), 1);
606 check ("cos (-0) == 1", FUNC(cos
) (minus_zero
), 1);
607 check_isnan_exc ("cos (+inf) == NaN plus invalid exception",
608 FUNC(cos
) (plus_infty
),
610 check_isnan_exc ("cos (-inf) == NaN plus invalid exception",
611 FUNC(cos
) (minus_infty
),
614 check_eps ("cos (pi/3) == 0.5", FUNC(cos
) (M_PI
/ 3.0),
615 0.5, CHOOSE (0, 1e-15L, 1e-7L));
616 check_eps ("cos (pi/2) == 0.5", FUNC(cos
) (M_PI_2
),
617 0, CHOOSE (1e-19L, 1e-16L, 1e-7L));
624 check ("cosh (+0) == 1", FUNC(cosh
) (0), 1);
625 check ("cosh (-0) == 1", FUNC(cosh
) (minus_zero
), 1);
627 check_isinfp ("cosh (+inf) == +inf", FUNC(cosh
) (plus_infty
));
628 check_isinfp ("cosh (-inf) == +inf", FUNC(cosh
) (minus_infty
));
635 check ("exp (+0) == 1", FUNC(exp
) (0), 1);
636 check ("exp (-0) == 1", FUNC(exp
) (minus_zero
), 1);
638 check_isinfp ("exp (+inf) == +inf", FUNC(exp
) (plus_infty
));
639 check ("exp (-inf) == 0", FUNC(exp
) (minus_infty
), 0);
641 check ("exp (1) == e", FUNC(exp
) (1), M_E
);
645 #ifdef ISO_9X_IMPLEMENTED
649 check ("exp2 (+0) == 1", FUNC(exp2
) (0), 1);
650 check ("exp2 (-0) == 1", FUNC(exp2
) (minus_zero
), 1);
652 check_isinfp ("exp2 (+inf) == +inf", FUNC(exp2
) (plus_infty
));
653 check ("exp2 (-inf) == 0", FUNC(exp2
) (minus_infty
), 0);
654 check ("exp2 (10) == 1024", FUNC(exp2
) (10), 1024);
662 check ("expm1 (+0) == 0", FUNC(expm1
) (0), 0);
663 check ("expm1 (-0) == -0", FUNC(expm1
) (minus_zero
), minus_zero
);
665 check_isinfp ("expm1 (+inf) == +inf", FUNC(expm1
) (plus_infty
));
666 check ("expm1 (-inf) == -1", FUNC(expm1
) (minus_infty
), -1);
668 check ("expm1 (1) == e-1", FUNC(expm1
) (1), M_E
- 1.0);
675 check_frexp (const char *test_name
, MATHTYPE computed
, MATHTYPE expected
,
676 int comp_int
, int exp_int
)
681 result
= (check_equal (computed
, expected
, 0, &diff
)
682 && (comp_int
== exp_int
));
687 printf ("Pass: %s\n", test_name
);
692 printf ("Fail: %s\n", test_name
);
695 printf ("Result:\n");
696 printf (" is: %.20" PRINTF_EXPR
" *2^%d\n", computed
, comp_int
);
697 printf (" should be: %.20" PRINTF_EXPR
" *2^%d\n", expected
, exp_int
);
698 printf (" difference: %.20" PRINTF_EXPR
"\n", diff
);
702 fpstack_test (test_name
);
703 output_result (test_name
, result
,
704 computed
, expected
, diff
, PRINT
, PRINT
);
714 result
= FUNC(frexp
) (plus_infty
, &x_int
);
715 check_isinfp ("frexp (+inf, expr) == +inf", result
);
717 result
= FUNC(frexp
) (minus_infty
, &x_int
);
718 check_isinfn ("frexp (-inf, expr) == -inf", result
);
720 result
= FUNC(frexp
) (nan_value
, &x_int
);
721 check_isnan ("frexp (Nan, expr) == NaN", result
);
723 result
= FUNC(frexp
) (0, &x_int
);
724 check_frexp ("frexp: +0 == 0 * 2^0", result
, 0, x_int
, 0);
726 result
= FUNC(frexp
) (minus_zero
, &x_int
);
727 check_frexp ("frexp: -0 == -0 * 2^0", result
, minus_zero
, x_int
, 0);
729 result
= FUNC(frexp
) (12.8L, &x_int
);
730 check_frexp ("frexp: 12.8 == 0.8 * 2^4", result
, 0.8L, x_int
, 4);
732 result
= FUNC(frexp
) (-27.34L, &x_int
);
733 check_frexp ("frexp: -27.34 == -0.854375 * 2^5", result
, -0.854375L, x_int
, 5);
738 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 1)
739 /* All floating-point numbers can be put in one of these categories. */
743 #define FP_NAN FP_NAN
745 #define FP_INFINITE FP_INFINITE
747 #define FP_ZERO FP_ZERO
749 #define FP_SUBNORMAL FP_SUBNORMAL
751 #define FP_NORMAL FP_NORMAL
757 fpclassify_test (void)
761 /* fpclassify is a macro, don't give it constants as parameter */
762 check_bool ("fpclassify (NaN) == FP_NAN", fpclassify (nan_value
) == FP_NAN
);
763 check_bool ("fpclassify (+inf) == FP_INFINITE",
764 fpclassify (plus_infty
) == FP_INFINITE
);
765 check_bool ("fpclassify (-inf) == FP_INFINITE",
766 fpclassify (minus_infty
) == FP_INFINITE
);
767 check_bool ("fpclassify (+0) == FP_ZERO",
768 fpclassify (plus_zero
) == FP_ZERO
);
769 check_bool ("fpclassify (-0) == FP_ZERO",
770 fpclassify (minus_zero
) == FP_ZERO
);
773 check_bool ("fpclassify (1000) == FP_NORMAL",
774 fpclassify (x
) == FP_NORMAL
);
781 check ("ldexp (0, 0) == 0", FUNC(ldexp
) (0, 0), 0);
783 check_isinfp ("ldexp (+inf, 1) == +inf", FUNC(ldexp
) (plus_infty
, 1));
784 check_isinfn ("ldexp (-inf, 1) == -inf", FUNC(ldexp
) (minus_infty
, 1));
785 check_isnan ("ldexp (NaN, 1) == NaN", FUNC(ldexp
) (nan_value
, 1));
787 check ("ldexp (0.8, 4) == 12.8", FUNC(ldexp
) (0.8L, 4), 12.8L);
788 check ("ldexp (-0.854375, 5) == -27.34", FUNC(ldexp
) (-0.854375L, 5), -27.34L);
795 check_isinfn_exc ("log (+0) == -inf", FUNC(log
) (0),
796 DIVIDE_BY_ZERO_EXCEPTION
);
797 check_isinfn_exc ("log (-0) == -inf", FUNC(log
) (minus_zero
),
798 DIVIDE_BY_ZERO_EXCEPTION
);
800 check ("log (1) == 0", FUNC(log
) (1), 0);
802 check_isnan_exc ("log (x) == NaN plus divide-by-zero exception if x < 0",
803 FUNC(log
) (-1), INVALID_EXCEPTION
);
804 check_isinfp ("log (+inf) == +inf", FUNC(log
) (plus_infty
));
806 check_eps ("log (e) == 1", FUNC(log
) (M_E
), 1, CHOOSE (0, 0, 9e-8L));
807 check ("log (1/e) == -1", FUNC(log
) (1.0 / M_E
), -1);
808 check ("log (2) == M_LN2", FUNC(log
) (2), M_LN2
);
809 check ("log (10) == M_LN10", FUNC(log
) (10), M_LN10
);
816 check_isinfn_exc ("log10 (+0) == -inf", FUNC(log10
) (0),
817 DIVIDE_BY_ZERO_EXCEPTION
);
818 check_isinfn_exc ("log10 (-0) == -inf", FUNC(log10
) (minus_zero
),
819 DIVIDE_BY_ZERO_EXCEPTION
);
821 check ("log10 (1) == +0", FUNC(log10
) (1), 0);
823 check_isnan_exc ("log10 (x) == NaN plus divide-by-zero exception if x < 0",
824 FUNC(log10
) (-1), INVALID_EXCEPTION
);
826 check_isinfp ("log10 (+inf) == +inf", FUNC(log10
) (plus_infty
));
828 check ("log10 (0.1) == -1", FUNC(log10
) (0.1L), -1);
829 check ("log10 (10) == 1", FUNC(log10
) (10.0), 1);
830 check ("log10 (100) == 2", FUNC(log10
) (100.0), 2);
831 check ("log10 (10000) == 4", FUNC(log10
) (10000.0), 4);
832 check_eps ("log10 (e) == M_LOG10E", FUNC(log10
) (M_E
), M_LOG10E
,
833 CHOOSE (9e-20, 0, 9e-8));
840 check ("log1p (+0) == +0", FUNC(log1p
) (0), 0);
841 check ("log1p (-0) == -0", FUNC(log1p
) (minus_zero
), minus_zero
);
843 check_isinfn_exc ("log1p (-1) == -inf", FUNC(log1p
) (-1),
844 DIVIDE_BY_ZERO_EXCEPTION
);
845 check_isnan_exc ("log1p (x) == NaN plus divide-by-zero exception if x < -1",
846 FUNC(log1p
) (-2), INVALID_EXCEPTION
);
848 check_isinfp ("log1p (+inf) == +inf", FUNC(log1p
) (plus_infty
));
850 check ("log1p (e-1) == 1", FUNC(log1p
) (M_E
- 1.0), 1);
855 #ifdef ISO_9X_IMPLEMENTED
859 check_isinfn_exc ("log2 (+0) == -inf", FUNC(log2
) (0),
860 DIVIDE_BY_ZERO_EXCEPTION
);
861 check_isinfn_exc ("log2 (-0) == -inf", FUNC(log2
) (minus_zero
),
862 DIVIDE_BY_ZERO_EXCEPTION
);
864 check ("log2 (1) == +0", FUNC(log2
) (1), 0);
866 check_isnan_exc ("log2 (x) == NaN plus divide-by-zero exception if x < 0",
867 FUNC(log2
) (-1), INVALID_EXCEPTION
);
869 check_isinfp ("log2 (+inf) == +inf", FUNC(log2
) (plus_infty
));
871 check ("log2 (e) == M_LOG2E", FUNC(log2
) (M_E
), M_LOG2E
);
872 check ("log2 (2) == 1", FUNC(log2
) (2.0), 1);
873 check ("log2 (16) == 4", FUNC(log2
) (16.0), 4);
874 check ("log2 (256) == 8", FUNC(log2
) (256.0), 8);
883 check_isinfp ("logb (+inf) == +inf", FUNC(logb
) (plus_infty
));
884 check_isinfp ("logb (-inf) == +inf", FUNC(logb
) (minus_infty
));
886 check_isinfn_exc ("logb (+0) == -inf plus divide-by-zero exception",
887 FUNC(logb
) (0), DIVIDE_BY_ZERO_EXCEPTION
);
889 check_isinfn_exc ("logb (-0) == -inf plus divide-by-zero exception",
890 FUNC(logb
) (minus_zero
), DIVIDE_BY_ZERO_EXCEPTION
);
892 check ("logb (1) == 0", FUNC(logb
) (1), 0);
893 check ("logb (e) == 1", FUNC(logb
) (M_E
), 1);
894 check ("logb (1024) == 10", FUNC(logb
) (1024), 10);
895 check ("logb (-2000) == 10", FUNC(logb
) (-2000), 10);
903 MATHTYPE result
, intpart
;
905 result
= FUNC(modf
) (plus_infty
, &intpart
);
906 check ("modf (+inf, &x) returns +0", result
, 0);
907 check_isinfp ("modf (+inf, &x) set x to +inf", intpart
);
909 result
= FUNC(modf
) (minus_infty
, &intpart
);
910 check ("modf (-inf, &x) returns -0", result
, minus_zero
);
911 check_isinfn ("modf (-inf, &x) sets x to -inf", intpart
);
913 result
= FUNC(modf
) (nan_value
, &intpart
);
914 check_isnan ("modf (NaN, &x) returns NaN", result
);
915 check_isnan ("modf (-inf, &x) sets x to NaN", intpart
);
917 result
= FUNC(modf
) (0, &intpart
);
918 check ("modf (0, &x) returns 0", result
, 0);
919 check ("modf (0, &x) sets x to 0", intpart
, 0);
921 result
= FUNC(modf
) (minus_zero
, &intpart
);
922 check ("modf (-0, &x) returns -0", result
, minus_zero
);
923 check ("modf (-0, &x) sets x to -0", intpart
, minus_zero
);
925 result
= FUNC(modf
) (2.5, &intpart
);
926 check ("modf (2.5, &x) returns 0.5", result
, 0.5);
927 check ("modf (2.5, &x) sets x to 2", intpart
, 2);
929 result
= FUNC(modf
) (-2.5, &intpart
);
930 check ("modf (-2.5, &x) returns -0.5", result
, -0.5);
931 check ("modf (-2.5, &x) sets x to -2", intpart
, -2);
939 check ("sin (+0) == +0", FUNC(sin
) (0), 0);
940 check ("sin (-0) == -0", FUNC(sin
) (minus_zero
), minus_zero
);
941 check_isnan_exc ("sin (+inf) == NaN plus invalid exception",
942 FUNC(sin
) (plus_infty
),
944 check_isnan_exc ("sin (-inf) == NaN plus invalid exception",
945 FUNC(sin
) (minus_infty
),
948 check ("sin (pi/6) == 0.5", FUNC(sin
) (M_PI
/ 6.0), 0.5);
949 check ("sin (pi/2) == 1", FUNC(sin
) (M_PI_2
), 1);
956 check ("sinh (+0) == +0", FUNC(sinh
) (0), 0);
957 check ("sinh (-0) == -0", FUNC(sinh
) (minus_zero
), minus_zero
);
959 check_isinfp ("sinh (+inf) == +inf", FUNC(sinh
) (plus_infty
));
960 check_isinfn ("sinh (-inf) == -inf", FUNC(sinh
) (minus_infty
));
967 check ("tan (+0) == -0", FUNC(tan
) (0), 0);
968 check ("tan (-0) == -0", FUNC(tan
) (minus_zero
), minus_zero
);
969 check_isnan_exc ("tan (+inf) == NaN plus invalid exception",
970 FUNC(tan
) (plus_infty
), INVALID_EXCEPTION
);
971 check_isnan_exc ("tan (-inf) == NaN plus invalid exception",
972 FUNC(tan
) (minus_infty
), INVALID_EXCEPTION
);
974 check_eps ("tan (pi/4) == 1", FUNC(tan
) (M_PI_4
), 1, CHOOSE (0, 1e-15L, 0));
981 check ("tanh (+0) == +0", FUNC(tanh
) (0), 0);
982 check ("tanh (-0) == -0", FUNC(tanh
) (minus_zero
), minus_zero
);
984 check ("tanh (+inf) == +1", FUNC(tanh
) (plus_infty
), 1);
985 check ("tanh (-inf) == -1", FUNC(tanh
) (minus_infty
), -1);
992 check ("fabs (+0) == +0", FUNC(fabs
) (0), 0);
993 check ("fabs (-0) == +0", FUNC(fabs
) (minus_zero
), 0);
995 check_isinfp ("fabs (+inf) == +inf", FUNC(fabs
) (plus_infty
));
996 check_isinfp ("fabs (-inf) == +inf", FUNC(fabs
) (minus_infty
));
998 check ("fabs (+38) == 38", FUNC(fabs
) (38.0), 38.0);
999 check ("fabs (-e) == e", FUNC(fabs
) (-M_E
), M_E
);
1006 check ("floor (+0) == +0", FUNC(floor
) (0.0), 0.0);
1007 check ("floor (-0) == -0", FUNC(floor
) (minus_zero
), minus_zero
);
1008 check_isinfp ("floor (+inf) == +inf", FUNC(floor
) (plus_infty
));
1009 check_isinfn ("floor (-inf) == -inf", FUNC(floor
) (minus_infty
));
1011 check ("floor (pi) == 3", FUNC(floor
) (M_PI
), 3.0);
1012 check ("floor (-pi) == -4", FUNC(floor
) (-M_PI
), -4.0);
1021 a
= random_greater (0);
1022 check_isinfp_ext ("hypot (+inf, x) == +inf", FUNC(hypot
) (plus_infty
, a
), a
);
1023 check_isinfp_ext ("hypot (-inf, x) == +inf", FUNC(hypot
) (minus_infty
, a
), a
);
1025 check_isnan ("hypot (NaN, NaN) == NaN", FUNC(hypot
) (nan_value
, nan_value
));
1027 a
= FUNC(hypot
) (12.4L, 0.7L);
1028 check ("hypot (x,y) == hypot (y,x)", FUNC(hypot
) (0.7L, 12.4L), a
);
1029 check ("hypot (x,y) == hypot (-x,y)", FUNC(hypot
) (-12.4L, 0.7L), a
);
1030 check ("hypot (x,y) == hypot (-y,x)", FUNC(hypot
) (-0.7L, 12.4L), a
);
1031 check ("hypot (x,y) == hypot (-x,-y)", FUNC(hypot
) (-12.4L, -0.7L), a
);
1032 check ("hypot (x,y) == hypot (-y,-x)", FUNC(hypot
) (-0.7L, -12.4L), a
);
1033 check ("hypot (x,0) == fabs (x)", FUNC(hypot
) (-0.7L, 0), 0.7L);
1034 check ("hypot (x,0) == fabs (x)", FUNC(hypot
) (0.7L, 0), 0.7L);
1035 check ("hypot (x,0) == fabs (x)", FUNC(hypot
) (-1.0L, 0), 1.0L);
1036 check ("hypot (x,0) == fabs (x)", FUNC(hypot
) (1.0L, 0), 1.0L);
1037 check ("hypot (x,0) == fabs (x)", FUNC(hypot
) (-5.7e7L
, 0), 5.7e7L
);
1038 check ("hypot (x,0) == fabs (x)", FUNC(hypot
) (5.7e7L
, 0), 5.7e7L
);
1047 check ("pow (+0, +0) == 1", FUNC(pow
) (0, 0), 1);
1048 check ("pow (+0, -0) == 1", FUNC(pow
) (0, minus_zero
), 1);
1049 check ("pow (-0, +0) == 1", FUNC(pow
) (minus_zero
, 0), 1);
1050 check ("pow (-0, -0) == 1", FUNC(pow
) (minus_zero
, minus_zero
), 1);
1052 check ("pow (+10, +0) == 1", FUNC(pow
) (10, 0), 1);
1053 check ("pow (+10, -0) == 1", FUNC(pow
) (10, minus_zero
), 1);
1054 check ("pow (-10, +0) == 1", FUNC(pow
) (-10, 0), 1);
1055 check ("pow (-10, -0) == 1", FUNC(pow
) (-10, minus_zero
), 1);
1057 check ("pow (NaN, +0) == 1", FUNC(pow
) (nan_value
, 0), 1);
1058 check ("pow (NaN, -0) == 1", FUNC(pow
) (nan_value
, minus_zero
), 1);
1060 check_isinfp ("pow (+1.1, +inf) == +inf", FUNC(pow
) (1.1, plus_infty
));
1061 check_isinfp ("pow (+inf, +inf) == +inf", FUNC(pow
) (plus_infty
, plus_infty
));
1062 check_isinfp ("pow (-1.1, +inf) == +inf", FUNC(pow
) (-1.1, plus_infty
));
1063 check_isinfp ("pow (-inf, +inf) == +inf", FUNC(pow
) (minus_infty
, plus_infty
));
1065 check ("pow (0.9, +inf) == +0", FUNC(pow
) (0.9L, plus_infty
), 0);
1066 check ("pow (1e-7, +inf) == +0", FUNC(pow
) (1e-7L, plus_infty
), 0);
1067 check ("pow (-0.9, +inf) == +0", FUNC(pow
) (-0.9L, plus_infty
), 0);
1068 check ("pow (-1e-7, +inf) == +0", FUNC(pow
) (-1e-7L, plus_infty
), 0);
1070 check ("pow (+1.1, -inf) == +inf", FUNC(pow
) (1.1, minus_infty
), 0);
1071 check ("pow (+inf, -inf) == +inf", FUNC(pow
) (plus_infty
, minus_infty
), 0);
1072 check ("pow (-1.1, -inf) == +inf", FUNC(pow
) (-1.1, minus_infty
), 0);
1073 check ("pow (-inf, -inf) == +inf", FUNC(pow
) (minus_infty
, minus_infty
), 0);
1075 check_isinfp ("pow (0.9, -inf) == +0", FUNC(pow
) (0.9L, minus_infty
));
1076 check_isinfp ("pow (1e-7, -inf) == +0", FUNC(pow
) (1e-7L, minus_infty
));
1077 check_isinfp ("pow (-0.9, -inf) == +0", FUNC(pow
) (-0.9L, minus_infty
));
1078 check_isinfp ("pow (-1e-7, -inf) == +0", FUNC(pow
) (-1e-7L, minus_infty
));
1080 check_isinfp ("pow (+inf, 1e-7) == +inf", FUNC(pow
) (plus_infty
, 1e-7L));
1081 check_isinfp ("pow (+inf, 1) == +inf", FUNC(pow
) (plus_infty
, 1));
1082 check_isinfp ("pow (+inf, 1e7) == +inf", FUNC(pow
) (plus_infty
, 1e7L
));
1084 check ("pow (+inf, -1e-7) == 0", FUNC(pow
) (plus_infty
, -1e-7L), 0);
1085 check ("pow (+inf, -1) == 0", FUNC(pow
) (plus_infty
, -1), 0);
1086 check ("pow (+inf, -1e7) == 0", FUNC(pow
) (plus_infty
, -1e7L
), 0);
1088 check_isinfn ("pow (-inf, 1) == -inf", FUNC(pow
) (minus_infty
, 1));
1089 check_isinfn ("pow (-inf, 11) == -inf", FUNC(pow
) (minus_infty
, 11));
1090 check_isinfn ("pow (-inf, 1001) == -inf", FUNC(pow
) (minus_infty
, 1001));
1092 check_isinfp ("pow (-inf, 2) == +inf", FUNC(pow
) (minus_infty
, 2));
1093 check_isinfp ("pow (-inf, 12) == +inf", FUNC(pow
) (minus_infty
, 12));
1094 check_isinfp ("pow (-inf, 1002) == +inf", FUNC(pow
) (minus_infty
, 1002));
1095 check_isinfp ("pow (-inf, 0.1) == +inf", FUNC(pow
) (minus_infty
, 0.1));
1096 check_isinfp ("pow (-inf, 1.1) == +inf", FUNC(pow
) (minus_infty
, 1.1));
1097 check_isinfp ("pow (-inf, 11.1) == +inf", FUNC(pow
) (minus_infty
, 11.1));
1098 check_isinfp ("pow (-inf, 1001.1) == +inf", FUNC(pow
) (minus_infty
, 1001.1));
1100 check ("pow (-inf, -1) == -0", FUNC(pow
) (minus_infty
, -1), minus_zero
);
1101 check ("pow (-inf, -11) == -0", FUNC(pow
) (minus_infty
, -11), minus_zero
);
1102 check ("pow (-inf, -1001) == -0", FUNC(pow
) (minus_infty
, -1001), minus_zero
);
1104 check ("pow (-inf, -2) == +0", FUNC(pow
) (minus_infty
, -2), 0);
1105 check ("pow (-inf, -12) == +0", FUNC(pow
) (minus_infty
, -12), 0);
1106 check ("pow (-inf, -1002) == +0", FUNC(pow
) (minus_infty
, -1002), 0);
1107 check ("pow (-inf, -0.1) == +0", FUNC(pow
) (minus_infty
, -0.1), 0);
1108 check ("pow (-inf, -1.1) == +0", FUNC(pow
) (minus_infty
, -1.1), 0);
1109 check ("pow (-inf, -11.1) == +0", FUNC(pow
) (minus_infty
, -11.1), 0);
1110 check ("pow (-inf, -1001.1) == +0", FUNC(pow
) (minus_infty
, -1001.1), 0);
1112 check_isnan ("pow (NaN, NaN) == NaN", FUNC(pow
) (nan_value
, nan_value
));
1113 check_isnan ("pow (0, NaN) == NaN", FUNC(pow
) (0, nan_value
));
1114 check_isnan ("pow (1, NaN) == NaN", FUNC(pow
) (1, nan_value
));
1115 check_isnan ("pow (-1, NaN) == NaN", FUNC(pow
) (-1, nan_value
));
1116 check_isnan ("pow (NaN, 1) == NaN", FUNC(pow
) (nan_value
, 1));
1117 check_isnan ("pow (NaN, -1) == NaN", FUNC(pow
) (nan_value
, -1));
1119 x
= random_greater (0.0);
1120 check_isnan_ext ("pow (x, NaN) == NaN", FUNC(pow
) (x
, nan_value
), x
);
1122 check_isnan_exc ("pow (+1, +inf) == NaN", FUNC(pow
) (1, plus_infty
),
1124 check_isnan_exc ("pow (-1, +inf) == NaN", FUNC(pow
) (1, plus_infty
),
1126 check_isnan_exc ("pow (+1, -inf) == NaN", FUNC(pow
) (1, plus_infty
),
1128 check_isnan_exc ("pow (-1, -inf) == NaN", FUNC(pow
) (1, plus_infty
),
1131 check_isnan_exc ("pow (-0.1, 1.1) == NaN", FUNC(pow
) (-0.1, 1.1),
1133 check_isnan_exc ("pow (-0.1, -1.1) == NaN", FUNC(pow
) (-0.1, -1.1),
1135 check_isnan_exc ("pow (-10.1, 1.1) == NaN", FUNC(pow
) (-10.1, 1.1),
1137 check_isnan_exc ("pow (-10.1, -1.1) == NaN", FUNC(pow
) (-10.1, -1.1),
1140 check_isinfp_exc ("pow (+0, -1) == +inf", FUNC(pow
) (0, -1),
1141 DIVIDE_BY_ZERO_EXCEPTION
);
1142 check_isinfp_exc ("pow (+0, -11) == +inf", FUNC(pow
) (0, -11),
1143 DIVIDE_BY_ZERO_EXCEPTION
);
1144 check_isinfn_exc ("pow (-0, -1) == -inf", FUNC(pow
) (minus_zero
, -1),
1145 DIVIDE_BY_ZERO_EXCEPTION
);
1146 check_isinfn_exc ("pow (-0, -11) == -inf", FUNC(pow
) (minus_zero
, -11),
1147 DIVIDE_BY_ZERO_EXCEPTION
);
1149 check_isinfp_exc ("pow (+0, -2) == +inf", FUNC(pow
) (0, -2),
1150 DIVIDE_BY_ZERO_EXCEPTION
);
1151 check_isinfp_exc ("pow (+0, -11.1) == +inf", FUNC(pow
) (0, -11.1),
1152 DIVIDE_BY_ZERO_EXCEPTION
);
1153 check_isinfp_exc ("pow (-0, -2) == +inf", FUNC(pow
) (minus_zero
, -2),
1154 DIVIDE_BY_ZERO_EXCEPTION
);
1155 check_isinfp_exc ("pow (-0, -11.1) == +inf", FUNC(pow
) (minus_zero
, -11.1),
1156 DIVIDE_BY_ZERO_EXCEPTION
);
1158 check ("pow (+0, 1) == +0", FUNC(pow
) (0, 1), 0);
1159 check ("pow (+0, 11) == +0", FUNC(pow
) (0, 11), 0);
1160 check ("pow (-0, 1) == -0", FUNC(pow
) (minus_zero
, 1), minus_zero
);
1161 check ("pow (-0, 11) == -0", FUNC(pow
) (minus_zero
, 11), minus_zero
);
1163 check ("pow (+0, 2) == +0", FUNC(pow
) (0, 2), 0);
1164 check ("pow (+0, 11.1) == +0", FUNC(pow
) (0, 11.1), 0);
1165 check ("pow (-0, 2) == +0", FUNC(pow
) (minus_zero
, 2), 0);
1166 check ("pow (-0, 11.1) == +0", FUNC(pow
) (minus_zero
, 11.1), 0);
1168 x
= random_greater (0.0);
1169 check_isinfp_ext ("pow (x, +inf) == +inf for |x| > 1",
1170 FUNC(pow
) (x
, plus_infty
), x
);
1172 x
= random_value (-1.0, 1.0);
1173 check_ext ("pow (x, +inf) == +0 for |x| < 1",
1174 FUNC(pow
) (x
, plus_infty
), 0.0, x
);
1176 x
= random_greater (0.0);
1177 check_ext ("pow (x, -inf) == +0 for |x| > 1",
1178 FUNC(pow
) (x
, minus_infty
), 0.0, x
);
1180 x
= random_value (-1.0, 1.0);
1181 check_isinfp_ext ("pow (x, -inf) == +inf for |x| < 1",
1182 FUNC(pow
) (x
, minus_infty
), x
);
1184 x
= random_greater (0.0);
1185 check_isinfp_ext ("pow (+inf, y) == +inf for y > 0",
1186 FUNC(pow
) (plus_infty
, x
), x
);
1188 x
= random_less (0.0);
1189 check_ext ("pow (+inf, y) == +0 for y < 0",
1190 FUNC(pow
) (plus_infty
, x
), 0.0, x
);
1192 x
= (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
1193 check_isinfn_ext ("pow (-inf, y) == -inf for y an odd integer > 0",
1194 FUNC(pow
) (minus_infty
, x
), x
);
1196 x
= ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
1197 check_isinfp_ext ("pow (-inf, y) == +inf for y > 0 and not an odd integer",
1198 FUNC(pow
) (minus_infty
, x
), x
);
1200 x
= -((rand () % 1000000) * 2.0 + 1); /* Get random odd integer < 0 */
1201 check_ext ("pow (-inf, y) == -0 for y an odd integer < 0",
1202 FUNC(pow
) (minus_infty
, x
), minus_zero
, x
);
1204 x
= ((rand () % 1000000) + 1) * -2.0; /* Get random even integer < 0 */
1205 check_ext ("pow (-inf, y) == 0 for y < 0 and not an odd integer",
1206 FUNC(pow
) (minus_infty
, x
), 0.0, x
);
1208 x
= (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
1209 check_ext ("pow (+0, y) == +0 for y an odd integer > 0",
1210 FUNC(pow
) (0.0, x
), 0.0, x
);
1211 x
= (rand () % 1000000) * 2.0 + 1; /* Get random odd integer > 0 */
1212 check_ext ("pow (-0, y) == -0 for y an odd integer > 0",
1213 FUNC(pow
) (minus_zero
, x
), minus_zero
, x
);
1215 x
= ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
1216 check_ext ("pow (+0, y) == +0 for y > 0 and not an odd integer",
1217 FUNC(pow
) (0.0, x
), 0.0, x
);
1219 x
= ((rand () % 1000000) + 1) * 2.0; /* Get random even integer > 1 */
1220 check_ext ("pow (-0, y) == +0 for y > 0 and not an odd integer",
1221 FUNC(pow
) (minus_zero
, x
), 0.0, x
);
1226 inverse_func_pair_test (const char *test_name
,
1227 mathfunc f1
, mathfunc inverse
,
1228 MATHTYPE x
, MATHTYPE epsilon
)
1230 MATHTYPE a
, b
, difference
;
1234 this_does_nothing ();
1236 this_does_nothing ();
1238 result
= check_equal (b
, x
, epsilon
, &difference
);
1239 output_result (test_name
, result
,
1240 b
, x
, difference
, PRINT
, PRINT
);
1245 inverse_functions (void)
1247 inverse_func_pair_test ("(asin(sin(x)) == x",
1248 FUNC(sin
), FUNC(asin
), 1.0, CHOOSE (0, 0, 1e-7L));
1249 inverse_func_pair_test ("(sin(asin(x)) == x",
1250 FUNC(asin
), FUNC(sin
), 1.0, 0.0);
1252 inverse_func_pair_test ("(acos(cos(x)) == x",
1253 FUNC(cos
), FUNC(acos
), 1.0, CHOOSE (0, 1e-15L, 0));
1254 inverse_func_pair_test ("(cos(acos(x)) == x",
1255 FUNC(acos
), FUNC(cos
), 1.0, 0.0);
1256 inverse_func_pair_test ("(atan(tan(x)) == x",
1257 FUNC(tan
), FUNC(atan
), 1.0, 0.0);
1258 inverse_func_pair_test ("(tan(atan(x)) == x",
1259 FUNC(atan
), FUNC(tan
), 1.0, CHOOSE (0, 1e-15L, 0));
1261 inverse_func_pair_test ("(asinh(sinh(x)) == x",
1262 FUNC(sinh
), FUNC(asinh
), 1.0, CHOOSE (1e-18L, 0, 0));
1263 inverse_func_pair_test ("(sinh(asinh(x)) == x",
1264 FUNC(asinh
), FUNC(sinh
), 1.0, 0.0);
1266 inverse_func_pair_test ("(acosh(cosh(x)) == x",
1267 FUNC(cosh
), FUNC(acosh
), 1.0, CHOOSE (1e-18L, 1e-15L, 0));
1268 inverse_func_pair_test ("(cosh(acosh(x)) == x",
1269 FUNC(acosh
), FUNC(cosh
), 1.0, 0.0);
1271 inverse_func_pair_test ("(atanh(tanh(x)) == x",
1272 FUNC(tanh
), FUNC(atanh
), 1.0, CHOOSE (0, 1e-15L, 0));
1273 inverse_func_pair_test ("(tanh(atanh(x)) == x",
1274 FUNC(atanh
), FUNC(tanh
), 1.0, 0.0);
1278 /* Test sin and cos with the identity: sin(x)^2 + cos(x)^2 = 1. */
1280 identities1_test (MATHTYPE x
, MATHTYPE epsilon
)
1282 MATHTYPE res1
, res2
, res3
, diff
;
1285 res1
= FUNC(sin
) (x
);
1286 this_does_nothing ();
1287 res2
= FUNC(cos
) (x
);
1288 this_does_nothing ();
1289 res3
= res1
* res1
+ res2
* res2
;
1290 this_does_nothing ();
1292 result
= check_equal (res3
, 1.0, epsilon
, &diff
);
1293 output_result_ext ("sin^2 + cos^2 == 1", result
,
1294 res3
, 1.0, diff
, x
, PRINT
, PRINT
);
1298 /* Test sin, cos, tan with the following relation: tan = sin/cos. */
1300 identities2_test (MATHTYPE x
, MATHTYPE epsilon
)
1302 MATHTYPE res1
, res2
, res3
, res4
, diff
;
1305 res1
= FUNC(sin
) (x
);
1306 this_does_nothing ();
1307 res2
= FUNC(cos
) (x
);
1308 this_does_nothing ();
1309 res3
= FUNC(tan
) (x
);
1310 this_does_nothing ();
1312 this_does_nothing ();
1314 result
= check_equal (res4
, res3
, epsilon
, &diff
);
1315 output_result_ext ("sin/cos == tan", result
,
1316 res4
, res3
, diff
, x
, PRINT
, PRINT
);
1320 /* Test cosh and sinh with the identity cosh^2 - sinh^2 = 1. */
1322 identities3_test (MATHTYPE x
, MATHTYPE epsilon
)
1324 MATHTYPE res1
, res2
, res3
, diff
;
1327 res1
= FUNC(sinh
) (x
);
1328 this_does_nothing ();
1329 res2
= FUNC(cosh
) (x
);
1330 this_does_nothing ();
1331 res3
= res2
* res2
- res1
* res1
;
1332 this_does_nothing ();
1334 result
= check_equal (res3
, 1.0, epsilon
, &diff
);
1335 output_result_ext ("cosh^2 - sinh^2 == 1", result
,
1336 res3
, 1.0, diff
, x
, PRINT
, PRINT
);
1343 identities1_test (0.2L, CHOOSE (1e-19L, 0, 0));
1344 identities1_test (0.9L, 0);
1345 identities1_test (0, 0);
1346 identities1_test (-1, CHOOSE (0, 0, 1e-7));
1348 identities2_test (0.2L, CHOOSE (0, 1e-16, 0));
1349 identities2_test (0.9L, CHOOSE (0, 1e-15, 0));
1350 identities2_test (0, 0);
1351 identities2_test (-1, CHOOSE (1e-18L, 1e-15, 0));
1353 identities3_test (0.2L, CHOOSE (0, 0, 1e-7));
1354 identities3_test (0.9L, CHOOSE (1e-18L, 1e-15, 1e-6));
1355 identities3_test (0, CHOOSE (0, 0, 1e-6));
1356 identities3_test (-1, CHOOSE (1e-18L, 0, 1e-6));
1361 Let's test that basic arithmetic is working
1362 tests: Infinity and NaN
1367 /* variables are declared volatile to forbid some compiler
1369 volatile MATHTYPE Inf_var
, NaN_var
, zero_var
, one_var
;
1374 NaN_var
= nan_value
;
1375 Inf_var
= one_var
/ zero_var
;
1377 this_does_nothing ();
1379 check_isinfp ("isinf (1/0) == +1", Inf_var
);
1380 check_isinfn ("isinf (-1/0) == -1", -Inf_var
);
1381 check_bool ("!isinf (1)", !(FUNC(isinf
) (one_var
)));
1382 check_bool ("!isinf (0/0)", !(FUNC(isinf
) (NaN_var
)));
1384 check_isnan ("isnan (0/0)", NaN_var
);
1385 check_isnan ("isnan (-(0/0))", -NaN_var
);
1386 check_bool ("!isnan (1)", !(FUNC(isnan
) (one_var
)));
1387 check_bool ("!isnan (0/0)", !(FUNC(isnan
) (Inf_var
)));
1389 check_bool ("inf == inf", Inf_var
== Inf_var
);
1390 check_bool ("-inf == -inf", -Inf_var
== -Inf_var
);
1391 check_bool ("inf != -inf", Inf_var
!= -Inf_var
);
1392 check_bool ("NaN != NaN", NaN_var
!= NaN_var
);
1395 the same tests but this time with NAN from <nan.h>
1396 NAN is a double const
1398 check_bool ("isnan (NAN)", isnan (NAN
));
1399 check_bool ("isnan (-NAN)", isnan (-NAN
));
1400 check_bool ("!isinf (NAN)", !(isinf (NAN
)));
1401 check_bool ("!isinf (-NAN)", !(isinf (-NAN
)));
1402 check_bool ("NAN != NAN", NAN
!= NAN
);
1404 /* test if EPSILON is ok */
1405 x1
= MATHCONST (1.0);
1406 x2
= x1
+ CHOOSE (LDBL_EPSILON
, DBL_EPSILON
, FLT_EPSILON
);
1407 check_bool ("1 != 1+EPSILON", x1
!= x2
);
1409 x1
= MATHCONST (1.0);
1410 x2
= x1
- CHOOSE (LDBL_EPSILON
, DBL_EPSILON
, FLT_EPSILON
);
1411 check_bool ("1 != 1-EPSILON", x1
!= x2
);
1413 /* test if HUGE_VALx is ok */
1414 x1
= CHOOSE (HUGE_VALL
, HUGE_VAL
, HUGE_VALF
);
1415 check_bool ("isinf (HUGE_VALx) == +1", ISINF (x1
) == +1);
1416 x1
= -CHOOSE (HUGE_VALL
, HUGE_VAL
, HUGE_VALF
);
1417 check_bool ("isinf (-HUGE_VALx) == -1", ISINF (x1
) == -1);
1426 nan_value
= plus_zero
/ plus_zero
; /* Suppress GCC warning */
1428 minus_zero
= copysign (0.0, -1.0);
1429 plus_infty
= CHOOSE (HUGE_VALL
, HUGE_VAL
, HUGE_VALF
);
1430 minus_infty
= -CHOOSE (HUGE_VALL
, HUGE_VAL
, HUGE_VALF
);
1432 /* Test to make sure we start correctly. */
1433 fpstack_test ("*init*");
1437 static struct option long_options
[] =
1439 {"verbose", optional_argument
, NULL
, 'v'},
1440 {"silent", no_argument
, NULL
, 's'},
1446 parse_options (int argc
, char *argv
[])
1455 c
= getopt_long (argc
, argv
, "vs",
1456 long_options
, &option_index
);
1458 /* Detect the end of the options. */
1466 verbose
= (unsigned int) strtoul (optarg
, NULL
, 0);
1480 main (int argc
, char *argv
[])
1482 parse_options (argc
, argv
);
1500 #ifdef ISO_9X_IMPLEMENTED
1509 #ifdef ISO_9X_IMPLEMENTED
1525 inverse_functions ();
1529 printf ("\n%d errors occured.\n", noErrors
);
1532 printf ("\n All tests passed sucessfully.\n");