1 /* test file for mpc_tan.
3 Copyright (C) 2008 Philippe Th\'eveny, Paul Zimmermann, Andreas Enge
5 This file is part of the MPC Library.
7 The MPC Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
12 The MPC Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the MPC Library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
23 #include "mpc-tests.h"
26 test_failed (mpc_t op, mpc_t get, mpc_t expected)
28 printf ("mpc_tan(op) failed\n with ");
37 pure_real_argument (void)
39 /* tan(x -i*0) = tan(x) -i*0 */
40 /* tan(x +i*0) = tan(x) +i*0 */
47 mpfr_init2 (tan_x, 113);
49 mpc_init2 (tan_z, 113);
51 /* tan(1 +i*0) = tan(1) +i*0 */
52 mpc_set_ui_ui (z, 1, 0, MPC_RNDNN);
53 mpfr_set_ui (x, 1, GMP_RNDN);
54 mpfr_tan (tan_x, x, GMP_RNDN);
55 mpc_tan (tan_z, z, MPC_RNDNN);
56 if (mpfr_cmp (MPC_RE (tan_z), tan_x) != 0
57 || !mpfr_zero_p (MPC_IM (tan_z)) || mpfr_signbit (MPC_IM (tan_z)))
59 printf ("mpc_tan(1 + i * 0) failed\n");
63 /* tan(1 -i*0) = tan(1) -i*0 */
64 mpc_conj (z, z, MPC_RNDNN);
65 mpc_tan (tan_z, z, MPC_RNDNN);
66 if (mpfr_cmp (MPC_RE (tan_z), tan_x) != 0
67 || !mpfr_zero_p (MPC_IM (tan_z)) || !mpfr_signbit (MPC_IM (tan_z)))
69 printf ("mpc_tan(1 - i * 0) failed\n");
73 /* tan(Pi/2 +i*0) = +Inf +i*0 */
74 mpfr_const_pi (x, GMP_RNDN);
75 mpfr_div_2ui (x, x, 1, GMP_RNDN);
76 mpfr_set (MPC_RE (z), x, GMP_RNDN);
77 mpfr_set_ui (MPC_IM (z), 0, GMP_RNDN);
78 mpfr_tan (tan_x, x, GMP_RNDN);
79 mpc_tan (tan_z, z, MPC_RNDNN);
80 if (mpfr_cmp (MPC_RE (tan_z), tan_x) != 0
81 || !mpfr_zero_p (MPC_IM (tan_z)) || mpfr_signbit (MPC_IM (tan_z)))
83 printf ("mpc_tan(Pi/2 + i * 0) failed\n");
87 /* tan(Pi/2 -i*0) = +Inf -i*0 */
88 mpc_conj (z, z, MPC_RNDNN);
89 mpc_tan (tan_z, z, MPC_RNDNN);
90 if (mpfr_cmp (MPC_RE (tan_z), tan_x) != 0
91 || !mpfr_zero_p (MPC_IM (tan_z)) || !mpfr_signbit (MPC_IM (tan_z)))
93 printf ("mpc_tan(Pi/2 - i * 0) failed\n");
97 /* tan(-Pi/2 +i*0) = -Inf +i*0 */
98 mpfr_neg (x, x, GMP_RNDN);
99 mpc_neg (z, z, MPC_RNDNN);
100 mpfr_tan (tan_x, x, GMP_RNDN);
101 mpc_tan (tan_z, z, MPC_RNDNN);
102 if (mpfr_cmp (MPC_RE (tan_z), tan_x) != 0
103 || !mpfr_zero_p (MPC_IM (tan_z)) || mpfr_signbit (MPC_IM (tan_z)))
105 printf ("mpc_tan(-Pi/2 + i * 0) failed\n");
109 /* tan(-Pi/2 -i*0) = -Inf -i*0 */
110 mpc_conj (z, z, MPC_RNDNN);
111 mpc_tan (tan_z, z, MPC_RNDNN);
112 if (mpfr_cmp (MPC_RE (tan_z), tan_x) != 0
113 || !mpfr_zero_p (MPC_IM (tan_z)) || !mpfr_signbit (MPC_IM (tan_z)))
115 printf ("mpc_tan(-Pi/2 - i * 0) failed\n");
126 pure_imaginary_argument (void)
128 /* tan(-0 +i*y) = -0 +i*tanh(y) */
129 /* tan(+0 +i*y) = +0 +i*tanh(y) */
134 mp_prec_t prec = (mp_prec_t) 111;
137 mpfr_init2 (tanh_y, prec);
139 mpc_init2 (tan_z, prec);
141 /* tan(0 +i) = +0 +i*tanh(1) */
142 mpc_set_ui_ui (z, 0, 1, MPC_RNDNN);
143 mpfr_set_ui (y, 1, GMP_RNDN);
144 mpfr_tanh (tanh_y, y, GMP_RNDN);
145 mpc_tan (tan_z, z, MPC_RNDNN);
146 if (mpfr_cmp (MPC_IM (tan_z), tanh_y) != 0
147 || !mpfr_zero_p (MPC_RE (tan_z)) || mpfr_signbit (MPC_RE (tan_z)))
151 mpc_init2 (c99, prec);
152 mpfr_set_ui (MPC_RE (c99), 0, GMP_RNDN);
153 mpfr_set (MPC_IM (c99), tanh_y, GMP_RNDN);
155 test_failed (z, tan_z, c99);
158 /* tan(0 -i) = +0 +i*tanh(-1) */
159 mpc_conj (z, z, MPC_RNDNN);
160 mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
161 mpc_tan (tan_z, z, MPC_RNDNN);
162 if (mpfr_cmp (MPC_IM (tan_z), tanh_y) != 0
163 || !mpfr_zero_p (MPC_RE (tan_z)) || mpfr_signbit (MPC_RE (tan_z)))
167 mpc_init2 (c99, prec);
168 mpfr_set_ui (MPC_RE (c99), 0, GMP_RNDN);
169 mpfr_set (MPC_IM (c99), tanh_y, GMP_RNDN);
171 test_failed (z, tan_z, c99);
174 /* tan(-0 +i) = -0 +i*tanh(1) */
175 mpc_neg (z, z, MPC_RNDNN);
176 mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
177 mpc_tan (tan_z, z, MPC_RNDNN);
178 if (mpfr_cmp (MPC_IM (tan_z), tanh_y) != 0
179 || !mpfr_zero_p (MPC_RE (tan_z)) || !mpfr_signbit (MPC_RE (tan_z)))
183 mpc_init2 (c99, prec);
184 mpfr_set_ui (MPC_RE (c99), 0, GMP_RNDN);
185 mpfr_set (MPC_IM (c99), tanh_y, GMP_RNDN);
187 test_failed (z, tan_z, c99);
190 /* tan(-0 -i) = -0 +i*tanh(-1) */
191 mpc_conj (z, z, MPC_RNDNN);
192 mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
193 mpc_tan (tan_z, z, MPC_RNDNN);
194 if (mpfr_cmp (MPC_IM (tan_z), tanh_y) != 0
195 || !mpfr_zero_p (MPC_RE (tan_z)) || !mpfr_signbit (MPC_RE (tan_z)))
199 mpc_init2 (c99, prec);
200 mpfr_set_ui (MPC_RE (c99), 0, GMP_RNDN);
201 mpfr_set (MPC_IM (c99), tanh_y, GMP_RNDN);
203 test_failed (z, tan_z, c99);
220 mpc_init2 (tan_z, 53);
223 /* Let's play around the poles */
224 /* x = Re(z) = Pi/2 rounded to nearest to 53 bits precision */
225 /* y = Im(z) = Pi/2 - Re(z) rounded to nearest to 53 bits precision */
226 mpfr_set_str (MPC_RE (z), "3243F6A8885A30p-53", 16, GMP_RNDN);
227 mpfr_set_str (MPC_IM (z), "11A62633145C07p-106", 16, GMP_RNDN);
228 mpfr_set_str (MPC_RE (t), "1D02967C31CDB5", 16, GMP_RNDN);
229 mpfr_set_str (MPC_IM (t), "1D02967C31CDB5", 16, GMP_RNDN);
230 mpc_tan (tan_z, z, MPC_RNDNN);
231 if (mpc_cmp (tan_z, t) != 0)
232 test_failed (z, tan_z, t);
234 mpfr_set_str (MPC_RE (t), "1D02967C31CDB4", 16, GMP_RNDN);
235 mpc_tan (tan_z, z, MPC_RNDDU);
236 if (mpc_cmp (tan_z, t) != 0)
237 test_failed (z, tan_z, t);
239 mpfr_set_str (MPC_IM (t), "1D02967C31CDB4", 16, GMP_RNDN);
240 mpc_tan (tan_z, z, MPC_RNDZD);
241 if (mpc_cmp (tan_z, t) != 0)
242 test_failed (z, tan_z, t);
244 /* Re(z) = x + 2^(-52) */
245 /* Im(z) = y - 2^(-52) */
246 mpfr_set_str (MPC_RE (z), "1921FB54442D19p-52", 16, GMP_RNDN);
247 mpfr_set_str (MPC_IM (z), "-172CECE675D1FDp-105", 16, GMP_RNDN);
248 mpfr_set_str (MPC_RE (t), "-B0BD0AA4A3B3D", 16, GMP_RNDN);
249 mpfr_set_str (MPC_IM (t), "-B0BD0AA4A3B3D", 16, GMP_RNDN);
250 mpc_tan (tan_z, z, MPC_RNDNN);
251 if (mpc_cmp (tan_z, t) != 0)
252 test_failed (z, tan_z, t);
262 DECL_FUNC (CC, f, mpc_tan);
266 data_check (f, "tan.dat");
267 tgeneric (f, 2, 512, 7, 4);
269 pure_real_argument ();
270 pure_imaginary_argument ();