Blame sysdeps/ieee754/dbl-64/gamma_product.c

Packit Service 82fcde
/* Compute a product of X, X+1, ..., with an error estimate.
Packit Service 82fcde
   Copyright (C) 2013-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <math.h>
Packit Service 82fcde
#include <math_private.h>
Packit Service 82fcde
#include <mul_split.h>
Packit Service 82fcde
Packit Service 82fcde
/* Compute the product of X + X_EPS, X + X_EPS + 1, ..., X + X_EPS + N
Packit Service 82fcde
   - 1, in the form R * (1 + *EPS) where the return value R is an
Packit Service 82fcde
   approximation to the product and *EPS is set to indicate the
Packit Service 82fcde
   approximate error in the return value.  X is such that all the
Packit Service 82fcde
   values X + 1, ..., X + N - 1 are exactly representable, and X_EPS /
Packit Service 82fcde
   X is small enough that factors quadratic in it can be
Packit Service 82fcde
   neglected.  */
Packit Service 82fcde
Packit Service 82fcde
double
Packit Service 82fcde
__gamma_product (double x, double x_eps, int n, double *eps)
Packit Service 82fcde
{
Packit Service 82fcde
  SET_RESTORE_ROUND (FE_TONEAREST);
Packit Service 82fcde
  double ret = x;
Packit Service 82fcde
  *eps = x_eps / x;
Packit Service 82fcde
  for (int i = 1; i < n; i++)
Packit Service 82fcde
    {
Packit Service 82fcde
      *eps += x_eps / (x + i);
Packit Service 82fcde
      double lo;
Packit Service 82fcde
      mul_split (&ret, &lo, ret, x + i);
Packit Service 82fcde
      *eps += lo / ret;
Packit Service 82fcde
    }
Packit Service 82fcde
  return ret;
Packit Service 82fcde
}