1 /*
2     Copyright (C) 2015 Fredrik Johansson
3 
4     This file is part of Arb.
5 
6     Arb is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include "acb.h"
13 
14 void
acb_tan_pi(acb_t r,const acb_t z,slong prec)15 acb_tan_pi(acb_t r, const acb_t z, slong prec)
16 {
17     if (arb_is_zero(acb_imagref(z)))
18     {
19         arb_tan_pi(acb_realref(r), acb_realref(z), prec);
20         arb_zero(acb_imagref(r));
21     }
22     else if (arb_is_zero(acb_realref(z)))
23     {
24         arb_t t;
25         arb_init(t);
26         arb_const_pi(t, prec + 4);
27         arb_mul(t, acb_imagref(z), t, prec + 4);
28         arb_tanh(acb_imagref(r), t, prec);
29         arb_zero(acb_realref(r));
30         arb_clear(t);
31     }
32     else
33     {
34         acb_t t;
35         acb_init(t);
36 
37         if (arf_cmpabs_2exp_si(arb_midref(acb_imagref(z)), 0) < 0)
38         {
39             acb_sin_cos_pi(r, t, z, prec + 4);
40             acb_div(r, r, t, prec);
41         }
42         else
43         {
44             acb_mul_2exp_si(t, z, 1);
45 
46             if (arf_sgn(arb_midref(acb_imagref(z))) > 0)
47             {
48                 acb_exp_pi_i(t, t, prec + 4);
49                 acb_add_ui(r, t, 1, prec + 4);
50                 acb_div(r, t, r, prec + 4);
51                 acb_mul_2exp_si(r, r, 1);
52                 acb_sub_ui(r, r, 1, prec);
53                 acb_div_onei(r, r);
54             }
55             else
56             {
57                 acb_neg(t, t);
58                 acb_exp_pi_i(t, t, prec + 4);
59                 acb_add_ui(r, t, 1, prec + 4);
60                 acb_div(r, t, r, prec + 4);
61                 acb_mul_2exp_si(r, r, 1);
62                 acb_sub_ui(r, r, 1, prec);
63                 acb_mul_onei(r, r);
64             }
65         }
66 
67         acb_clear(t);
68     }
69 }
70 
71