|
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 <math_ldbl_opt.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
__sincosl (long double x, long double *sinx, long double *cosx)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int64_t ix;
|
|
Packit |
6c4009 |
double xhi;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* High word of x. */
|
|
Packit |
6c4009 |
xhi = ldbl_high (x);
|
|
Packit |
6c4009 |
EXTRACT_WORDS64 (ix, xhi);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* |x| ~< pi/4 */
|
|
Packit |
6c4009 |
ix &= 0x7fffffffffffffffLL;
|
|
Packit |
6c4009 |
if (ix <= 0x3fe921fb54442d10LL)
|
|
Packit |
6c4009 |
__kernel_sincosl (x, 0.0L, sinx, cosx, 0);
|
|
Packit |
6c4009 |
else if (ix >= 0x7ff0000000000000LL)
|
|
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 |
long double 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 |
long_double_symbol (libm, __sincosl, sincosl);
|