1 /*
2     Copyright (C) 2012, 2013 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 "arb.h"
13 
14 void
arb_pow_fmpq(arb_t y,const arb_t x,const fmpq_t a,slong prec)15 arb_pow_fmpq(arb_t y, const arb_t x, const fmpq_t a, slong prec)
16 {
17     if (fmpz_is_one(fmpq_denref(a)))
18     {
19         arb_pow_fmpz(y, x, fmpq_numref(a), prec);
20     }
21     else
22     {
23         int use_exp;
24         slong k = *fmpq_denref(a);
25 
26         if (k == 2 || k == 4)
27             use_exp = 0;
28         else if (k > 1 && k < 50)
29             use_exp = prec < (WORD(1) << ((k / 8) + 8));
30         else
31             use_exp = 1;
32 
33         if (use_exp)
34         {
35             arb_log(y, x, prec + 10);
36             arb_mul_fmpz(y, y, fmpq_numref(a), prec + 10);
37             arb_div_fmpz(y, y, fmpq_denref(a), prec + 10);
38             arb_exp(y, y, prec);
39         }
40         else
41         {
42             arb_root_ui(y, x, k, prec);
43             arb_pow_fmpz(y, y, fmpq_numref(a), prec);
44         }
45     }
46 }
47 
48