arb/bernoulli/fmpq_ui_zeta.c

51 lines
1.1 KiB
C
Raw Normal View History

/*
2013-03-15 16:16:09 +01:00
Copyright (C) 2013 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
2013-03-15 16:16:09 +01:00
#include "bernoulli.h"
2014-06-14 22:08:38 +02:00
#include "arb.h"
2013-03-15 16:16:09 +01:00
void
_bernoulli_fmpq_ui_zeta(fmpz_t num, fmpz_t den, ulong n)
{
slong prec;
2014-06-14 22:08:38 +02:00
arb_t t;
2013-03-15 16:16:09 +01:00
arith_bernoulli_number_denom(den, n);
if (n % 2)
{
fmpz_set_si(num, -(n == 1));
return;
}
if (n < BERNOULLI_SMALL_NUMER_LIMIT)
{
fmpz_set_si(num, _bernoulli_numer_small[n / 2]);
return;
}
2014-06-14 22:08:38 +02:00
arb_init(t);
2013-03-15 16:16:09 +01:00
for (prec = arith_bernoulli_number_size(n) + fmpz_bits(den) + 2; ; prec += 20)
{
2014-06-14 22:08:38 +02:00
arb_bernoulli_ui_zeta(t, n, prec);
arb_mul_fmpz(t, t, den, prec);
2013-03-15 16:16:09 +01:00
2014-06-14 22:08:38 +02:00
if (arb_get_unique_fmpz(num, t))
2013-03-15 16:16:09 +01:00
break;
flint_printf("warning: %wd insufficient precision for Bernoulli number %wu\n", prec, n);
2013-03-15 16:16:09 +01:00
}
2014-06-14 22:08:38 +02:00
arb_clear(t);
2013-03-15 16:16:09 +01:00
}