4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 #pragma weak __sin = sin
34 * Accurate Table look-up algorithm by K.C. Ng, May, 1995.
36 * Algorithm: see sincos.c
41 static const double sc
[] = {
45 * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008
47 /* PP1 = */ -0.166666666666316558867252052378889521480627858683055567,
48 /* PP2 = */ .008333315652997472323564894248466758248475374977974017927,
50 * |(sin(x) - (x+p1*x^3+...+p4*x^9)|
51 * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125
54 /* P1 = */ -1.666666666666629669805215138920301589656e-0001,
55 /* P2 = */ 8.333333332390951295683993455280336376663e-0003,
56 /* P3 = */ -1.984126237997976692791551778230098403960e-0004,
57 /* P4 = */ 2.753403624854277237649987622848330351110e-0006,
59 * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d)
61 /* QQ1 = */ -0.4999999999975492381842911981948418542742729,
62 /* QQ2 = */ 0.041666542904352059294545209158357640398771740,
63 /* PI_H = */ 3.1415926535897931159979634685,
64 /* PI_L = */ 1.22464679914735317722606593227425e-16,
65 /* PI_L0 = */ 1.22464679914558443311283879205095e-16,
66 /* PI_L1 = */ 1.768744113227140223300005233735517376e-28,
67 /* PI2_H = */ 6.2831853071795862319959269370,
68 /* PI2_L = */ 2.44929359829470635445213186454850e-16,
69 /* PI2_L0 = */ 2.44929359829116886622567758410190e-16,
70 /* PI2_L1 = */ 3.537488226454280446600010467471034752e-28,
94 extern const double _TBL_sincos
[], _TBL_sincosx
[];
98 double z
, y
[2], w
, s
, v
, p
, q
;
99 int i
, j
, n
, hx
, ix
, lx
;
101 hx
= ((int *)&x
)[HIWORD
];
102 lx
= ((int *)&x
)[LOWORD
];
103 ix
= hx
& ~0x80000000;
105 if (ix
<= 0x3fc50000) { /* |x| < .1640625 */
106 if (ix
< 0x3e400000) /* |x| < 2**-27 */
110 if (ix
< 0x3f800000) /* |x| < 2**-8 */
111 w
= (z
* x
) * (PP1
+ z
* PP2
);
113 w
= (x
* z
) * ((P1
+ z
* P2
) + (z
* z
) * (P3
+ z
* P4
));
117 /* for .1640625 < x < M, */
119 if (n
< 0x402) { /* x < 8 */
120 i
= (((ix
>> 12) & 0xff) | 0x100) >> (0x401 - n
);
123 v
= x
- _TBL_sincosx
[j
];
124 if (((j
- 181) ^ (j
- 201)) < 0) {
125 /* near pi, sin(x) = sin(pi-x) */
129 if ((i
| ((lx
- 0x54442D00) & 0xffffff00)) == 0) {
130 /* very close to pi */
132 return ((hx
>= 0)? x
+ PI_L1
: -(x
+ PI_L1
));
135 if (((ix
- 0x40092000) >> 11) == 0) {
137 w
= PI_L
+ (z
* x
) * (PP1
+ z
* PP2
);
139 w
= PI_L
+ (z
* x
) * ((P1
+ z
* P2
) +
140 (z
* z
) * (P3
+ z
* P4
));
142 return ((hx
>= 0)? p
+ w
: -p
- w
);
145 if (((j
- 382) ^ (j
- 402)) < 0) {
146 /* near 2pi, sin(x) = sin(x-2pi) */
150 if ((i
| ((lx
- 0x54442D00) & 0xffffff00)) == 0) {
151 /* very close to 2pi */
153 return ((hx
>= 0)? x
- PI2_L1
: -(x
- PI2_L1
));
156 if (((ix
- 0x40192000) >> 10) == 0) {
158 w
= (z
* x
) * (PP1
+ z
* PP2
) - PI2_L
;
160 w
= (z
* x
) * ((P1
+ z
* P2
) +
161 (z
* z
) * (P3
+ z
* P4
)) - PI2_L
;
163 return ((hx
>= 0)? p
+ w
: -p
- w
);
166 w
= _TBL_sincos
[j
+1];
168 p
= v
+ (v
* s
) * (PP1
+ s
* PP2
);
169 q
= s
* (QQ1
+ s
* QQ2
);
171 return ((hx
>= 0)? z
+ v
: -z
- v
);
174 if (ix
>= 0x7ff00000) /* sin(Inf or NaN) is NaN */
177 /* argument reduction needed */
178 n
= __rem_pio2(x
, y
);
181 return (__k_sin(y
[0], y
[1]));
183 return (__k_cos(y
[0], y
[1]));
185 return (-__k_sin(y
[0], y
[1]));
187 return (-__k_cos(y
[0], y
[1]));