Blame sysdeps/ieee754/flt-32/s_sincosf.h

Packit Service 82fcde
/* Used by sinf, cosf and sincosf functions.
Packit Service 82fcde
   Copyright (C) 2017-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
/* Chebyshev constants for cos, range -PI/4 - PI/4.  */
Packit Service 82fcde
static const double C0 = -0x1.ffffffffe98aep-2;
Packit Service 82fcde
static const double C1 =  0x1.55555545c50c7p-5;
Packit Service 82fcde
static const double C2 = -0x1.6c16b348b6874p-10;
Packit Service 82fcde
static const double C3 =  0x1.a00eb9ac43ccp-16;
Packit Service 82fcde
static const double C4 = -0x1.23c97dd8844d7p-22;
Packit Service 82fcde
Packit Service 82fcde
/* Chebyshev constants for sin, range -PI/4 - PI/4.  */
Packit Service 82fcde
static const double S0 = -0x1.5555555551cd9p-3;
Packit Service 82fcde
static const double S1 =  0x1.1111110c2688bp-7;
Packit Service 82fcde
static const double S2 = -0x1.a019f8b4bd1f9p-13;
Packit Service 82fcde
static const double S3 =  0x1.71d7264e6b5b4p-19;
Packit Service 82fcde
static const double S4 = -0x1.a947e1674b58ap-26;
Packit Service 82fcde
Packit Service 82fcde
/* Chebyshev constants for sin, range 2^-27 - 2^-5.  */
Packit Service 82fcde
static const double SS0 = -0x1.555555543d49dp-3;
Packit Service 82fcde
static const double SS1 =  0x1.110f475cec8c5p-7;
Packit Service 82fcde
Packit Service 82fcde
/* Chebyshev constants for cos, range 2^-27 - 2^-5.  */
Packit Service 82fcde
static const double CC0 = -0x1.fffffff5cc6fdp-2;
Packit Service 82fcde
static const double CC1 =  0x1.55514b178dac5p-5;
Packit Service 82fcde
Packit Service 82fcde
/* PI/2 with 98 bits of accuracy.  */
Packit Service 82fcde
static const double PI_2_hi = 0x1.921fb544p+0;
Packit Service 82fcde
static const double PI_2_lo = 0x1.0b4611a626332p-34;
Packit Service 82fcde
Packit Service 82fcde
static const double SMALL = 0x1p-50; /* 2^-50.  */
Packit Service 82fcde
static const double inv_PI_4 = 0x1.45f306dc9c883p+0; /* 4/PI.  */
Packit Service 82fcde
Packit Service 82fcde
#define FLOAT_EXPONENT_SHIFT 23
Packit Service 82fcde
#define FLOAT_EXPONENT_BIAS 127
Packit Service 82fcde
Packit Service 82fcde
static const double pio2_table[] = {
Packit Service 82fcde
  0 * M_PI_2,
Packit Service 82fcde
  1 * M_PI_2,
Packit Service 82fcde
  2 * M_PI_2,
Packit Service 82fcde
  3 * M_PI_2,
Packit Service 82fcde
  4 * M_PI_2,
Packit Service 82fcde
  5 * M_PI_2
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
static const double invpio4_table[] = {
Packit Service 82fcde
  0x0p+0,
Packit Service 82fcde
  0x1.45f306cp+0,
Packit Service 82fcde
  0x1.c9c882ap-28,
Packit Service 82fcde
  0x1.4fe13a8p-58,
Packit Service 82fcde
  0x1.f47d4dp-85,
Packit Service 82fcde
  0x1.bb81b6cp-112,
Packit Service 82fcde
  0x1.4acc9ep-142,
Packit Service 82fcde
  0x1.0e4107cp-169
Packit Service 82fcde
};
Packit Service 82fcde
Packit Service 82fcde
static const double ones[] = { 1.0, -1.0 };
Packit Service 82fcde
Packit Service 82fcde
/* Compute the sine value using Chebyshev polynomials where
Packit Service 82fcde
   THETA is the range reduced absolute value of the input
Packit Service 82fcde
   and it is less than Pi/4,
Packit Service 82fcde
   N is calculated as trunc(|x|/(Pi/4)) + 1 and it is used to decide
Packit Service 82fcde
   whether a sine or cosine approximation is more accurate and
Packit Service 82fcde
   SIGNBIT is used to add the correct sign after the Chebyshev
Packit Service 82fcde
   polynomial is computed.  */
Packit Service 82fcde
static inline float
Packit Service 82fcde
reduced_sin (const double theta, const unsigned int n,
Packit Service 82fcde
	 const unsigned int signbit)
Packit Service 82fcde
{
Packit Service 82fcde
  double sx;
Packit Service 82fcde
  const double theta2 = theta * theta;
Packit Service 82fcde
  /* We are operating on |x|, so we need to add back the original
Packit Service 82fcde
     signbit for sinf.  */
Packit Service 82fcde
  double sign;
Packit Service 82fcde
  /* Determine positive or negative primary interval.  */
Packit Service 82fcde
  sign = ones[((n >> 2) & 1) ^ signbit];
Packit Service 82fcde
  /* Are we in the primary interval of sin or cos?  */
Packit Service 82fcde
  if ((n & 2) == 0)
Packit Service 82fcde
    {
Packit Service 82fcde
      /* Here sinf() is calculated using sin Chebyshev polynomial:
Packit Service 82fcde
	x+x^3*(S0+x^2*(S1+x^2*(S2+x^2*(S3+x^2*S4)))).  */
Packit Service 82fcde
      sx = S3 + theta2 * S4;     /* S3+x^2*S4.  */
Packit Service 82fcde
      sx = S2 + theta2 * sx;     /* S2+x^2*(S3+x^2*S4).  */
Packit Service 82fcde
      sx = S1 + theta2 * sx;     /* S1+x^2*(S2+x^2*(S3+x^2*S4)).  */
Packit Service 82fcde
      sx = S0 + theta2 * sx;     /* S0+x^2*(S1+x^2*(S2+x^2*(S3+x^2*S4))).  */
Packit Service 82fcde
      sx = theta + theta * theta2 * sx;
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    {
Packit Service 82fcde
     /* Here sinf() is calculated using cos Chebyshev polynomial:
Packit Service 82fcde
	1.0+x^2*(C0+x^2*(C1+x^2*(C2+x^2*(C3+x^2*C4)))).  */
Packit Service 82fcde
      sx = C3 + theta2 * C4;     /* C3+x^2*C4.  */
Packit Service 82fcde
      sx = C2 + theta2 * sx;     /* C2+x^2*(C3+x^2*C4).  */
Packit Service 82fcde
      sx = C1 + theta2 * sx;     /* C1+x^2*(C2+x^2*(C3+x^2*C4)).  */
Packit Service 82fcde
      sx = C0 + theta2 * sx;     /* C0+x^2*(C1+x^2*(C2+x^2*(C3+x^2*C4))).  */
Packit Service 82fcde
      sx = 1.0 + theta2 * sx;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  /* Add in the signbit and assign the result.  */
Packit Service 82fcde
  return sign * sx;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
/* Compute the cosine value using Chebyshev polynomials where
Packit Service 82fcde
   THETA is the range reduced absolute value of the input
Packit Service 82fcde
   and it is less than Pi/4,
Packit Service 82fcde
   N is calculated as trunc(|x|/(Pi/4)) + 1 and it is used to decide
Packit Service 82fcde
   whether a sine or cosine approximation is more accurate and
Packit Service 82fcde
   the sign of the result.  */
Packit Service 82fcde
static inline float
Packit Service 82fcde
reduced_cos (double theta, unsigned int n)
Packit Service 82fcde
{
Packit Service 82fcde
  double sign, cx;
Packit Service 82fcde
  const double theta2 = theta * theta;
Packit Service 82fcde
Packit Service 82fcde
  /* Determine positive or negative primary interval.  */
Packit Service 82fcde
  n += 2;
Packit Service 82fcde
  sign = ones[(n >> 2) & 1];
Packit Service 82fcde
Packit Service 82fcde
  /* Are we in the primary interval of sin or cos?  */
Packit Service 82fcde
  if ((n & 2) == 0)
Packit Service 82fcde
    {
Packit Service 82fcde
      /* Here cosf() is calculated using sin Chebyshev polynomial:
Packit Service 82fcde
	x+x^3*(S0+x^2*(S1+x^2*(S2+x^2*(S3+x^2*S4)))).  */
Packit Service 82fcde
      cx = S3 + theta2 * S4;
Packit Service 82fcde
      cx = S2 + theta2 * cx;
Packit Service 82fcde
      cx = S1 + theta2 * cx;
Packit Service 82fcde
      cx = S0 + theta2 * cx;
Packit Service 82fcde
      cx = theta + theta * theta2 * cx;
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    {
Packit Service 82fcde
     /* Here cosf() is calculated using cos Chebyshev polynomial:
Packit Service 82fcde
	1.0+x^2*(C0+x^2*(C1+x^2*(C2+x^2*(C3+x^2*C4)))).  */
Packit Service 82fcde
      cx = C3 + theta2 * C4;
Packit Service 82fcde
      cx = C2 + theta2 * cx;
Packit Service 82fcde
      cx = C1 + theta2 * cx;
Packit Service 82fcde
      cx = C0 + theta2 * cx;
Packit Service 82fcde
      cx = 1. + theta2 * cx;
Packit Service 82fcde
    }
Packit Service 82fcde
  return sign * cx;
Packit Service 82fcde
}