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

Packit 6c4009
/* Compute sine and cosine of argument.
Packit 6c4009
   Copyright (C) 1997-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
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
#include <errno.h>
Packit 6c4009
#include <math.h>
Packit 6c4009
Packit 6c4009
#include <math_private.h>
Packit 6c4009
#include <math-underflow.h>
Packit 6c4009
#include <libm-alias-double.h>
Packit 6c4009
Packit 6c4009
#define IN_SINCOS
Packit 6c4009
#include "s_sin.c"
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
__sincos (double x, double *sinx, double *cosx)
Packit 6c4009
{
Packit 6c4009
  mynumber u;
Packit 6c4009
  int k;
Packit 6c4009
Packit 6c4009
  SET_RESTORE_ROUND_53BIT (FE_TONEAREST);
Packit 6c4009
Packit 6c4009
  u.x = x;
Packit 6c4009
  k = u.i[HIGH_HALF] & 0x7fffffff;
Packit 6c4009
Packit 6c4009
  if (k < 0x400368fd)
Packit 6c4009
    {
Packit 6c4009
      double a, da, y;
Packit 6c4009
      /* |x| < 2^-27 => cos (x) = 1, sin (x) = x.  */
Packit 6c4009
      if (k < 0x3e400000)
Packit 6c4009
	{
Packit 6c4009
	  if (k < 0x3e500000)
Packit 6c4009
	    math_check_force_underflow (x);
Packit 6c4009
	  *sinx = x;
Packit 6c4009
	  *cosx = 1.0;
Packit 6c4009
	  return;
Packit 6c4009
	}
Packit 6c4009
      /* |x| < 0.855469.  */
Packit 6c4009
      else if (k < 0x3feb6000)
Packit 6c4009
	{
Packit 6c4009
	  *sinx = do_sin (x, 0);
Packit 6c4009
	  *cosx = do_cos (x, 0);
Packit 6c4009
	  return;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      /* |x| < 2.426265.  */
Packit 6c4009
      y = hp0 - fabs (x);
Packit 6c4009
      a = y + hp1;
Packit 6c4009
      da = (y - a) + hp1;
Packit 6c4009
      *sinx = __copysign (do_cos (a, da), x);
Packit 6c4009
      *cosx = do_sin (a, da);
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
  /* |x| < 2^1024.  */
Packit 6c4009
  if (k < 0x7ff00000)
Packit 6c4009
    {
Packit 6c4009
      double a, da, xx;
Packit 6c4009
      unsigned int n;
Packit 6c4009
Packit 6c4009
      /* If |x| < 105414350 use simple range reduction.  */
Packit 6c4009
      n = k < 0x419921FB ? reduce_sincos (x, &a, &da) : __branred (x, &a, &da);
Packit 6c4009
      n = n & 3;
Packit 6c4009
Packit 6c4009
      if (n == 1 || n == 2)
Packit 6c4009
	{
Packit 6c4009
	  a = -a;
Packit 6c4009
	  da = -da;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      if (n & 1)
Packit 6c4009
	{
Packit 6c4009
	  double *temp = cosx;
Packit 6c4009
	  cosx = sinx;
Packit 6c4009
	  sinx = temp;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      *sinx = do_sin (a, da);
Packit 6c4009
      xx = do_cos (a, da);
Packit 6c4009
      *cosx = (n & 2) ? -xx : xx;
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (isinf (x))
Packit 6c4009
    __set_errno (EDOM);
Packit 6c4009
Packit 6c4009
  *sinx = *cosx = x / x;
Packit 6c4009
}
Packit 6c4009
libm_alias_double (__sincos, sincos)