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" 213a8617a8SJordan K. Hubbard static const float 223a8617a8SJordan K. Hubbard one = 1.0000000000e+00, /* 0x3f800000 */ 233a8617a8SJordan K. Hubbard pio4 = 7.8539812565e-01, /* 0x3f490fda */ 243a8617a8SJordan K. Hubbard pio4lo= 3.7748947079e-08, /* 0x33222168 */ 25c01611e4SBruce Evans /* Bounds for tan(x)/x - t(x): ~[-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; 403a8617a8SJordan K. Hubbard GET_FLOAT_WORD(hx,x); 413a8617a8SJordan K. Hubbard ix = hx&0x7fffffff; /* high word of |x| */ 423a8617a8SJordan K. Hubbard if(ix>=0x3f2ca140) { /* |x|>=0.6744 */ 433a8617a8SJordan K. Hubbard if(hx<0) {x = -x; y = -y;} 443a8617a8SJordan K. Hubbard z = pio4-x; 453a8617a8SJordan K. Hubbard w = pio4lo-y; 463a8617a8SJordan K. Hubbard x = z+w; y = 0.0; 473a8617a8SJordan K. Hubbard } 483a8617a8SJordan K. Hubbard z = x*x; 493a8617a8SJordan K. Hubbard w = z*z; 503a8617a8SJordan K. Hubbard /* Break x^5*(T[1]+x^2*T[2]+...) into 51c01611e4SBruce Evans * x^5*(T[1]+x^4*T[3]+x^8*T[5]) + 52c01611e4SBruce Evans * x^5*(x^2*(T[2]+x^4*T[4])) 533a8617a8SJordan K. Hubbard */ 54c01611e4SBruce Evans r = T[1]+w*(T[3]+w*T[5]); 55c01611e4SBruce Evans v = z*(T[2]+w*T[4]); 563a8617a8SJordan K. Hubbard s = z*x; 573a8617a8SJordan K. Hubbard r = y + z*(s*(r+v)+y); 583a8617a8SJordan K. Hubbard r += T[0]*s; 593a8617a8SJordan K. Hubbard w = x+r; 603a8617a8SJordan K. Hubbard if(ix>=0x3f2ca140) { 613a8617a8SJordan K. Hubbard v = (float)iy; 623a8617a8SJordan K. Hubbard return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r))); 633a8617a8SJordan K. Hubbard } 643a8617a8SJordan K. Hubbard if(iy==1) return w; 653a8617a8SJordan K. Hubbard else { /* if allow error up to 2 ulp, 663a8617a8SJordan K. Hubbard simply return -1.0/(x+r) here */ 673a8617a8SJordan K. Hubbard /* compute -1.0/(x+r) accurately */ 683a8617a8SJordan K. Hubbard float a,t; 693a8617a8SJordan K. Hubbard int32_t i; 703a8617a8SJordan K. Hubbard z = w; 713a8617a8SJordan K. Hubbard GET_FLOAT_WORD(i,z); 723a8617a8SJordan K. Hubbard SET_FLOAT_WORD(z,i&0xfffff000); 733a8617a8SJordan K. Hubbard v = r-(z - x); /* z+v = r+x */ 743a8617a8SJordan K. Hubbard t = a = -(float)1.0/w; /* a = -1.0/w */ 753a8617a8SJordan K. Hubbard GET_FLOAT_WORD(i,t); 763a8617a8SJordan K. Hubbard SET_FLOAT_WORD(t,i&0xfffff000); 773a8617a8SJordan K. Hubbard s = (float)1.0+t*z; 783a8617a8SJordan K. Hubbard return t+a*(s+t*v); 793a8617a8SJordan K. Hubbard } 803a8617a8SJordan K. Hubbard } 81