1 /*
2     Copyright (C) 2009, 2010 William Hart
3     Copyright (C) 2010 Sebastian Pancratz
4     Copyright (C) 2014 Abhinav Baid
5 
6     This file is part of FLINT.
7 
8     FLINT 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 <stdio.h>
15 #include <stdlib.h>
16 #include <gmp.h>
17 #include <math.h>
18 #include "flint.h"
19 #include "fmpz.h"
20 #include "fmpz_vec.h"
21 #include "d_vec.h"
22 #include "ulong_extras.h"
23 
24 int
main(void)25 main(void)
26 {
27     int i;
28     FLINT_TEST_INIT(state);
29 
30     flint_printf("get_d_vec_2exp....");
31     fflush(stdout);
32 
33     for (i = 0; i < 1000 * flint_test_multiplier(); i++)
34     {
35         int result;
36         fmpz *a;
37         double *d1, *d2;
38         slong bits, j, len, l1, l2, l3;
39 
40         len = n_randint(state, 100);
41 
42         a = _fmpz_vec_init(len);
43         d1 = _d_vec_init(len);
44         d2 = _d_vec_init(len);
45 
46         bits = 1 + n_randint(state, 200);
47 
48         _fmpz_vec_randtest(a, state, len, bits);
49 
50         l1 = _fmpz_vec_get_d_vec_2exp(d1, a, len / 2);
51         l2 = _fmpz_vec_get_d_vec_2exp(d1 + len / 2, a + len / 2,
52                                       (len + 1) / 2);
53         l3 = _fmpz_vec_get_d_vec_2exp(d2, a, len);
54 
55         if (l1 < l2)
56             for (j = 0; j < len / 2; j++)
57                 d1[j] = ldexp(d1[j], l1 - l2);
58 
59         if (l2 < l1)
60             for (j = len / 2; j < len; j++)
61                 d1[j] = ldexp(d1[j], l2 - l1);
62 
63         result = (l3 == FLINT_MAX(l1, l2) && _d_vec_equal(d1, d2, len));
64         if (!result)
65         {
66             flint_printf("FAIL:\n");
67             _fmpz_vec_print(a, len), flint_printf("\n");
68             abort();
69         }
70 
71         _fmpz_vec_clear(a, len);
72         _d_vec_clear(d1);
73         _d_vec_clear(d2);
74     }
75 
76     FLINT_TEST_CLEANUP(state);
77 
78     flint_printf("PASS\n");
79     return 0;
80 }
81