]>
Commit | Line | Data |
---|---|---|
7799b7b3 | 1 | /* Compute sine and cosine of argument. |
568035b7 | 2 | Copyright (C) 1997-2013 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 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
7799b7b3 UD |
19 | |
20 | #include <math.h> | |
21 | ||
1ed0291c | 22 | #include <math_private.h> |
7799b7b3 | 23 | |
22bf5c17 LD |
24 | #ifndef SINCOSF |
25 | # define SINCOSF_FUNC __sincosf | |
26 | #else | |
27 | # define SINCOSF_FUNC SINCOSF | |
28 | #endif | |
7799b7b3 UD |
29 | |
30 | void | |
22bf5c17 | 31 | SINCOSF_FUNC (float x, float *sinx, float *cosx) |
7799b7b3 UD |
32 | { |
33 | int32_t ix; | |
34 | ||
35 | /* High word of x. */ | |
36 | GET_FLOAT_WORD (ix, x); | |
37 | ||
38 | /* |x| ~< pi/4 */ | |
39 | ix &= 0x7fffffff; | |
40 | if (ix <= 0x3f490fd8) | |
41 | { | |
42 | *sinx = __kernel_sinf (x, 0.0, 0); | |
43 | *cosx = __kernel_cosf (x, 0.0); | |
44 | } | |
940f0754 | 45 | else if (ix>=0x7f800000) |
7799b7b3 UD |
46 | { |
47 | /* sin(Inf or NaN) is NaN */ | |
48 | *sinx = *cosx = x - x; | |
49 | } | |
50 | else | |
51 | { | |
52 | /* Argument reduction needed. */ | |
53 | float y[2]; | |
54 | int n; | |
55 | ||
56 | n = __ieee754_rem_pio2f (x, y); | |
57 | switch (n & 3) | |
58 | { | |
59 | case 0: | |
60 | *sinx = __kernel_sinf (y[0], y[1], 1); | |
61 | *cosx = __kernel_cosf (y[0], y[1]); | |
62 | break; | |
63 | case 1: | |
64 | *sinx = __kernel_cosf (y[0], y[1]); | |
65 | *cosx = -__kernel_sinf (y[0], y[1], 1); | |
66 | break; | |
67 | case 2: | |
68 | *sinx = -__kernel_sinf (y[0], y[1], 1); | |
69 | *cosx = -__kernel_cosf (y[0], y[1]); | |
70 | break; | |
71 | default: | |
72 | *sinx = -__kernel_cosf (y[0], y[1]); | |
73 | *cosx = __kernel_sinf (y[0], y[1], 1); | |
74 | break; | |
75 | } | |
76 | } | |
77 | } | |
22bf5c17 LD |
78 | |
79 | #ifndef SINCOSF | |
7799b7b3 | 80 | weak_alias (__sincosf, sincosf) |
22bf5c17 | 81 | #endif |