13a8617a8SJordan K. Hubbard /* k_tanf.c -- float version of k_tan.c 23a8617a8SJordan K. Hubbard * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 33a8617a8SJordan K. Hubbard */ 43a8617a8SJordan K. Hubbard 53a8617a8SJordan K. Hubbard /* 63a8617a8SJordan K. Hubbard * ==================================================== 773fbb89dSDavid Schultz * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. 83a8617a8SJordan K. Hubbard * 93a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this 103a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice 113a8617a8SJordan K. Hubbard * is preserved. 123a8617a8SJordan K. Hubbard * ==================================================== 133a8617a8SJordan K. Hubbard */ 143a8617a8SJordan K. Hubbard 153a8617a8SJordan K. Hubbard #ifndef lint 167f3dea24SPeter Wemm static char rcsid[] = "$FreeBSD$"; 173a8617a8SJordan K. Hubbard #endif 183a8617a8SJordan K. Hubbard 193a8617a8SJordan K. Hubbard #include "math.h" 203a8617a8SJordan K. Hubbard #include "math_private.h" 21e96c4fd9SBruce Evans 223a8617a8SJordan K. Hubbard static const float 233a8617a8SJordan K. Hubbard pio4 = 7.8539812565e-01, /* 0x3f490fda */ 243a8617a8SJordan K. Hubbard pio4lo= 3.7748947079e-08, /* 0x33222168 */ 25e96c4fd9SBruce Evans /* |tan(x)/x - t(x)| < 2**-29.2 (~[-1.73e-09, 1.724e-09]). */ 263a8617a8SJordan K. Hubbard T[] = { 27c01611e4SBruce Evans 0xaaaaa3.0p-25, /* 0.33333310485 */ 28c01611e4SBruce Evans 0x888b06.0p-26, /* 0.13334283238 */ 29c01611e4SBruce Evans 0xdc84c8.0p-28, /* 0.053837567568 */ 30c01611e4SBruce Evans 0xb9d8f1.0p-29, /* 0.022686453536 */ 31c01611e4SBruce Evans 0xcfe632.0p-31, /* 0.0063445800915 */ 32c01611e4SBruce Evans 0xeaf97e.0p-31, /* 0.0071708550677 */ 333a8617a8SJordan K. Hubbard }; 343a8617a8SJordan K. Hubbard 3559b19ff1SAlfred Perlstein float 3659b19ff1SAlfred Perlstein __kernel_tanf(float x, float y, int iy) 373a8617a8SJordan K. Hubbard { 383a8617a8SJordan K. Hubbard float z,r,v,w,s; 393a8617a8SJordan K. Hubbard int32_t ix,hx; 40e96c4fd9SBruce Evans 413a8617a8SJordan K. Hubbard GET_FLOAT_WORD(hx,x); 42e96c4fd9SBruce Evans ix = hx&0x7fffffff; 43e96c4fd9SBruce Evans if(ix>=0x3f2ca140) { /* |x|>=0.67434 */ 443a8617a8SJordan K. Hubbard if(hx<0) {x = -x; y = -y;} 453a8617a8SJordan K. Hubbard z = pio4-x; 463a8617a8SJordan K. Hubbard w = pio4lo-y; 473a8617a8SJordan K. Hubbard x = z+w; y = 0.0; 483a8617a8SJordan K. Hubbard } 493a8617a8SJordan K. Hubbard z = x*x; 503a8617a8SJordan K. Hubbard w = z*z; 513a8617a8SJordan K. Hubbard /* Break x^5*(T[1]+x^2*T[2]+...) into 52c01611e4SBruce Evans * x^5*(T[1]+x^4*T[3]+x^8*T[5]) + 53c01611e4SBruce Evans * x^5*(x^2*(T[2]+x^4*T[4])) 543a8617a8SJordan K. Hubbard */ 55c01611e4SBruce Evans r = T[1]+w*(T[3]+w*T[5]); 56c01611e4SBruce Evans v = z*(T[2]+w*T[4]); 573a8617a8SJordan K. Hubbard s = z*x; 583a8617a8SJordan K. Hubbard r = y + z*(s*(r+v)+y); 593a8617a8SJordan K. Hubbard r += T[0]*s; 603a8617a8SJordan K. Hubbard w = x+r; 613a8617a8SJordan K. Hubbard if(ix>=0x3f2ca140) { 623a8617a8SJordan K. Hubbard v = (float)iy; 633a8617a8SJordan K. Hubbard return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r))); 643a8617a8SJordan K. Hubbard } 653a8617a8SJordan K. Hubbard if(iy==1) return w; 663a8617a8SJordan K. Hubbard else { /* if allow error up to 2 ulp, 673a8617a8SJordan K. Hubbard simply return -1.0/(x+r) here */ 683a8617a8SJordan K. Hubbard /* compute -1.0/(x+r) accurately */ 693a8617a8SJordan K. Hubbard float a,t; 703a8617a8SJordan K. Hubbard int32_t i; 713a8617a8SJordan K. Hubbard z = w; 723a8617a8SJordan K. Hubbard GET_FLOAT_WORD(i,z); 733a8617a8SJordan K. Hubbard SET_FLOAT_WORD(z,i&0xfffff000); 743a8617a8SJordan K. Hubbard v = r-(z - x); /* z+v = r+x */ 753a8617a8SJordan K. Hubbard t = a = -(float)1.0/w; /* a = -1.0/w */ 763a8617a8SJordan K. Hubbard GET_FLOAT_WORD(i,t); 773a8617a8SJordan K. Hubbard SET_FLOAT_WORD(t,i&0xfffff000); 783a8617a8SJordan K. Hubbard s = (float)1.0+t*z; 793a8617a8SJordan K. Hubbard return t+a*(s+t*v); 803a8617a8SJordan K. Hubbard } 813a8617a8SJordan K. Hubbard } 82