1 /*
2     Copyright (C) 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 #include "bernoulli.h"
14 
15 void
arb_bernoulli_ui(arb_t b,ulong n,slong prec)16 arb_bernoulli_ui(arb_t b, ulong n, slong prec)
17 {
18     if (n < bernoulli_cache_num)
19     {
20         arb_set_fmpq(b, bernoulli_cache + n, prec);
21     }
22     else
23     {
24         int use_frac;
25 
26         use_frac = (n < BERNOULLI_SMALL_NUMER_LIMIT) || (n % 2 != 0);
27         if (!use_frac && n < UWORD_MAX / 1000)
28             use_frac = (prec > bernoulli_global_prec(n));
29 
30         if (use_frac)
31         {
32             fmpq_t t;
33             fmpq_init(t);
34             bernoulli_fmpq_ui(t, n);
35             arb_set_fmpq(b, t, prec);
36             fmpq_clear(t);
37         }
38         else
39         {
40             arb_bernoulli_ui_zeta(b, n, prec);
41         }
42     }
43 }
44 
45