k_sin.c revision 141296
1141296Sdas
2141296Sdas/* @(#)k_sin.c 1.3 95/01/18 */
32116Sjkh/*
42116Sjkh * ====================================================
52116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
62116Sjkh *
7141296Sdas * Developed at SunSoft, a Sun Microsystems, Inc. business.
82116Sjkh * Permission to use, copy, modify, and distribute this
9141296Sdas * software is freely granted, provided that this notice
102116Sjkh * is preserved.
112116Sjkh * ====================================================
122116Sjkh */
132116Sjkh
142116Sjkh#ifndef lint
1550476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/k_sin.c 141296 2005-02-04 18:26:06Z das $";
162116Sjkh#endif
172116Sjkh
182116Sjkh/* __kernel_sin( x, y, iy)
192116Sjkh * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
202116Sjkh * Input x is assumed to be bounded by ~pi/4 in magnitude.
212116Sjkh * Input y is the tail of x.
22141296Sdas * Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
232116Sjkh *
242116Sjkh * Algorithm
25141296Sdas *	1. Since sin(-x) = -sin(x), we need only to consider positive x.
262116Sjkh *	2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
272116Sjkh *	3. sin(x) is approximated by a polynomial of degree 13 on
282116Sjkh *	   [0,pi/4]
292116Sjkh *		  	         3            13
302116Sjkh *	   	sin(x) ~ x + S1*x + ... + S6*x
312116Sjkh *	   where
32141296Sdas *
332116Sjkh * 	|sin(x)         2     4     6     8     10     12  |     -58
342116Sjkh * 	|----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x  +S6*x   )| <= 2
35141296Sdas * 	|  x 					           |
36141296Sdas *
372116Sjkh *	4. sin(x+y) = sin(x) + sin'(x')*y
382116Sjkh *		    ~ sin(x) + (1-x*x/2)*y
39141296Sdas *	   For better accuracy, let
402116Sjkh *		     3      2      2      2      2
412116Sjkh *		r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
422116Sjkh *	   then                   3    2
432116Sjkh *		sin(x) = x + (S1*x + (x *(r-y/2)+y))
442116Sjkh */
452116Sjkh
462116Sjkh#include "math.h"
472116Sjkh#include "math_private.h"
482116Sjkh
498870Srgrimesstatic const double
502116Sjkhhalf =  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
512116SjkhS1  = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
522116SjkhS2  =  8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
532116SjkhS3  = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
542116SjkhS4  =  2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
552116SjkhS5  = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
562116SjkhS6  =  1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
572116Sjkh
5897413Salfreddouble
5997413Salfred__kernel_sin(double x, double y, int iy)
602116Sjkh{
612116Sjkh	double z,r,v;
622116Sjkh	int32_t ix;
632116Sjkh	GET_HIGH_WORD(ix,x);
642116Sjkh	ix &= 0x7fffffff;			/* high word of x */
652116Sjkh	if(ix<0x3e400000)			/* |x| < 2**-27 */
662116Sjkh	   {if((int)x==0) return x;}		/* generate inexact */
672116Sjkh	z	=  x*x;
682116Sjkh	v	=  z*x;
692116Sjkh	r	=  S2+z*(S3+z*(S4+z*(S5+z*S6)));
702116Sjkh	if(iy==0) return x+v*(S1+z*r);
712116Sjkh	else      return x-((z*(half*y-v*r)-y)-v*S1);
722116Sjkh}
73