]>
Commit | Line | Data |
---|---|---|
7799b7b3 | 1 | /* Compute sine and cosine of argument. |
2b778ceb | 2 | Copyright (C) 1997-2021 Free Software Foundation, Inc. |
7799b7b3 UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
7799b7b3 UD |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
7799b7b3 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
7799b7b3 | 19 | |
d435569c | 20 | #include <errno.h> |
7799b7b3 UD |
21 | #include <math.h> |
22 | ||
1ed0291c | 23 | #include <math_private.h> |
70e2ba33 | 24 | #include <fenv_private.h> |
8f5b00d3 | 25 | #include <math-underflow.h> |
1e2bffd0 | 26 | #include <libm-alias-double.h> |
7799b7b3 | 27 | |
e88ecbbf | 28 | #define IN_SINCOS |
463ac90d | 29 | #include "s_sin.c" |
7799b7b3 UD |
30 | |
31 | void | |
32 | __sincos (double x, double *sinx, double *cosx) | |
33 | { | |
a045832d SP |
34 | mynumber u; |
35 | int k; | |
36 | ||
463ac90d SP |
37 | SET_RESTORE_ROUND_53BIT (FE_TONEAREST); |
38 | ||
a045832d | 39 | u.x = x; |
e88ecbbf | 40 | k = u.i[HIGH_HALF] & 0x7fffffff; |
a045832d | 41 | |
b3004556 | 42 | if (k < 0x400368fd) |
a045832d | 43 | { |
e88ecbbf WD |
44 | double a, da, y; |
45 | /* |x| < 2^-27 => cos (x) = 1, sin (x) = x. */ | |
46 | if (k < 0x3e400000) | |
47 | { | |
48 | if (k < 0x3e500000) | |
49 | math_check_force_underflow (x); | |
50 | *sinx = x; | |
51 | *cosx = 1.0; | |
52 | return; | |
53 | } | |
54 | /* |x| < 0.855469. */ | |
55 | else if (k < 0x3feb6000) | |
56 | { | |
57 | *sinx = do_sin (x, 0); | |
58 | *cosx = do_cos (x, 0); | |
59 | return; | |
60 | } | |
b3004556 | 61 | |
e88ecbbf WD |
62 | /* |x| < 2.426265. */ |
63 | y = hp0 - fabs (x); | |
64 | a = y + hp1; | |
65 | da = (y - a) + hp1; | |
81dca813 | 66 | *sinx = copysign (do_cos (a, da), x); |
e88ecbbf | 67 | *cosx = do_sin (a, da); |
a045832d SP |
68 | return; |
69 | } | |
e88ecbbf | 70 | /* |x| < 2^1024. */ |
a045832d SP |
71 | if (k < 0x7ff00000) |
72 | { | |
e88ecbbf WD |
73 | double a, da, xx; |
74 | unsigned int n; | |
64909583 | 75 | |
e88ecbbf WD |
76 | /* If |x| < 105414350 use simple range reduction. */ |
77 | n = k < 0x419921FB ? reduce_sincos (x, &a, &da) : __branred (x, &a, &da); | |
78 | n = n & 3; | |
79 | ||
80 | if (n == 1 || n == 2) | |
81 | { | |
82 | a = -a; | |
83 | da = -da; | |
84 | } | |
85 | ||
86 | if (n & 1) | |
87 | { | |
88 | double *temp = cosx; | |
89 | cosx = sinx; | |
90 | sinx = temp; | |
91 | } | |
92 | ||
93 | *sinx = do_sin (a, da); | |
94 | xx = do_cos (a, da); | |
95 | *cosx = (n & 2) ? -xx : xx; | |
96 | return; | |
a045832d SP |
97 | } |
98 | ||
99 | if (isinf (x)) | |
100 | __set_errno (EDOM); | |
101 | ||
102 | *sinx = *cosx = x / x; | |
7799b7b3 | 103 | } |
1e2bffd0 | 104 | libm_alias_double (__sincos, sincos) |