1 /*
2 Copyright (C) 2017 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_expm1(acb_t res,const acb_t z,slong prec)15 acb_expm1(acb_t res, const acb_t z, slong prec)
16 {
17 if (acb_is_real(z))
18 {
19 arb_expm1(acb_realref(res), acb_realref(z), prec);
20 arb_zero(acb_imagref(res));
21 }
22 else if (arf_cmpabs_2exp_si(arb_midref(acb_realref(z)), -3) <= 0 &&
23 arf_cmpabs_2exp_si(arb_midref(acb_imagref(z)), -3) <= 0 &&
24 arf_cmpabs_2exp_si(arb_midref(acb_realref(z)), -3) <= 0 &&
25 arf_cmpabs_2exp_si(arb_midref(acb_imagref(z)), -3) <= 0)
26 {
27 arf_srcptr midmax;
28 slong extra;
29
30 if (arf_cmpabs(arb_midref(acb_realref(z)), arb_midref(acb_imagref(z))) >= 0)
31 midmax = arb_midref(acb_realref(z));
32 else
33 midmax = arb_midref(acb_imagref(z));
34
35 if (arf_cmpabs_2exp_si(arb_midref(acb_realref(z)), -prec - 100) > 0)
36 {
37 extra = -ARF_EXP(midmax);
38 extra = FLINT_MIN(extra, prec + 100);
39 extra = FLINT_MAX(extra, 0);
40 acb_exp(res, z, prec + extra + 4);
41 acb_sub_ui(res, res, 1, prec);
42 }
43 else
44 {
45 /* lazy solution: e^z-1 = 4 (sinh(z/4)+cosh(z/4))^2 sinh(z/4) cosh(z/4) */
46 acb_t t, u;
47 acb_init(t);
48 acb_init(u);
49 acb_mul_2exp_si(t, z, -2);
50 acb_sinh_cosh(t, u, t, prec + 4);
51 acb_add(res, t, u, prec + 4);
52 acb_mul(res, res, res, prec + 4);
53 acb_mul(t, t, u, prec + 4);
54 acb_mul(res, res, t, prec);
55 acb_mul_2exp_si(res, res, 2);
56 acb_clear(t);
57 acb_clear(u);
58 }
59 }
60 else
61 {
62 acb_exp(res, z, prec + 4);
63 acb_sub_ui(res, res, 1, prec);
64 }
65 }
66
67