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