1 /*
2 Copyright (C) 2021 Daniel Schultz
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 <https://www.gnu.org/licenses/>.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <gmp.h>
15 #include "flint.h"
16 #include "fmpz.h"
17 #include "fmpz_vec.h"
18 #include "ulong_extras.h"
19
20 int
main(void)21 main(void)
22 {
23 slong i, j;
24 FLINT_TEST_INIT(state);
25
26 flint_printf("sum_max_bits....");
27 fflush(stdout);
28
29 for (i = 0; i < 1000 * flint_test_multiplier(); i++)
30 {
31 fmpz * a;
32 fmpz_t max, sum, t;
33 slong sum_bits, max_bits;
34 slong len = n_randint(state, 300);
35
36 a = _fmpz_vec_init(len);
37 fmpz_init(max);
38 fmpz_init(sum);
39 fmpz_init(t);
40
41 _fmpz_vec_randtest(a, state, len, 300);
42
43 _fmpz_vec_sum_max_bits(&sum_bits, &max_bits, a, len);
44
45 fmpz_zero(max);
46 fmpz_zero(sum);
47 for (j = 0; j < len; j++)
48 {
49 fmpz_abs(t, a + j);
50 fmpz_add(sum, sum, t);
51 if (fmpz_cmp(max, t) < 0)
52 fmpz_set(max, t);
53 }
54
55 if (sum_bits != fmpz_bits(sum))
56 {
57 flint_printf("FAIL: sum bits is wrong\n");
58 flint_abort();
59 }
60
61 if (max_bits != fmpz_bits(max))
62 {
63 flint_printf("FAIL: max bits is wrong\n");
64 flint_abort();
65 }
66
67 _fmpz_vec_clear(a, len);
68 fmpz_clear(max);
69 fmpz_clear(sum);
70 fmpz_clear(t);
71 }
72
73 FLINT_TEST_CLEANUP(state);
74
75 flint_printf("PASS\n");
76 return 0;
77 }
78