Blame sysdeps/ieee754/ldbl-128/s_sincosl.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 and
Packit 6c4009
		  Jakub Jelinek <jj@ultra.linux.cz>.
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 <libm-alias-ldouble.h>
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
__sincosl (_Float128 x, _Float128 *sinx, _Float128 *cosx)
Packit 6c4009
{
Packit 6c4009
  int64_t ix;
Packit 6c4009
Packit 6c4009
  /* High word of x. */
Packit 6c4009
  GET_LDOUBLE_MSW64 (ix, x);
Packit 6c4009
Packit 6c4009
  /* |x| ~< pi/4 */
Packit 6c4009
  ix &= 0x7fffffffffffffffLL;
Packit 6c4009
  if (ix <= 0x3ffe921fb54442d1LL)
Packit 6c4009
    __kernel_sincosl (x, 0, sinx, cosx, 0);
Packit 6c4009
  else if (ix >= 0x7fff000000000000LL)
Packit 6c4009
    {
Packit 6c4009
      /* sin(Inf or NaN) is NaN */
Packit 6c4009
      *sinx = *cosx = x - x;
Packit 6c4009
      if (isinf (x))
Packit 6c4009
	__set_errno (EDOM);
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      /* Argument reduction needed.  */
Packit 6c4009
      _Float128 y[2];
Packit 6c4009
      int n;
Packit 6c4009
Packit 6c4009
      n = __ieee754_rem_pio2l (x, y);
Packit 6c4009
      switch (n & 3)
Packit 6c4009
	{
Packit 6c4009
	case 0:
Packit 6c4009
	  __kernel_sincosl (y[0], y[1], sinx, cosx, 1);
Packit 6c4009
	  break;
Packit 6c4009
	case 1:
Packit 6c4009
	  __kernel_sincosl (y[0], y[1], cosx, sinx, 1);
Packit 6c4009
	  *cosx = -*cosx;
Packit 6c4009
	  break;
Packit 6c4009
	case 2:
Packit 6c4009
	  __kernel_sincosl (y[0], y[1], sinx, cosx, 1);
Packit 6c4009
	  *sinx = -*sinx;
Packit 6c4009
	  *cosx = -*cosx;
Packit 6c4009
	  break;
Packit 6c4009
	default:
Packit 6c4009
	  __kernel_sincosl (y[0], y[1], cosx, sinx, 1);
Packit 6c4009
	  *sinx = -*sinx;
Packit 6c4009
	  break;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
libm_alias_ldouble (__sincos, sincos)