Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/R/cosf.c
+++ new/usr/src/lib/libm/common/R/cosf.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 cosf = __cosf
30 30
31 31 /*
32 32 * See sincosf.c
33 33 */
34 34
35 35 #include "libm.h"
36 36
37 37 extern const int _TBL_ipio2_inf[];
38 38 extern int __rem_pio2m(double *, double *, int, int, int, const int *);
39 39 #if defined(__i386) && !defined(__amd64)
40 40 extern int __swapRP(int);
41 41 #endif
42 42
43 43 static const double C[] = {
44 44 1.85735322054308378716204874632872525989806770558e-0003,
45 45 -1.95035094218403635082921458859320791358115801259e-0004,
46 46 5.38400550766074785970952495168558701485841707252e+0002,
47 47 -3.31975110777873728964197739157371509422022905947e+0001,
48 48 1.09349482127188401868272000389539985058873853699e-0003,
49 49 -5.03324285989964979398034700054920226866107675091e-0004,
50 50 2.43792880266971107750418061559602239831538067410e-0005,
51 51 9.14499072605666582228127405245558035523741471271e+0002,
52 52 -3.63151270591815439197122504991683846785293207730e+0001,
53 53 0.636619772367581343075535, /* 2^ -1 * 1.45F306DC9C883 */
54 54 0.5,
55 55 1.570796326734125614166, /* 2^ 0 * 1.921FB54400000 */
56 56 6.077100506506192601475e-11, /* 2^-34 * 1.0B4611A626331 */
57 57 };
58 58
59 59 #define S0 C[0]
60 60 #define S1 C[1]
61 61 #define S2 C[2]
62 62 #define S3 C[3]
63 63 #define C0 C[4]
64 64 #define C1 C[5]
65 65 #define C2 C[6]
66 66 #define C3 C[7]
67 67 #define C4 C[8]
68 68 #define invpio2 C[9]
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
69 69 #define half C[10]
70 70 #define pio2_1 C[11]
71 71 #define pio2_t C[12]
72 72
73 73 float
74 74 cosf(float x)
75 75 {
76 76 double y, z, w;
77 77 float f;
78 78 int n, ix, hx, hy;
79 + volatile int i;
79 80
80 81 hx = *((int *)&x);
81 82 ix = hx & 0x7fffffff;
82 83
83 84 y = (double)x;
84 85
85 86 if (ix <= 0x4016cbe4) { /* |x| < 3*pi/4 */
86 87 if (ix <= 0x3f490fdb) { /* |x| < pi/4 */
87 88 if (ix <= 0x39800000) { /* |x| <= 2**-12 */
88 - volatile int i = (int)y;
89 + i = (int)y;
89 90 #ifdef lint
90 91 i = i;
91 92 #endif
92 93 return (1.0f);
93 94 }
94 95 z = y * y;
95 96 return ((float)(((C0 + z * C1) + (z * z) * C2) *
96 97 (C3 + z * (C4 + z))));
97 98 } else if (hx > 0) {
98 99 y = (y - pio2_1) - pio2_t;
99 100 z = y * y;
100 101 return ((float)-((y * (S0 + z * S1)) *
101 102 (S2 + z * (S3 + z))));
102 103 } else {
103 104 y = (y + pio2_1) + pio2_t;
104 105 z = y * y;
105 106 return ((float)((y * (S0 + z * S1)) *
106 107 (S2 + z * (S3 + z))));
107 108 }
108 109 } else if (ix <= 0x49c90fdb) { /* |x| < 2^19*pi */
109 110 #if defined(__i386) && !defined(__amd64)
110 111 int rp;
111 112
112 113 rp = __swapRP(fp_extended);
113 114 #endif
114 115 w = y * invpio2;
115 116 if (hx < 0)
116 117 n = (int)(w - half);
117 118 else
118 119 n = (int)(w + half);
119 120 y = (y - n * pio2_1) - n * pio2_t;
120 121 n++;
121 122 #if defined(__i386) && !defined(__amd64)
122 123 if (rp != fp_extended)
123 124 (void) __swapRP(rp);
124 125 #endif
125 126 } else {
126 127 if (ix >= 0x7f800000)
127 128 return (x / x); /* cos(Inf or NaN) is NaN */
128 129 hy = ((int *)&y)[HIWORD];
129 130 n = ((hy >> 20) & 0x7ff) - 1046;
130 131 ((int *)&w)[HIWORD] = (hy & 0xfffff) | 0x41600000;
131 132 ((int *)&w)[LOWORD] = ((int *)&y)[LOWORD];
132 133 n = __rem_pio2m(&w, &y, n, 1, 0, _TBL_ipio2_inf) + 1;
133 134 }
134 135
135 136 if (n & 1) {
136 137 /* compute cos y */
137 138 z = y * y;
138 139 f = (float)(((C0 + z * C1) + (z * z) * C2) *
139 140 (C3 + z * (C4 + z)));
140 141 } else {
141 142 /* compute sin y */
142 143 z = y * y;
143 144 f = (float)((y * (S0 + z * S1)) * (S2 + z * (S3 + z)));
144 145 }
145 146
146 147 return ((n & 2)? -f : f);
147 148 }
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX