1 /* Test file for mpfr_atanh.
2
3 Copyright 2001-2023 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 https://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 "mpfr-test.h"
24
25 #define TEST_FUNCTION mpfr_atanh
26 #define TEST_RANDOM_EMAX 7
27 #include "tgeneric.c"
28
29 static void
special(void)30 special (void)
31 {
32 mpfr_t x, y, z;
33 int i;
34
35 mpfr_init (x);
36 mpfr_init (y);
37
38 MPFR_SET_INF(x);
39 mpfr_set_ui (y, 0, MPFR_RNDN);
40 mpfr_atanh (x, y, MPFR_RNDN);
41 if (MPFR_IS_INF(x) || MPFR_IS_NAN(x) )
42 {
43 printf ("Inf flag not clears in atanh!\n");
44 exit (1);
45 }
46
47 MPFR_SET_NAN(x);
48 mpfr_atanh (x, y, MPFR_RNDN);
49 if (MPFR_IS_NAN(x) || MPFR_IS_INF(x))
50 {
51 printf ("NAN flag not clears in atanh!\n");
52 exit (1);
53 }
54
55 /* atanh(+/-x) = NaN if x > 1 */
56 for (i = 3; i <= 6; i++)
57 {
58 mpfr_set_si (x, i, MPFR_RNDN);
59 mpfr_div_2ui (x, x, 1, MPFR_RNDN);
60 mpfr_atanh (y, x, MPFR_RNDN);
61 if (!mpfr_nan_p (y))
62 {
63 printf ("Error: mpfr_atanh(%d/2) <> NaN\n", i);
64 exit (1);
65 }
66 mpfr_neg (x, x, MPFR_RNDN);
67 mpfr_atanh (y, x, MPFR_RNDN);
68 if (!mpfr_nan_p (y))
69 {
70 printf ("Error: mpfr_atanh(-%d/2) <> NaN\n", i);
71 exit (1);
72 }
73 }
74
75 /* atanh(+0) = +0, atanh(-0) = -0 */
76 mpfr_set_ui (x, 0, MPFR_RNDN);
77 mpfr_atanh (y, x, MPFR_RNDN);
78 if (MPFR_NOTZERO (y) || MPFR_IS_NEG (y))
79 {
80 printf ("Error: mpfr_atanh(+0) <> +0\n");
81 exit (1);
82 }
83 mpfr_neg (x, x, MPFR_RNDN);
84 mpfr_atanh (y, x, MPFR_RNDN);
85 if (MPFR_NOTZERO (y) || MPFR_IS_POS (y))
86 {
87 printf ("Error: mpfr_atanh(-0) <> -0\n");
88 exit (1);
89 }
90
91 MPFR_SET_NAN(x);
92 mpfr_atanh (y, x, MPFR_RNDN);
93 if (!mpfr_nan_p (y))
94 {
95 printf ("Error: mpfr_atanh(NaN) <> NaN\n");
96 exit (1);
97 }
98
99 mpfr_set_inf (x, 1);
100 mpfr_atanh (y, x, MPFR_RNDN);
101 if (!mpfr_nan_p (y))
102 {
103 printf ("Error: mpfr_atanh(+Inf) <> NaN\n");
104 mpfr_dump (y);
105 exit (1);
106 }
107
108 mpfr_set_inf (x, -1);
109 mpfr_atanh (y, x, MPFR_RNDN);
110 if (!mpfr_nan_p (y))
111 {
112 printf ("Error: mpfr_atanh(-Inf) <> NaN\n");
113 exit (1);
114 }
115
116 mpfr_set_ui (x, 1, MPFR_RNDN);
117 mpfr_atanh (y, x, MPFR_RNDN);
118 if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
119 {
120 printf ("Error: mpfr_atanh(1) <> +Inf\n");
121 exit (1);
122 }
123
124 mpfr_set_si (x, -1, MPFR_RNDN);
125 mpfr_atanh (y, x, MPFR_RNDN);
126 if (!mpfr_inf_p (y) || mpfr_sgn (y) > 0)
127 {
128 printf ("Error: mpfr_atanh(-1) <> -Inf\n");
129 exit (1);
130 }
131
132 mpfr_set_prec (x, 32);
133 mpfr_set_prec (y, 32);
134
135 mpfr_set_str_binary (x, "0.10001000001001011000100001E-6");
136 mpfr_atanh (x, x, MPFR_RNDN);
137 mpfr_set_str_binary (y, "0.10001000001001100101010110100001E-6");
138 if (mpfr_cmp (x, y))
139 {
140 printf ("Error: mpfr_atanh (1)\n");
141 exit (1);
142 }
143
144 mpfr_set_str_binary (x, "-0.1101011110111100111010011001011E-1");
145 mpfr_atanh (x, x, MPFR_RNDN);
146 mpfr_set_str_binary (y, "-0.11100110000100001111101100010111E-1");
147 if (mpfr_cmp (x, y))
148 {
149 printf ("Error: mpfr_atanh (2)\n");
150 exit (1);
151 }
152
153 mpfr_set_prec (x, 33);
154 mpfr_set_prec (y, 43);
155 mpfr_set_str_binary (x, "0.111001101100000110011001010000101");
156 mpfr_atanh (y, x, MPFR_RNDZ);
157 mpfr_init2 (z, 43);
158 mpfr_set_str_binary (z, "1.01111010110001101001000000101101011110101");
159 if (mpfr_cmp (y, z))
160 {
161 printf ("Error: mpfr_atanh (3)\n");
162 mpfr_dump (y);
163 exit (1);
164 }
165
166 mpfr_clear (x);
167 mpfr_clear (y);
168 mpfr_clear (z);
169 }
170
171 int
main(int argc,char * argv[])172 main (int argc, char *argv[])
173 {
174 tests_start_mpfr ();
175
176 special ();
177
178 test_generic (MPFR_PREC_MIN, 100, 25);
179
180 data_check ("data/atanh", mpfr_atanh, "mpfr_atanh");
181 bad_cases (mpfr_atanh, mpfr_tanh, "mpfr_atanh", 256, -128, 8,
182 4, 128, 800, 100);
183
184 tests_end_mpfr ();
185 return 0;
186 }
187