1 /*
2     Copyright (C) 2016 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 <gmp.h>
13 #include <stdlib.h>
14 #include "flint.h"
15 #include "mpoly.h"
16 
mpoly_unpack_monomials_tight(ulong * e1,ulong * e2,slong len,slong * mults,slong num,slong bits)17 void mpoly_unpack_monomials_tight(ulong * e1, ulong * e2, slong len,
18                                           slong * mults, slong num, slong bits)
19 {
20    slong i, j;
21    ulong exp;
22    slong * prods;
23    TMP_INIT;
24 
25    TMP_START;
26 
27    prods = (slong *) TMP_ALLOC((num + 1)*sizeof(slong));
28 
29    prods[0] = 1;
30    for (i = 1; i <= num; i++)
31       prods[i] = mults[i - 1]*prods[i - 1];
32 
33    for (i = 0; i < len; i++)
34    {
35       exp = 0;
36 
37       for (j = 0; j < num; j++)
38          exp += (e2[i] % prods[j + 1])/prods[j] << bits*j;
39 
40       e1[i] = exp;
41 
42    }
43 
44    TMP_END;
45 }
46 
47