1 /*
2     Copyright (C) 2016 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 
15 void
acb_poly_set_trunc_round(acb_poly_t res,const acb_poly_t poly,slong n,slong prec)16 acb_poly_set_trunc_round(acb_poly_t res, const acb_poly_t poly, slong n, slong prec)
17 {
18     if (poly == res)
19     {
20         acb_poly_truncate(res, n);
21         _acb_vec_set_round(res->coeffs, res->coeffs, res->length, prec);
22     }
23     else
24     {
25         slong rlen;
26 
27         rlen = FLINT_MIN(n, poly->length);
28         while (rlen > 0 && acb_is_zero(poly->coeffs + rlen - 1))
29             rlen--;
30 
31         acb_poly_fit_length(res, rlen);
32         _acb_vec_set_round(res->coeffs, poly->coeffs, rlen, prec);
33         _acb_poly_set_length(res, rlen);
34     }
35 }
36 
37