Home | History | Annotate | Line # | Download | only in math
      1  1.1  mrg /* Compute a product of 1 + (T/X), 1 + (T/(X+1)), ....
      2  1.1  mrg    Copyright (C) 2015-2018 Free Software Foundation, Inc.
      3  1.1  mrg    This file is part of the GNU C Library.
      4  1.1  mrg 
      5  1.1  mrg    The GNU C Library is free software; you can redistribute it and/or
      6  1.1  mrg    modify it under the terms of the GNU Lesser General Public
      7  1.1  mrg    License as published by the Free Software Foundation; either
      8  1.1  mrg    version 2.1 of the License, or (at your option) any later version.
      9  1.1  mrg 
     10  1.1  mrg    The GNU C Library is distributed in the hope that it will be useful,
     11  1.1  mrg    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  1.1  mrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  1.1  mrg    Lesser General Public License for more details.
     14  1.1  mrg 
     15  1.1  mrg    You should have received a copy of the GNU Lesser General Public
     16  1.1  mrg    License along with the GNU C Library; if not, see
     17  1.1  mrg    <http://www.gnu.org/licenses/>.  */
     18  1.1  mrg 
     19  1.1  mrg #include "quadmath-imp.h"
     20  1.1  mrg 
     21  1.1  mrg /* Compute the product of 1 + (T / (X + X_EPS)), 1 + (T / (X + X_EPS +
     22  1.1  mrg    1)), ..., 1 + (T / (X + X_EPS + N - 1)), minus 1.  X is such that
     23  1.1  mrg    all the values X + 1, ..., X + N - 1 are exactly representable, and
     24  1.1  mrg    X_EPS / X is small enough that factors quadratic in it can be
     25  1.1  mrg    neglected.  */
     26  1.1  mrg 
     27  1.1  mrg __float128
     28  1.1  mrg __quadmath_lgamma_productq (__float128 t, __float128 x, __float128 x_eps, int n)
     29  1.1  mrg {
     30  1.1  mrg   __float128 ret = 0, ret_eps = 0;
     31  1.1  mrg   for (int i = 0; i < n; i++)
     32  1.1  mrg     {
     33  1.1  mrg       __float128 xi = x + i;
     34  1.1  mrg       __float128 quot = t / xi;
     35  1.1  mrg       __float128 mhi, mlo;
     36  1.1  mrg       mul_splitq (&mhi, &mlo, quot, xi);
     37  1.1  mrg       __float128 quot_lo = (t - mhi - mlo) / xi - t * x_eps / (xi * xi);
     38  1.1  mrg       /* We want (1 + RET + RET_EPS) * (1 + QUOT + QUOT_LO) - 1.  */
     39  1.1  mrg       __float128 rhi, rlo;
     40  1.1  mrg       mul_splitq (&rhi, &rlo, ret, quot);
     41  1.1  mrg       __float128 rpq = ret + quot;
     42  1.1  mrg       __float128 rpq_eps = (ret - rpq) + quot;
     43  1.1  mrg       __float128 nret = rpq + rhi;
     44  1.1  mrg       __float128 nret_eps = (rpq - nret) + rhi;
     45  1.1  mrg       ret_eps += (rpq_eps + nret_eps + rlo + ret_eps * quot
     46  1.1  mrg 		  + quot_lo + quot_lo * (ret + ret_eps));
     47  1.1  mrg       ret = nret;
     48  1.1  mrg     }
     49  1.1  mrg   return ret + ret_eps;
     50  1.1  mrg }
     51