/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* INDENT OFF */
/*
* sin(x)
* Accurate Table look-up algorithm by K.C. Ng, May, 1995.
*
* Algorithm: see sincos.c
*/
#include "libm.h"
static const double sc[] = {
/* ONE = */ 1.0,
/* NONE = */ -1.0,
/*
* |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008
*/
/* PP1 = */ -0.166666666666316558867252052378889521480627858683055567,
/* PP2 = */ .008333315652997472323564894248466758248475374977974017927,
/*
* |(sin(x) - (x+p1*x^3+...+p4*x^9)|
* |------------------------------ | <= 2^-57.63 for |x| < 0.1953125
* | x |
*/
/* P1 = */ -1.666666666666629669805215138920301589656e-0001,
/* P2 = */ 8.333333332390951295683993455280336376663e-0003,
/* P3 = */ -1.984126237997976692791551778230098403960e-0004,
/* P4 = */ 2.753403624854277237649987622848330351110e-0006,
/*
* |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d)
*/
/* QQ1 = */ -0.4999999999975492381842911981948418542742729,
/* QQ2 = */ 0.041666542904352059294545209158357640398771740,
/* PI_H = */ 3.1415926535897931159979634685,
/* PI_L = */ 1.22464679914735317722606593227425e-16,
/* PI_L0 = */ 1.22464679914558443311283879205095e-16,
/* PI_L1 = */ 1.768744113227140223300005233735517376e-28,
/* PI2_H = */ 6.2831853071795862319959269370,
/* PI2_L = */ 2.44929359829470635445213186454850e-16,
/* PI2_L0 = */ 2.44929359829116886622567758410190e-16,
/* PI2_L1 = */ 3.537488226454280446600010467471034752e-28,
};
/* INDENT ON */
extern const double _TBL_sincos[], _TBL_sincosx[];
double
sin(double x) {
double z, y[2], w, s, v, p, q;
if ((int)x == 0)
return (x);
z = x * x;
else
return (x + w);
}
/* for .1640625 < x < M, */
n = ix >> 20;
if (n < 0x402) { /* x < 8 */
j = i - 10;
x = fabs(x);
v = x - _TBL_sincosx[j];
if (((j - 181) ^ (j - 201)) < 0) {
/* near pi, sin(x) = sin(pi-x) */
p = PI_H - x;
i = ix - 0x400921fb;
x = p + PI_L;
/* very close to pi */
x = p + PI_L0;
}
z = x * x;
/* |pi-x|<2**-8 */
} else {
}
return ((hx >= 0)? p + w : -p - w);
}
s = v * v;
if (((j - 382) ^ (j - 402)) < 0) {
/* near 2pi, sin(x) = sin(x-2pi) */
p = x - PI2_H;
i = ix - 0x401921fb;
x = p - PI2_L;
/* very close to 2pi */
x = p - PI2_L0;
}
z = x * x;
/* |x-2pi|<2**-8 */
} else {
}
return ((hx >= 0)? p + w : -p - w);
}
j <<= 1;
w = _TBL_sincos[j+1];
z = _TBL_sincos[j];
v = w * p + z * q;
return ((hx >= 0)? z + v : -z - v);
}
return (x / x);
/* argument reduction needed */
n = __rem_pio2(x, y);
switch (n & 3) {
case 0:
return (__k_sin(y[0], y[1]));
case 1:
return (__k_cos(y[0], y[1]));
case 2:
return (-__k_sin(y[0], y[1]));
default:
return (-__k_cos(y[0], y[1]));
}
}