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_root_ui(acb_t res,const acb_t z,ulong n,slong prec)15 acb_root_ui(acb_t res, const acb_t z, ulong n, slong prec)
16 {
17 if (n == 0)
18 {
19 acb_indeterminate(res);
20 }
21 else if (n == 1)
22 {
23 acb_set_round(res, z, prec);
24 }
25 else if (n == 2)
26 {
27 acb_sqrt(res, z, prec);
28 }
29 else if (n == 4)
30 {
31 acb_sqrt(res, z, prec + 4);
32 acb_sqrt(res, res, prec);
33 }
34 else if (acb_is_real(z) && arb_is_nonnegative(acb_realref(z)))
35 {
36 arb_root(acb_realref(res), acb_realref(z), n, prec);
37 arb_zero(acb_imagref(res));
38 }
39 else
40 {
41 acb_log(res, z, prec + 4);
42 acb_div_ui(res, res, n, prec + 4);
43 acb_exp(res, res, prec);
44 }
45 }
46
47