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