Blame math/mul_splitl.h

Packit 6c4009
/* Compute full X * Y for long double type.
Packit 6c4009
   Copyright (C) 2013-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _MUL_SPLITL_H
Packit 6c4009
#define _MUL_SPLITL_H
Packit 6c4009
Packit 6c4009
#include <float.h>
Packit 6c4009
Packit 6c4009
/* Calculate X * Y exactly and store the result in *HI + *LO.  It is
Packit 6c4009
   given that the values are small enough that no overflow occurs and
Packit 6c4009
   large enough (or zero) that no underflow occurs.  */
Packit 6c4009
Packit 6c4009
static inline void
Packit 6c4009
mul_splitl (long double *hi, long double *lo, long double x, long double y)
Packit 6c4009
{
Packit 6c4009
#ifdef __FP_FAST_FMAL
Packit 6c4009
  /* Fast built-in fused multiply-add.  */
Packit 6c4009
  *hi = x * y;
Packit 6c4009
  *lo = __builtin_fmal (x, y, -*hi);
Packit 6c4009
#else
Packit 6c4009
  /* Apply Dekker's algorithm.  */
Packit 6c4009
  *hi = x * y;
Packit 6c4009
# define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1)
Packit 6c4009
  long double x1 = x * C;
Packit 6c4009
  long double y1 = y * C;
Packit 6c4009
# undef C
Packit 6c4009
  x1 = (x - x1) + x1;
Packit 6c4009
  y1 = (y - y1) + y1;
Packit 6c4009
  long double x2 = x - x1;
Packit 6c4009
  long double y2 = y - y1;
Packit 6c4009
  *lo = (((x1 * y1 - *hi) + x1 * y2) + x2 * y1) + x2 * y2;
Packit 6c4009
#endif
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#endif /* _MUL_SPLITL_H */