]>
Commit | Line | Data |
---|---|---|
f964490f | 1 | /* Compute sine and cosine of argument. |
dff8da6b | 2 | Copyright (C) 1997-2024 Free Software Foundation, Inc. |
f964490f | 3 | This file is part of the GNU C Library. |
f964490f RM |
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 | |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
f964490f | 18 | |
d435569c | 19 | #include <errno.h> |
f964490f RM |
20 | #include <math.h> |
21 | ||
1ed0291c | 22 | #include <math_private.h> |
f964490f RM |
23 | #include <math_ldbl_opt.h> |
24 | ||
25 | void | |
26 | __sincosl (long double x, long double *sinx, long double *cosx) | |
27 | { | |
28 | int64_t ix; | |
4ebd120c | 29 | double xhi; |
f964490f RM |
30 | |
31 | /* High word of x. */ | |
4ebd120c AM |
32 | xhi = ldbl_high (x); |
33 | EXTRACT_WORDS64 (ix, xhi); | |
f964490f RM |
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; | |
fe8c2b33 | 43 | if (isinf (x)) |
d435569c | 44 | __set_errno (EDOM); |
f964490f RM |
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); |