1 /*
2     Copyright (C) 2012 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 
_acb_poly_mul(acb_ptr C,acb_srcptr A,slong lenA,acb_srcptr B,slong lenB,slong prec)14 void _acb_poly_mul(acb_ptr C,
15     acb_srcptr A, slong lenA,
16     acb_srcptr B, slong lenB, slong prec)
17 {
18     _acb_poly_mullow(C, A, lenA, B, lenB, lenA + lenB - 1, prec);
19 }
20 
21 void
acb_poly_mul(acb_poly_t res,const acb_poly_t poly1,const acb_poly_t poly2,slong prec)22 acb_poly_mul(acb_poly_t res, const acb_poly_t poly1,
23               const acb_poly_t poly2, slong prec)
24 {
25     slong len_out;
26 
27     if ((poly1->length == 0) || (poly2->length == 0))
28     {
29         acb_poly_zero(res);
30         return;
31     }
32 
33     len_out = poly1->length + poly2->length - 1;
34 
35     if (res == poly1 || res == poly2)
36     {
37         acb_poly_t temp;
38         acb_poly_init2(temp, len_out);
39         _acb_poly_mul(temp->coeffs, poly1->coeffs, poly1->length,
40                                  poly2->coeffs, poly2->length, prec);
41         acb_poly_swap(res, temp);
42         acb_poly_clear(temp);
43     }
44     else
45     {
46         acb_poly_fit_length(res, len_out);
47         _acb_poly_mul(res->coeffs, poly1->coeffs, poly1->length,
48                                  poly2->coeffs, poly2->length, prec);
49     }
50 
51     _acb_poly_set_length(res, len_out);
52     _acb_poly_normalise(res);
53 }
54 
55