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