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 "acb.h"
13 
14 void
acb_chebyshev_t2_ui(acb_t a,acb_t b,ulong n,const acb_t x,slong prec)15 acb_chebyshev_t2_ui(acb_t a, acb_t b, ulong n, const acb_t x, slong prec)
16 {
17     int i;
18 
19     acb_set_round(a, x, prec);
20     acb_one(b);
21 
22     if (n <= 1)
23     {
24         if (n == 0)
25             acb_swap(a, b);
26         return;
27     }
28 
29     for (i = FLINT_BIT_COUNT(n - 1) - 1; i >= 0; i--)
30     {
31         if (((n - 1) >> i) & 1)
32         {
33             acb_mul(b, b, a, prec);
34             acb_mul_2exp_si(b, b, 1);
35             acb_sub(b, b, x, prec);
36             acb_mul(a, a, a, prec);
37             acb_mul_2exp_si(a, a, 1);
38             acb_sub_ui(a, a, 1, prec);
39         }
40         else
41         {
42             acb_mul(a, a, b, prec);
43             acb_mul_2exp_si(a, a, 1);
44             acb_sub(a, a, x, prec);
45             acb_mul(b, b, b, prec);
46             acb_mul_2exp_si(b, b, 1);
47             acb_sub_ui(b, b, 1, prec);
48         }
49     }
50 }
51 
52