xref: /netbsd-src/external/lgpl3/mpfr/dist/tests/tcsch.c (revision ba125506a622fe649968631a56eba5d42ff57863)
1efee5258Smrg /* Test file for mpfr_csch.
2efee5258Smrg 
3*ba125506Smrg Copyright 2005-2023 Free Software Foundation, Inc.
4efdec83bSmrg Contributed by the AriC and Caramba projects, INRIA.
5efee5258Smrg 
6efee5258Smrg This file is part of the GNU MPFR Library.
7efee5258Smrg 
8efee5258Smrg The GNU MPFR Library is free software; you can redistribute it and/or modify
9efee5258Smrg it under the terms of the GNU Lesser General Public License as published by
10efee5258Smrg the Free Software Foundation; either version 3 of the License, or (at your
11efee5258Smrg option) any later version.
12efee5258Smrg 
13efee5258Smrg The GNU MPFR Library is distributed in the hope that it will be useful, but
14efee5258Smrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15efee5258Smrg or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16efee5258Smrg License for more details.
17efee5258Smrg 
18efee5258Smrg You should have received a copy of the GNU Lesser General Public License
19efee5258Smrg along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
202ba2404bSmrg https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21efee5258Smrg 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
22efee5258Smrg 
23efee5258Smrg #include "mpfr-test.h"
24efee5258Smrg 
25efee5258Smrg #define TEST_FUNCTION mpfr_csch
26efee5258Smrg #define TEST_RANDOM_EMAX 63
27efee5258Smrg #include "tgeneric.c"
28efee5258Smrg 
29efee5258Smrg static void
check_specials(void)30efee5258Smrg check_specials (void)
31efee5258Smrg {
32efee5258Smrg   mpfr_t  x, y;
33efee5258Smrg 
34efee5258Smrg   mpfr_init2 (x, 123L);
35efee5258Smrg   mpfr_init2 (y, 123L);
36efee5258Smrg 
37efee5258Smrg   mpfr_set_nan (x);
38efee5258Smrg   mpfr_csch (y, x, MPFR_RNDN);
39efee5258Smrg   if (! mpfr_nan_p (y))
40efee5258Smrg     {
41efee5258Smrg       printf ("Error: csch(NaN) != NaN\n");
42efee5258Smrg       exit (1);
43efee5258Smrg     }
44efee5258Smrg 
45efee5258Smrg   mpfr_set_inf (x, 1);
46efee5258Smrg   mpfr_csch (y, x, MPFR_RNDN);
47299c6f0cSmrg   if (! (mpfr_zero_p (y) && MPFR_IS_POS (y)))
48efee5258Smrg     {
49efee5258Smrg       printf ("Error: csch(+Inf) != +0\n");
50efee5258Smrg       exit (1);
51efee5258Smrg     }
52efee5258Smrg 
53efee5258Smrg   mpfr_set_inf (x, -1);
54efee5258Smrg   mpfr_csch (y, x, MPFR_RNDN);
55299c6f0cSmrg   if (! (mpfr_zero_p (y) && MPFR_IS_NEG (y)))
56efee5258Smrg     {
57efee5258Smrg       printf ("Error: csch(-0) != -0\n");
58efee5258Smrg       exit (1);
59efee5258Smrg     }
60efee5258Smrg 
61efee5258Smrg   /* csc(+/-0) = +/-Inf */
62efee5258Smrg   mpfr_set_ui (x, 0, MPFR_RNDN);
63efee5258Smrg   mpfr_csch (y, x, MPFR_RNDN);
64efee5258Smrg   if (! (mpfr_inf_p (y) && mpfr_sgn (y) > 0))
65efee5258Smrg     {
66efee5258Smrg       printf ("Error: csch(+0) != +Inf\n");
67efee5258Smrg       exit (1);
68efee5258Smrg     }
69efee5258Smrg   mpfr_neg (x, x, MPFR_RNDN);
70efee5258Smrg   mpfr_csch (y, x, MPFR_RNDN);
71efee5258Smrg   if (! (mpfr_inf_p (y) && mpfr_sgn (y) < 0))
72efee5258Smrg     {
73efee5258Smrg       printf ("Error: csch(-0) != -Inf\n");
74efee5258Smrg       exit (1);
75efee5258Smrg     }
76efee5258Smrg 
77efee5258Smrg   /* check huge x */
78efee5258Smrg   mpfr_set_str (x, "8e8", 10, MPFR_RNDN);
79efee5258Smrg   mpfr_csch (y, x, MPFR_RNDN);
80299c6f0cSmrg   if (! (mpfr_zero_p (y) && MPFR_IS_POS (y)))
81efee5258Smrg     {
82efee5258Smrg       printf ("Error: csch(8e8) != +0\n");
83efee5258Smrg       exit (1);
84efee5258Smrg     }
85efee5258Smrg   mpfr_set_str (x, "-8e8", 10, MPFR_RNDN);
86efee5258Smrg   mpfr_csch (y, x, MPFR_RNDN);
87299c6f0cSmrg   if (! (mpfr_zero_p (y) && MPFR_IS_NEG (y)))
88efee5258Smrg     {
89efee5258Smrg       printf ("Error: csch(-8e8) != -0\n");
90efee5258Smrg       exit (1);
91efee5258Smrg     }
92efee5258Smrg 
93efee5258Smrg   mpfr_clear (x);
94efee5258Smrg   mpfr_clear (y);
95efee5258Smrg }
96efee5258Smrg 
97efee5258Smrg int
main(int argc,char * argv[])98efee5258Smrg main (int argc, char *argv[])
99efee5258Smrg {
100efee5258Smrg   tests_start_mpfr ();
101efee5258Smrg 
102efee5258Smrg   check_specials ();
103299c6f0cSmrg   test_generic (MPFR_PREC_MIN, 200, 10);
104efee5258Smrg 
105efee5258Smrg   tests_end_mpfr ();
106efee5258Smrg   return 0;
107efee5258Smrg }
108