1 /*
2 Copyright (C) 2013 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 "arb.h"
13
14 void
arb_sech(arb_t res,const arb_t x,slong prec)15 arb_sech(arb_t res, const arb_t x, slong prec)
16 {
17 if (arf_cmpabs_2exp_si(arb_midref(x), 0) > 0)
18 {
19 arb_t t;
20 arb_init(t);
21
22 if (arf_sgn(arb_midref(x)) > 0)
23 {
24 arb_neg(t, x);
25 arb_exp(t, t, prec + 4);
26 }
27 else
28 {
29 arb_exp(t, x, prec + 4);
30 }
31
32 arb_mul(res, t, t, prec + 4);
33 arb_add_ui(res, res, 1, prec + 4);
34 arb_div(res, t, res, prec);
35 arb_mul_2exp_si(res, res, 1);
36 arb_clear(t);
37 }
38 else
39 {
40 arb_cosh(res, x, prec + 4);
41 arb_inv(res, res, prec);
42 }
43 }
44
45