Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/R/sincosf.c
+++ new/usr/src/lib/libm/common/R/sincosf.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23 23 */
24 24 /*
25 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 26 * Use is subject to license terms.
27 27 */
28 28
29 29 #pragma weak sincosf = __sincosf
30 30
31 31 /* INDENT OFF */
32 32 /*
33 33 * For |x| < pi/4, let z = x * x, and approximate sin(x) by
34 34 *
35 35 * S(x) = x(S0 + S1*z)(S2 + S3*z + z*z)
36 36 * where
37 37 * S0 = 1.85735322054308378716204874632872525989806770558e-0003,
38 38 * S1 = -1.95035094218403635082921458859320791358115801259e-0004,
39 39 * S2 = 5.38400550766074785970952495168558701485841707252e+0002,
40 40 * S3 = -3.31975110777873728964197739157371509422022905947e+0001,
41 41 *
42 42 * with error bounded by |(sin(x) - S(x))/x| < 2**(-28.2), and
43 43 * cos(x) by
44 44 *
45 45 * C(x) = (C0 + C1*z + C2*z*z) * (C3 + C4*z + z*z)
46 46 * where
47 47 * C0 = 1.09349482127188401868272000389539985058873853699e-0003
48 48 * C1 = -5.03324285989964979398034700054920226866107675091e-0004
49 49 * C2 = 2.43792880266971107750418061559602239831538067410e-0005
50 50 * C3 = 9.14499072605666582228127405245558035523741471271e+0002
51 51 * C4 = -3.63151270591815439197122504991683846785293207730e+0001
52 52 *
53 53 * with error bounded by |cos(x) - C(x)| < 2**(-34.2).
54 54 */
55 55 /* INDENT ON */
56 56
57 57 #include "libm.h"
58 58
59 59 extern const int _TBL_ipio2_inf[];
60 60 extern int __rem_pio2m(double *, double *, int, int, int, const int *);
61 61 #if defined(__i386) && !defined(__amd64)
62 62 extern int __swapRP(int);
63 63 #endif
64 64
65 65 static const double C[] = {
66 66 1.85735322054308378716204874632872525989806770558e-0003,
67 67 -1.95035094218403635082921458859320791358115801259e-0004,
68 68 5.38400550766074785970952495168558701485841707252e+0002,
69 69 -3.31975110777873728964197739157371509422022905947e+0001,
70 70 1.09349482127188401868272000389539985058873853699e-0003,
71 71 -5.03324285989964979398034700054920226866107675091e-0004,
72 72 2.43792880266971107750418061559602239831538067410e-0005,
73 73 9.14499072605666582228127405245558035523741471271e+0002,
74 74 -3.63151270591815439197122504991683846785293207730e+0001,
75 75 0.636619772367581343075535, /* 2^ -1 * 1.45F306DC9C883 */
76 76 0.5,
77 77 1.570796326734125614166, /* 2^ 0 * 1.921FB54400000 */
78 78 6.077100506506192601475e-11, /* 2^-34 * 1.0B4611A626331 */
79 79 };
80 80
81 81 #define S0 C[0]
82 82 #define S1 C[1]
83 83 #define S2 C[2]
84 84 #define S3 C[3]
85 85 #define C0 C[4]
86 86 #define C1 C[5]
87 87 #define C2 C[6]
88 88 #define C3 C[7]
89 89 #define C4 C[8]
90 90 #define invpio2 C[9]
↓ open down ↓ |
90 lines elided |
↑ open up ↑ |
91 91 #define half C[10]
92 92 #define pio2_1 C[11]
93 93 #define pio2_t C[12]
94 94
95 95 void
96 96 sincosf(float x, float *s, float *c)
97 97 {
98 98 double y, z, w;
99 99 float f, g;
100 100 int n, ix, hx, hy;
101 + volatile int i;
101 102
102 103 hx = *((int *)&x);
103 104 ix = hx & 0x7fffffff;
104 105
105 106 y = (double)x;
106 107
107 108 if (ix <= 0x4016cbe4) { /* |x| < 3*pi/4 */
108 109 if (ix <= 0x3f490fdb) { /* |x| < pi/4 */
109 110 if (ix <= 0x39800000) { /* |x| <= 2**-12 */
110 - volatile int i = (int)y;
111 + i = (int)y;
111 112 #ifdef lint
112 113 i = i;
113 114 #endif
114 115 *s = x;
115 116 *c = 1.0f;
116 117 return;
117 118 }
118 119 z = y * y;
119 120 *s = (float)((y * (S0 + z * S1)) *
120 121 (S2 + z * (S3 + z)));
121 122 *c = (float)(((C0 + z * C1) + (z * z) * C2) *
122 123 (C3 + z * (C4 + z)));
123 124 } else if (hx > 0) {
124 125 y = (y - pio2_1) - pio2_t;
125 126 z = y * y;
126 127 *s = (float)(((C0 + z * C1) + (z * z) * C2) *
127 128 (C3 + z * (C4 + z)));
128 129 *c = (float)-((y * (S0 + z * S1)) *
129 130 (S2 + z * (S3 + z)));
130 131 } else {
131 132 y = (y + pio2_1) + pio2_t;
132 133 z = y * y;
133 134 *s = (float)-(((C0 + z * C1) + (z * z) * C2) *
134 135 (C3 + z * (C4 + z)));
135 136 *c = (float)((y * (S0 + z * S1)) *
136 137 (S2 + z * (S3 + z)));
137 138 }
138 139 return;
139 140 } else if (ix <= 0x49c90fdb) { /* |x| < 2^19*pi */
140 141 #if defined(__i386) && !defined(__amd64)
141 142 int rp;
142 143
143 144 rp = __swapRP(fp_extended);
144 145 #endif
145 146 w = y * invpio2;
146 147 if (hx < 0)
147 148 n = (int)(w - half);
148 149 else
149 150 n = (int)(w + half);
150 151 y = (y - n * pio2_1) - n * pio2_t;
151 152 #if defined(__i386) && !defined(__amd64)
152 153 if (rp != fp_extended)
153 154 (void) __swapRP(rp);
154 155 #endif
155 156 } else {
156 157 if (ix >= 0x7f800000) {
157 158 *s = *c = x / x;
158 159 return;
159 160 }
160 161 hy = ((int *)&y)[HIWORD];
161 162 n = ((hy >> 20) & 0x7ff) - 1046;
162 163 ((int *)&w)[HIWORD] = (hy & 0xfffff) | 0x41600000;
163 164 ((int *)&w)[LOWORD] = ((int *)&y)[LOWORD];
164 165 n = __rem_pio2m(&w, &y, n, 1, 0, _TBL_ipio2_inf);
165 166 if (hy < 0) {
166 167 y = -y;
167 168 n = -n;
168 169 }
169 170 }
170 171
171 172 z = y * y;
172 173 f = (float)((y * (S0 + z * S1)) * (S2 + z * (S3 + z)));
173 174 g = (float)(((C0 + z * C1) + (z * z) * C2) *
174 175 (C3 + z * (C4 + z)));
175 176 if (n & 2) {
176 177 f = -f;
177 178 g = -g;
178 179 }
179 180 if (n & 1) {
180 181 *s = g;
181 182 *c = -f;
182 183 } else {
183 184 *s = f;
184 185 *c = g;
185 186 }
186 187 }
↓ open down ↓ |
66 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX