1 /* Compute sine and cosine of argument.
2 Copyright (C) 1997-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <errno.h>
20 #include <math.h>
21
22 #include <math_private.h>
23 #include <math_ldbl_opt.h>
24
25 void
__sincosl(long double x,long double * sinx,long double * cosx)26 __sincosl (long double x, long double *sinx, long double *cosx)
27 {
28 int64_t ix;
29 double xhi;
30
31 /* High word of x. */
32 xhi = ldbl_high (x);
33 EXTRACT_WORDS64 (ix, xhi);
34
35 /* |x| ~< pi/4 */
36 ix &= 0x7fffffffffffffffLL;
37 if (ix <= 0x3fe921fb54442d10LL)
38 __kernel_sincosl (x, 0.0L, sinx, cosx, 0);
39 else if (ix >= 0x7ff0000000000000LL)
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 long double 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 }
74 long_double_symbol (libm, __sincosl, sincosl);
75