1 /*
2     Copyright (C) 2016 Pascal Molin
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 static void
_acb_unit_root(acb_t res,ulong order,slong prec)15 _acb_unit_root(acb_t res, ulong order, slong prec)
16 {
17     fmpq_t t;
18     fmpq_init(t);
19     fmpq_set_si(t, 2, order);
20     arb_sin_cos_pi_fmpq(acb_imagref(res), acb_realref(res), t, prec);
21     fmpq_clear(t);
22 }
23 
24 void
acb_unit_root(acb_t res,ulong order,slong prec)25 acb_unit_root(acb_t res, ulong order, slong prec)
26 {
27     switch (order)
28     {
29        case 1:
30            acb_one(res);
31            break;
32        case 2:
33            acb_set_si(res, -1);
34            break;
35        case 4:
36            acb_onei(res);
37            break;
38        default:
39            _acb_unit_root(res, order, prec);
40            break;
41     }
42 }
43