1*181254a7Smrg /* Compute sine and cosine of argument.
2*181254a7Smrg Copyright (C) 1997-2018 Free Software Foundation, Inc.
3*181254a7Smrg This file is part of the GNU C Library.
4*181254a7Smrg Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and
5*181254a7Smrg Jakub Jelinek <jj@ultra.linux.cz>.
6*181254a7Smrg
7*181254a7Smrg The GNU C Library is free software; you can redistribute it and/or
8*181254a7Smrg modify it under the terms of the GNU Lesser General Public
9*181254a7Smrg License as published by the Free Software Foundation; either
10*181254a7Smrg version 2.1 of the License, or (at your option) any later version.
11*181254a7Smrg
12*181254a7Smrg The GNU C Library is distributed in the hope that it will be useful,
13*181254a7Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of
14*181254a7Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15*181254a7Smrg Lesser General Public License for more details.
16*181254a7Smrg
17*181254a7Smrg You should have received a copy of the GNU Lesser General Public
18*181254a7Smrg License along with the GNU C Library; if not, see
19*181254a7Smrg <http://www.gnu.org/licenses/>. */
20*181254a7Smrg
21*181254a7Smrg #include "quadmath-imp.h"
22*181254a7Smrg
23*181254a7Smrg void
sincosq(__float128 x,__float128 * sinx,__float128 * cosx)24*181254a7Smrg sincosq (__float128 x, __float128 *sinx, __float128 *cosx)
25*181254a7Smrg {
26*181254a7Smrg int64_t ix;
27*181254a7Smrg
28*181254a7Smrg /* High word of x. */
29*181254a7Smrg GET_FLT128_MSW64 (ix, x);
30*181254a7Smrg
31*181254a7Smrg /* |x| ~< pi/4 */
32*181254a7Smrg ix &= 0x7fffffffffffffffLL;
33*181254a7Smrg if (ix <= 0x3ffe921fb54442d1LL)
34*181254a7Smrg __quadmath_kernel_sincosq (x, 0, sinx, cosx, 0);
35*181254a7Smrg else if (ix >= 0x7fff000000000000LL)
36*181254a7Smrg {
37*181254a7Smrg /* sin(Inf or NaN) is NaN */
38*181254a7Smrg *sinx = *cosx = x - x;
39*181254a7Smrg if (isinfq (x))
40*181254a7Smrg errno = EDOM;
41*181254a7Smrg }
42*181254a7Smrg else
43*181254a7Smrg {
44*181254a7Smrg /* Argument reduction needed. */
45*181254a7Smrg __float128 y[2];
46*181254a7Smrg int n;
47*181254a7Smrg
48*181254a7Smrg n = __quadmath_rem_pio2q (x, y);
49*181254a7Smrg switch (n & 3)
50*181254a7Smrg {
51*181254a7Smrg case 0:
52*181254a7Smrg __quadmath_kernel_sincosq (y[0], y[1], sinx, cosx, 1);
53*181254a7Smrg break;
54*181254a7Smrg case 1:
55*181254a7Smrg __quadmath_kernel_sincosq (y[0], y[1], cosx, sinx, 1);
56*181254a7Smrg *cosx = -*cosx;
57*181254a7Smrg break;
58*181254a7Smrg case 2:
59*181254a7Smrg __quadmath_kernel_sincosq (y[0], y[1], sinx, cosx, 1);
60*181254a7Smrg *sinx = -*sinx;
61*181254a7Smrg *cosx = -*cosx;
62*181254a7Smrg break;
63*181254a7Smrg default:
64*181254a7Smrg __quadmath_kernel_sincosq (y[0], y[1], cosx, sinx, 1);
65*181254a7Smrg *sinx = -*sinx;
66*181254a7Smrg break;
67*181254a7Smrg }
68*181254a7Smrg }
69*181254a7Smrg }
70