1 /* ttan -- test file for mpc_tan.
3 Copyright (C) 2008, 2011 INRIA
5 This file is part of GNU MPC.
7 GNU MPC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/ .
22 #include "mpc-tests.h"
25 pure_real_argument (void)
27 /* tan(x -i*0) = tan(x) -i*0 */
28 /* tan(x +i*0) = tan(x) +i*0 */
35 mpfr_init2 (tan_x, 113);
37 mpc_init2 (tan_z, 113);
39 /* tan(1 +i*0) = tan(1) +i*0 */
40 mpc_set_ui_ui (z, 1, 0, MPC_RNDNN);
41 mpfr_set_ui (x, 1, GMP_RNDN);
42 mpfr_tan (tan_x, x, GMP_RNDN);
43 mpc_tan (tan_z, z, MPC_RNDNN);
44 if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
45 || !mpfr_zero_p (mpc_imagref (tan_z)) || mpfr_signbit (mpc_imagref (tan_z)))
47 printf ("mpc_tan(1 + i * 0) failed\n");
51 /* tan(1 -i*0) = tan(1) -i*0 */
52 mpc_conj (z, z, MPC_RNDNN);
53 mpc_tan (tan_z, z, MPC_RNDNN);
54 if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
55 || !mpfr_zero_p (mpc_imagref (tan_z)) || !mpfr_signbit (mpc_imagref (tan_z)))
57 printf ("mpc_tan(1 - i * 0) failed\n");
61 /* tan(Pi/2 +i*0) = +Inf +i*0 */
62 mpfr_const_pi (x, GMP_RNDN);
63 mpfr_div_2ui (x, x, 1, GMP_RNDN);
64 mpfr_set (mpc_realref (z), x, GMP_RNDN);
65 mpfr_set_ui (mpc_imagref (z), 0, GMP_RNDN);
66 mpfr_tan (tan_x, x, GMP_RNDN);
67 mpc_tan (tan_z, z, MPC_RNDNN);
68 if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
69 || !mpfr_zero_p (mpc_imagref (tan_z)) || mpfr_signbit (mpc_imagref (tan_z)))
71 printf ("mpc_tan(Pi/2 + i * 0) failed\n");
75 /* tan(Pi/2 -i*0) = +Inf -i*0 */
76 mpc_conj (z, z, MPC_RNDNN);
77 mpc_tan (tan_z, z, MPC_RNDNN);
78 if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
79 || !mpfr_zero_p (mpc_imagref (tan_z)) || !mpfr_signbit (mpc_imagref (tan_z)))
81 printf ("mpc_tan(Pi/2 - i * 0) failed\n");
85 /* tan(-Pi/2 +i*0) = -Inf +i*0 */
86 mpfr_neg (x, x, GMP_RNDN);
87 mpc_neg (z, z, MPC_RNDNN);
88 mpfr_tan (tan_x, x, GMP_RNDN);
89 mpc_tan (tan_z, z, MPC_RNDNN);
90 if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
91 || !mpfr_zero_p (mpc_imagref (tan_z)) || mpfr_signbit (mpc_imagref (tan_z)))
93 printf ("mpc_tan(-Pi/2 + i * 0) failed\n");
97 /* tan(-Pi/2 -i*0) = -Inf -i*0 */
98 mpc_conj (z, z, MPC_RNDNN);
99 mpc_tan (tan_z, z, MPC_RNDNN);
100 if (mpfr_cmp (mpc_realref (tan_z), tan_x) != 0
101 || !mpfr_zero_p (mpc_imagref (tan_z)) || !mpfr_signbit (mpc_imagref (tan_z)))
103 printf ("mpc_tan(-Pi/2 - i * 0) failed\n");
114 pure_imaginary_argument (void)
116 /* tan(-0 +i*y) = -0 +i*tanh(y) */
117 /* tan(+0 +i*y) = +0 +i*tanh(y) */
122 mpfr_prec_t prec = (mpfr_prec_t) 111;
125 mpfr_init2 (tanh_y, prec);
127 mpc_init2 (tan_z, prec);
129 /* tan(0 +i) = +0 +i*tanh(1) */
130 mpc_set_ui_ui (z, 0, 1, MPC_RNDNN);
131 mpfr_set_ui (y, 1, GMP_RNDN);
132 mpfr_tanh (tanh_y, y, GMP_RNDN);
133 mpc_tan (tan_z, z, MPC_RNDNN);
134 if (mpfr_cmp (mpc_imagref (tan_z), tanh_y) != 0
135 || !mpfr_zero_p (mpc_realref (tan_z)) || mpfr_signbit (mpc_realref (tan_z)))
139 mpc_init2 (c99, prec);
140 mpfr_set_ui (mpc_realref (c99), 0, GMP_RNDN);
141 mpfr_set (mpc_imagref (c99), tanh_y, GMP_RNDN);
143 TEST_FAILED ("mpc_tan", z, tan_z, c99, MPC_RNDNN);
146 /* tan(0 -i) = +0 +i*tanh(-1) */
147 mpc_conj (z, z, MPC_RNDNN);
148 mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
149 mpc_tan (tan_z, z, MPC_RNDNN);
150 if (mpfr_cmp (mpc_imagref (tan_z), tanh_y) != 0
151 || !mpfr_zero_p (mpc_realref (tan_z)) || mpfr_signbit (mpc_realref (tan_z)))
155 mpc_init2 (c99, prec);
156 mpfr_set_ui (mpc_realref (c99), 0, GMP_RNDN);
157 mpfr_set (mpc_imagref (c99), tanh_y, GMP_RNDN);
159 TEST_FAILED ("mpc_tan", z, tan_z, c99, MPC_RNDNN);
162 /* tan(-0 +i) = -0 +i*tanh(1) */
163 mpc_neg (z, z, MPC_RNDNN);
164 mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
165 mpc_tan (tan_z, z, MPC_RNDNN);
166 if (mpfr_cmp (mpc_imagref (tan_z), tanh_y) != 0
167 || !mpfr_zero_p (mpc_realref (tan_z)) || !mpfr_signbit (mpc_realref (tan_z)))
171 mpc_init2 (c99, prec);
172 mpfr_set_ui (mpc_realref (c99), 0, GMP_RNDN);
173 mpfr_set (mpc_imagref (c99), tanh_y, GMP_RNDN);
175 TEST_FAILED ("mpc_tan", z, tan_z, c99, MPC_RNDNN);
178 /* tan(-0 -i) = -0 +i*tanh(-1) */
179 mpc_conj (z, z, MPC_RNDNN);
180 mpfr_neg (tanh_y, tanh_y, GMP_RNDN);
181 mpc_tan (tan_z, z, MPC_RNDNN);
182 if (mpfr_cmp (mpc_imagref (tan_z), tanh_y) != 0
183 || !mpfr_zero_p (mpc_realref (tan_z)) || !mpfr_signbit (mpc_realref (tan_z)))
187 mpc_init2 (c99, prec);
188 mpfr_set_ui (mpc_realref (c99), 0, GMP_RNDN);
189 mpfr_set (mpc_imagref (c99), tanh_y, GMP_RNDN);
191 TEST_FAILED ("mpc_tan", z, tan_z, c99, MPC_RNDNN);
203 DECL_FUNC (CC, f, mpc_tan);
207 data_check (f, "tan.dat");
208 tgeneric (f, 2, 512, 7, 4);
210 pure_real_argument ();
211 pure_imaginary_argument ();