arb/gamma/rising_fmprb_fmpq_ui_bsplit.c

102 lines
2.5 KiB
C

/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2013 Fredrik Johansson
******************************************************************************/
#include "gamma.h"
static void
bsplit(fmprb_t y, const fmpz_t p, const fmpz_t q, ulong a, ulong b, long prec)
{
if (b - a <= 8)
{
fmpz_t t, u;
ulong c;
fmpz_init(t);
fmpz_init(u);
fmpz_mul_ui(t, q, a);
fmpz_add(t, t, p);
fmpz_set(u, t);
for (c = a + 1; c < b; c++)
{
fmpz_add(u, u, q);
fmpz_mul(t, t, u);
}
fmprb_set_round_fmpz(y, t, prec);
fmpz_clear(t);
fmpz_clear(u);
}
else
{
fmprb_t w;
ulong m = a + (b - a) / 2;
fmprb_init(w);
bsplit(y, p, q, a, m, prec);
bsplit(w, p, q, m, b, prec);
fmprb_mul(y, y, w, prec);
fmprb_clear(w);
}
}
void
gamma_rising_fmprb_fmpq_ui_bsplit(fmprb_t y, const fmpq_t x, ulong n, long prec)
{
if (n == 0)
{
fmprb_one(y);
}
else if (n == 1)
{
fmprb_set_fmpq(y, x, prec);
}
else
{
long wp;
wp = FMPR_PREC_ADD(prec, FLINT_BIT_COUNT(n));
bsplit(y, fmpq_numref(x), fmpq_denref(x), 0, n, wp);
if (fmpz_is_one(fmpq_denref(x)))
{
fmprb_set_round(y, y, prec);
}
else
{
fmprb_t t;
fmprb_init(t);
fmprb_set_fmpz(t, fmpq_denref(x));
fmprb_pow_ui(t, t, n, wp);
fmprb_div(y, y, t, prec);
fmprb_clear(t);
}
}
}