1*5b2ba9d3SPiotr Jasiukajtis /*
2*5b2ba9d3SPiotr Jasiukajtis * CDDL HEADER START
3*5b2ba9d3SPiotr Jasiukajtis *
4*5b2ba9d3SPiotr Jasiukajtis * The contents of this file are subject to the terms of the
5*5b2ba9d3SPiotr Jasiukajtis * Common Development and Distribution License (the "License").
6*5b2ba9d3SPiotr Jasiukajtis * You may not use this file except in compliance with the License.
7*5b2ba9d3SPiotr Jasiukajtis *
8*5b2ba9d3SPiotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5b2ba9d3SPiotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
10*5b2ba9d3SPiotr Jasiukajtis * See the License for the specific language governing permissions
11*5b2ba9d3SPiotr Jasiukajtis * and limitations under the License.
12*5b2ba9d3SPiotr Jasiukajtis *
13*5b2ba9d3SPiotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
14*5b2ba9d3SPiotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5b2ba9d3SPiotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
16*5b2ba9d3SPiotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
17*5b2ba9d3SPiotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
18*5b2ba9d3SPiotr Jasiukajtis *
19*5b2ba9d3SPiotr Jasiukajtis * CDDL HEADER END
20*5b2ba9d3SPiotr Jasiukajtis */
21*5b2ba9d3SPiotr Jasiukajtis /*
22*5b2ba9d3SPiotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23*5b2ba9d3SPiotr Jasiukajtis */
24*5b2ba9d3SPiotr Jasiukajtis /*
25*5b2ba9d3SPiotr Jasiukajtis * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26*5b2ba9d3SPiotr Jasiukajtis * Use is subject to license terms.
27*5b2ba9d3SPiotr Jasiukajtis */
28*5b2ba9d3SPiotr Jasiukajtis
29*5b2ba9d3SPiotr Jasiukajtis /* INDENT OFF */
30*5b2ba9d3SPiotr Jasiukajtis /*
31*5b2ba9d3SPiotr Jasiukajtis * __k_sin( double x; double y )
32*5b2ba9d3SPiotr Jasiukajtis * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.785398164
33*5b2ba9d3SPiotr Jasiukajtis * Input x is assumed to be bounded by ~pi/4 in magnitude.
34*5b2ba9d3SPiotr Jasiukajtis * Input y is the tail of x.
35*5b2ba9d3SPiotr Jasiukajtis *
36*5b2ba9d3SPiotr Jasiukajtis * Accurate Table look-up algorithm by K.C. Ng, May, 1995.
37*5b2ba9d3SPiotr Jasiukajtis *
38*5b2ba9d3SPiotr Jasiukajtis * Algorithm: see __sincos.c
39*5b2ba9d3SPiotr Jasiukajtis */
40*5b2ba9d3SPiotr Jasiukajtis
41*5b2ba9d3SPiotr Jasiukajtis #include "libm.h"
42*5b2ba9d3SPiotr Jasiukajtis
43*5b2ba9d3SPiotr Jasiukajtis static const double sc[] = {
44*5b2ba9d3SPiotr Jasiukajtis /* ONE = */ 1.0,
45*5b2ba9d3SPiotr Jasiukajtis /* NONE = */ -1.0,
46*5b2ba9d3SPiotr Jasiukajtis /*
47*5b2ba9d3SPiotr Jasiukajtis * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008
48*5b2ba9d3SPiotr Jasiukajtis */
49*5b2ba9d3SPiotr Jasiukajtis /* PP1 = */ -0.166666666666316558867252052378889521480627858683055567,
50*5b2ba9d3SPiotr Jasiukajtis /* PP2 = */ .008333315652997472323564894248466758248475374977974017927,
51*5b2ba9d3SPiotr Jasiukajtis /*
52*5b2ba9d3SPiotr Jasiukajtis * |(sin(x) - (x+p1*x^3+...+p4*x^9)|
53*5b2ba9d3SPiotr Jasiukajtis * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125
54*5b2ba9d3SPiotr Jasiukajtis * | x |
55*5b2ba9d3SPiotr Jasiukajtis */
56*5b2ba9d3SPiotr Jasiukajtis /* P1 = */ -1.666666666666629669805215138920301589656e-0001,
57*5b2ba9d3SPiotr Jasiukajtis /* P2 = */ 8.333333332390951295683993455280336376663e-0003,
58*5b2ba9d3SPiotr Jasiukajtis /* P3 = */ -1.984126237997976692791551778230098403960e-0004,
59*5b2ba9d3SPiotr Jasiukajtis /* P4 = */ 2.753403624854277237649987622848330351110e-0006,
60*5b2ba9d3SPiotr Jasiukajtis /*
61*5b2ba9d3SPiotr Jasiukajtis * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d)
62*5b2ba9d3SPiotr Jasiukajtis */
63*5b2ba9d3SPiotr Jasiukajtis /* QQ1 = */ -0.4999999999975492381842911981948418542742729,
64*5b2ba9d3SPiotr Jasiukajtis /* QQ2 = */ 0.041666542904352059294545209158357640398771740,
65*5b2ba9d3SPiotr Jasiukajtis /*
66*5b2ba9d3SPiotr Jasiukajtis * |cos(x) - (1+q1*x^2+...+q4*x^8)| <= 2^-55.86 for |x| <= 0.1640625 (10.5/64)
67*5b2ba9d3SPiotr Jasiukajtis */
68*5b2ba9d3SPiotr Jasiukajtis /* Q1 = */ -0.5,
69*5b2ba9d3SPiotr Jasiukajtis /* Q2 = */ 4.166666666500350703680945520860748617445e-0002,
70*5b2ba9d3SPiotr Jasiukajtis /* Q3 = */ -1.388888596436972210694266290577848696006e-0003,
71*5b2ba9d3SPiotr Jasiukajtis /* Q4 = */ 2.478563078858589473679519517892953492192e-0005,
72*5b2ba9d3SPiotr Jasiukajtis };
73*5b2ba9d3SPiotr Jasiukajtis /* INDENT ON */
74*5b2ba9d3SPiotr Jasiukajtis
75*5b2ba9d3SPiotr Jasiukajtis #define ONE sc[0]
76*5b2ba9d3SPiotr Jasiukajtis #define NONE sc[1]
77*5b2ba9d3SPiotr Jasiukajtis #define PP1 sc[2]
78*5b2ba9d3SPiotr Jasiukajtis #define PP2 sc[3]
79*5b2ba9d3SPiotr Jasiukajtis #define P1 sc[4]
80*5b2ba9d3SPiotr Jasiukajtis #define P2 sc[5]
81*5b2ba9d3SPiotr Jasiukajtis #define P3 sc[6]
82*5b2ba9d3SPiotr Jasiukajtis #define P4 sc[7]
83*5b2ba9d3SPiotr Jasiukajtis #define QQ1 sc[8]
84*5b2ba9d3SPiotr Jasiukajtis #define QQ2 sc[9]
85*5b2ba9d3SPiotr Jasiukajtis #define Q1 sc[10]
86*5b2ba9d3SPiotr Jasiukajtis #define Q2 sc[11]
87*5b2ba9d3SPiotr Jasiukajtis #define Q3 sc[12]
88*5b2ba9d3SPiotr Jasiukajtis #define Q4 sc[13]
89*5b2ba9d3SPiotr Jasiukajtis
90*5b2ba9d3SPiotr Jasiukajtis extern const double _TBL_sincos[], _TBL_sincosx[];
91*5b2ba9d3SPiotr Jasiukajtis
92*5b2ba9d3SPiotr Jasiukajtis double
__k_sin(double x,double y)93*5b2ba9d3SPiotr Jasiukajtis __k_sin(double x, double y) {
94*5b2ba9d3SPiotr Jasiukajtis double z, w, s, v, p, q;
95*5b2ba9d3SPiotr Jasiukajtis int i, j, n, hx, ix;
96*5b2ba9d3SPiotr Jasiukajtis
97*5b2ba9d3SPiotr Jasiukajtis hx = ((int *)&x)[HIWORD];
98*5b2ba9d3SPiotr Jasiukajtis ix = hx & ~0x80000000;
99*5b2ba9d3SPiotr Jasiukajtis
100*5b2ba9d3SPiotr Jasiukajtis if (ix <= 0x3fc50000) { /* |x| < 10.5/64 = 0.164062500 */
101*5b2ba9d3SPiotr Jasiukajtis if (ix < 0x3e400000) /* |x| < 2**-27 */
102*5b2ba9d3SPiotr Jasiukajtis if ((int)x == 0)
103*5b2ba9d3SPiotr Jasiukajtis return (x + y);
104*5b2ba9d3SPiotr Jasiukajtis z = x * x;
105*5b2ba9d3SPiotr Jasiukajtis if (ix < 0x3f800000) /* |x| < 0.008 */
106*5b2ba9d3SPiotr Jasiukajtis p = (x * z) * (PP1 + z * PP2) + y;
107*5b2ba9d3SPiotr Jasiukajtis else
108*5b2ba9d3SPiotr Jasiukajtis p = (x * z) * ((P1 + z * P2) + (z * z) * (P3 +
109*5b2ba9d3SPiotr Jasiukajtis z * P4)) + y;
110*5b2ba9d3SPiotr Jasiukajtis return (x + p);
111*5b2ba9d3SPiotr Jasiukajtis } else { /* 0.164062500 < |x| < ~pi/4 */
112*5b2ba9d3SPiotr Jasiukajtis n = ix >> 20;
113*5b2ba9d3SPiotr Jasiukajtis i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n);
114*5b2ba9d3SPiotr Jasiukajtis j = i - 10;
115*5b2ba9d3SPiotr Jasiukajtis if (hx < 0)
116*5b2ba9d3SPiotr Jasiukajtis v = -y - (_TBL_sincosx[j] + x);
117*5b2ba9d3SPiotr Jasiukajtis else
118*5b2ba9d3SPiotr Jasiukajtis v = y - (_TBL_sincosx[j] - x);
119*5b2ba9d3SPiotr Jasiukajtis s = v * v;
120*5b2ba9d3SPiotr Jasiukajtis j <<= 1;
121*5b2ba9d3SPiotr Jasiukajtis w = _TBL_sincos[j];
122*5b2ba9d3SPiotr Jasiukajtis z = _TBL_sincos[j+1];
123*5b2ba9d3SPiotr Jasiukajtis p = s * (PP1 + s * PP2);
124*5b2ba9d3SPiotr Jasiukajtis q = s * (QQ1 + s * QQ2);
125*5b2ba9d3SPiotr Jasiukajtis p = v + v * p;
126*5b2ba9d3SPiotr Jasiukajtis s = w * q + z * p;
127*5b2ba9d3SPiotr Jasiukajtis return ((hx >= 0)? w + s : -(w + s));
128*5b2ba9d3SPiotr Jasiukajtis }
129*5b2ba9d3SPiotr Jasiukajtis }
130