1 /*
2     Copyright (C) 2008-2011 William Hart
3 
4     This file is part of FLINT.
5 
6     FLINT 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 <stdlib.h>
13 #include <gmp.h>
14 #include "flint.h"
15 #include "fmpz.h"
16 #include "fmpz_vec.h"
17 #include "fmpz_poly.h"
18 #include "fft.h"
19 
_fmpz_vec_set_fft(fmpz * coeffs_m,slong length,const mp_ptr * coeffs_f,slong limbs,slong sign)20 void _fmpz_vec_set_fft(fmpz * coeffs_m, slong length,
21                           const mp_ptr * coeffs_f, slong limbs, slong sign)
22 {
23     slong i, size;
24     mp_limb_t * data;
25     __mpz_struct * mpz_ptr;
26 
27     if (sign)
28     {
29         for (i = 0; i < length; i++)
30         {
31             mpz_ptr = _fmpz_promote(coeffs_m);
32             data = FLINT_MPZ_REALLOC(mpz_ptr, limbs);
33 
34 			if ((coeffs_f[i][limbs - 1] >> (FLINT_BITS - 1)) || coeffs_f[i][limbs])
35             {
36                 mpn_neg_n(data, coeffs_f[i], limbs);
37                 mpn_add_1(data, data, limbs, WORD(1));
38                 size = limbs;
39                 while ((size) && (data[size - 1] == 0)) size--; /* normalise */
40                 mpz_ptr->_mp_size = -size;
41                 if (size >= WORD(-1)) _fmpz_demote_val(coeffs_m); /* coefficient may be small*/
42             }
43             else
44             {
45                 flint_mpn_copyi(data, coeffs_f[i], limbs);
46                 size = limbs;
47                 while ((size) && (data[size - 1] == WORD(0))) size--; /* normalise */
48                 mpz_ptr->_mp_size = size;
49                 if (size <= 1) _fmpz_demote_val(coeffs_m); /* coefficient may be small */
50             }
51 
52             coeffs_m++;
53         }
54     }
55     else
56     {
57         for (i = 0; i < length; i++)
58         {
59             mpz_ptr = _fmpz_promote(coeffs_m);
60             data = FLINT_MPZ_REALLOC(mpz_ptr, limbs);
61             flint_mpn_copyi(data, coeffs_f[i], limbs);
62             size = limbs;
63             while ((size) && (data[size - 1] == WORD(0))) size--; /* normalise */
64             mpz_ptr->_mp_size = size;
65             if (size <= 1) _fmpz_demote_val(coeffs_m); /* coefficient may be small */
66 
67             coeffs_m++;
68         }
69     }
70 }
71