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