1 /*
2 Copyright (C) 2012 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_log(acb_t r,const acb_t z,slong prec)15 acb_log(acb_t r, const acb_t z, slong prec)
16 {
17 #define a acb_realref(z)
18 #define b acb_imagref(z)
19
20 if (arb_is_zero(b))
21 {
22 if (arb_is_positive(a))
23 {
24 arb_log(acb_realref(r), a, prec);
25 arb_zero(acb_imagref(r));
26 }
27 else if (arb_is_negative(a))
28 {
29 arb_neg(acb_realref(r), a);
30 arb_log(acb_realref(r), acb_realref(r), prec);
31 arb_const_pi(acb_imagref(r), prec);
32 }
33 else
34 {
35 acb_indeterminate(r);
36 }
37 }
38 else if (arb_is_zero(a))
39 {
40 if (arb_is_positive(b))
41 {
42 arb_log(acb_realref(r), b, prec);
43 arb_const_pi(acb_imagref(r), prec);
44 arb_mul_2exp_si(acb_imagref(r), acb_imagref(r), -1);
45 }
46 else if (arb_is_negative(b))
47 {
48 arb_neg(acb_realref(r), b);
49 arb_log(acb_realref(r), acb_realref(r), prec);
50 arb_const_pi(acb_imagref(r), prec);
51 arb_mul_2exp_si(acb_imagref(r), acb_imagref(r), -1);
52 arb_neg(acb_imagref(r), acb_imagref(r));
53 }
54 else
55 {
56 acb_indeterminate(r);
57 }
58 }
59 else
60 {
61 if (r != z)
62 {
63 arb_log_hypot(acb_realref(r), a, b, prec);
64 if (arb_is_finite(acb_realref(r)))
65 arb_atan2(acb_imagref(r), b, a, prec);
66 else
67 arb_indeterminate(acb_imagref(r));
68 }
69 else
70 {
71 arb_t t;
72 arb_init(t);
73 arb_log_hypot(t, a, b, prec);
74 if (arb_is_finite(t))
75 arb_atan2(acb_imagref(r), b, a, prec);
76 else
77 arb_indeterminate(acb_imagref(r));
78 arb_swap(acb_realref(r), t);
79 arb_clear(t);
80 }
81 }
82 #undef a
83 #undef b
84 }
85
86 void
acb_log_analytic(acb_ptr res,const acb_t z,int analytic,slong prec)87 acb_log_analytic(acb_ptr res, const acb_t z, int analytic, slong prec)
88 {
89 if (analytic && arb_contains_zero(acb_imagref(z)) &&
90 !arb_is_positive(acb_realref(z)))
91 {
92 acb_indeterminate(res);
93 }
94 else
95 {
96 acb_log(res, z, prec);
97 }
98 }
99
100