1 /*
2 Copyright (C) 2008, 2009 William Hart
3 Copyright (C) 2010 Sebastian Pancratz
4 Copyright (C) 2013 Fredrik Johansson
5
6 This file is part of Arb.
7
8 Arb is free software: you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License (LGPL) as published
10 by the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version. See <http://www.gnu.org/licenses/>.
12 */
13
14 #include "acb_poly.h"
15
16 void
_acb_poly_shift_right(acb_ptr res,acb_srcptr poly,slong len,slong n)17 _acb_poly_shift_right(acb_ptr res, acb_srcptr poly, slong len, slong n)
18 {
19 slong i;
20
21 /* Copy in forward order to avoid writing over unshifted coefficients */
22 if (res != poly)
23 {
24 for (i = 0; i < len - n; i++)
25 acb_set(res + i, poly + n + i);
26 }
27 else
28 {
29 for (i = 0; i < len - n; i++)
30 acb_swap(res + i, res + n + i);
31 }
32
33 }
34
35 void
acb_poly_shift_right(acb_poly_t res,const acb_poly_t poly,slong n)36 acb_poly_shift_right(acb_poly_t res, const acb_poly_t poly, slong n)
37 {
38 if (n == 0)
39 {
40 acb_poly_set(res, poly);
41 return;
42 }
43
44 if (poly->length <= n)
45 {
46 acb_poly_zero(res);
47 return;
48 }
49
50 acb_poly_fit_length(res, poly->length - n);
51 _acb_poly_shift_right(res->coeffs, poly->coeffs, poly->length, n);
52 _acb_poly_set_length(res, poly->length - n);
53 }
54
55