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