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 "acb_poly.h"
13 
14 void
_acb_poly_pow_ui(acb_ptr res,acb_srcptr f,slong flen,ulong exp,slong prec)15 _acb_poly_pow_ui(acb_ptr res, acb_srcptr f, slong flen, ulong exp, slong prec)
16 {
17     _acb_poly_pow_ui_trunc_binexp(res, f, flen, exp, exp * (flen - 1) + 1, prec);
18 }
19 
20 void
acb_poly_pow_ui(acb_poly_t res,const acb_poly_t poly,ulong exp,slong prec)21 acb_poly_pow_ui(acb_poly_t res,
22     const acb_poly_t poly, ulong exp, slong prec)
23 {
24     slong flen, rlen;
25 
26     flen = poly->length;
27 
28     if (exp == 0)
29     {
30         acb_poly_one(res);
31     }
32     else if (flen == 0)
33     {
34         acb_poly_zero(res);
35     }
36     else
37     {
38         rlen = exp * (flen - 1) + 1;
39 
40         if (res != poly)
41         {
42             acb_poly_fit_length(res, rlen);
43             _acb_poly_pow_ui(res->coeffs,
44                 poly->coeffs, flen, exp, prec);
45             _acb_poly_set_length(res, rlen);
46             _acb_poly_normalise(res);
47         }
48         else
49         {
50             acb_poly_t t;
51             acb_poly_init2(t, rlen);
52             _acb_poly_pow_ui(t->coeffs,
53                 poly->coeffs, flen, exp, prec);
54             _acb_poly_set_length(t, rlen);
55             _acb_poly_normalise(t);
56             acb_poly_swap(res, t);
57             acb_poly_clear(t);
58         }
59     }
60 }
61 
62