1 /*
2 Copyright (C) 2014 Fredrik Johansson
3
4 This file is part of Arb.
5
6 Arb 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 "mag.h"
13
14 /* bound (1 + 1/m)^n, m > 0, n >= 0 */
15 void
mag_binpow_uiui(mag_t b,ulong m,ulong n)16 mag_binpow_uiui(mag_t b, ulong m, ulong n)
17 {
18 mag_t t;
19
20 if (m == 0)
21 {
22 mag_inf(b);
23 return;
24 }
25
26 mag_init(t);
27
28 /* bound by exp(n/m) <= 1 + (n/m) + (n/m)^2 */
29 if (m > n)
30 {
31 mag_set_ui(t, n); /* x = n/m */
32 mag_div_ui(t, t, m);
33
34 mag_mul(b, t, t); /* x^2 */
35 mag_add(b, b, t); /* x */
36 mag_one(t);
37 mag_add(b, b, t); /* 1 */
38 }
39 else
40 {
41 mag_one(b);
42 mag_div_ui(b, b, m);
43 mag_one(t);
44 mag_add(t, t, b);
45 mag_pow_ui(b, t, n);
46 }
47
48 mag_clear(t);
49 }
50
51