1 /*
2 Copyright (C) 2009 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 <https://www.gnu.org/licenses/>.
10 */
11
12 #include <gmp.h>
13 #include "flint.h"
14 #include "ulong_extras.h"
15
16 int
n_remove2_precomp(mp_limb_t * n,mp_limb_t p,double ppre)17 n_remove2_precomp(mp_limb_t * n, mp_limb_t p, double ppre)
18 {
19 int exp = 0;
20 mp_limb_t quot, rem = UWORD(0);
21
22 if (p == 2)
23 {
24 count_trailing_zeros(exp, *n);
25 if (exp)
26 (*n) >>= exp;
27
28 return exp;
29 }
30
31 do
32 {
33 if ((*n) < p)
34 break;
35 rem = n_divrem2_precomp(", *n, p, ppre);
36 if (rem)
37 break;
38 exp++;
39 (*n) = quot;
40 } while (1);
41
42 return exp;
43 }
44