/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* long double __k_sinl(long double x, long double y);
* kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.785398164
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
*
* Table look up algorithm
* 1. by sin(-x) = -sin(x), need only to consider positive x
* 2. if x < 25/128 = [0x3ffc9000,0,0,0] = 0.1953125 , then
* if x < 2^-57 (hx < 0x3fc60000,0,0,0), return x (inexact if x != 0)
* z = x*x;
* if x <= 1/64 = 2**-6
* sin(x) = x + (y+(x*z)*(p1 + z*p2))
* else
* sin(x) = x + (y+(x*z)*(p1 + z*(p2 + z*(p3 + z*p4))))
* 3. else
* ht = (hx + 0x400)&0x7ffff800 (round x to a break point t)
* lt = 0
* i = (hy-0x3ffc4000)>>11; (i<=64)
* x' = (x - t)+y (|x'| ~<= 2^-7
* By
* sin(t+x')
* = sin(t)cos(x')+cos(t)sin(x')
* = sin(t)(1+z*(qq1+z*qq2))+[cos(t)]*x*(1+z*(pp1+z*pp2))
* = sin(t) + [sin(t)]*(z*(qq1+z*qq2))+
* [cos(t)]*x*(1+z*(pp1+z*pp2))
*
* Thus,
* let a= _TBL_sin_hi[i], b = _TBL_sin_lo[i], c= _TBL_cos_hi[i],
* x = (x-t)+y
* z = x*x;
* sin(t+x) = a+(b+ ((c*x)*(1+z*(pp1+z*pp2))+a*(z*(qq1+z*qq2)))
*/
#include "libm.h"
static const long double
/*
* 3 11 -122.32
* |sin(x) - (x+pp1*x +...+ pp5*x )| <= 2 for |x|<1/64
*/
/*
* |(sin(x) - (x+p1*x^3+...+p8*x^17)|
* |------------------------------- | <= 2^-116.17 for |x|<0.1953125
* | x |
*/
/*
* 2 10 -123.84
* |cos(x) - (1+qq1*x +...+ qq5*x )| <= 2 for |x|<=1/128
*/
#define i0 0
long double
__k_sinl(long double x, long double y) {
long double a, t, z, w;
t = 1.0L;
if (ix < 0x3ffc9000) {
*(2 + (int *) &t) = -1; /* one-ulp */
*(1 + (int *) &t) = -1; /* one-ulp */
if (ix < 0x3fc60000)
if (((int) (x * t)) < 1)
return (x); /* inexact and underflow */
z = x * x;
t = y + x * t;
return (x + t);
}
i = (j - 0x3ffc4000) >> 11;
if (hx > 0)
x = y - (t - x);
else
x = (-y) - (t + x);
a = _TBL_sinl_hi[i];
z = x * x;
t = _TBL_cosl_hi[i] * w + a * t;
t += _TBL_sinl_lo[i];
if (hx < 0)
return (-a - t);
else
return (a + t);
}