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