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_cot_pi(acb_t r,const acb_t z,slong prec)15 acb_cot_pi(acb_t r, const acb_t z, slong prec)
16 {
17     if (arb_is_zero(acb_imagref(z)))
18     {
19         arb_cot_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_coth(acb_imagref(r), t, prec);
29         arb_neg(acb_imagref(r), acb_imagref(r));
30         arb_zero(acb_realref(r));
31         arb_clear(t);
32     }
33     else
34     {
35         acb_t t;
36         acb_init(t);
37 
38         if (arf_cmpabs_2exp_si(arb_midref(acb_imagref(z)), 0) < 0)
39         {
40             acb_sin_cos_pi(r, t, z, prec + 4);
41             acb_div(r, t, r, prec);
42         }
43         else
44         {
45             acb_mul_2exp_si(t, z, 1);
46 
47             if (arf_sgn(arb_midref(acb_imagref(z))) > 0)
48             {
49                 acb_exp_pi_i(t, t, prec + 4);
50                 acb_sub_ui(r, t, 1, prec + 4);
51                 acb_div(r, t, r, prec + 4);
52                 acb_mul_2exp_si(r, r, 1);
53                 acb_sub_ui(r, r, 1, prec);
54                 acb_mul_onei(r, r);
55             }
56             else
57             {
58                 acb_neg(t, t);
59                 acb_exp_pi_i(t, t, prec + 4);
60                 acb_sub_ui(r, t, 1, prec + 4);
61                 acb_div(r, t, r, prec + 4);
62                 acb_mul_2exp_si(r, r, 1);
63                 acb_sub_ui(r, r, 1, prec);
64                 acb_div_onei(r, r);
65             }
66         }
67 
68         acb_clear(t);
69     }
70 }
71 
72