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 154ce51209SBruce Evans #ifndef INLINE_KERNEL_TANF 163a8617a8SJordan K. Hubbard #ifndef lint 177f3dea24SPeter Wemm static char rcsid[] = "$FreeBSD$"; 183a8617a8SJordan K. Hubbard #endif 194ce51209SBruce Evans #endif 203a8617a8SJordan K. Hubbard 213a8617a8SJordan K. Hubbard #include "math.h" 223a8617a8SJordan K. Hubbard #include "math_private.h" 23e96c4fd9SBruce Evans 243a8617a8SJordan K. Hubbard static const float 253a8617a8SJordan K. Hubbard pio4 = 7.8539812565e-01, /* 0x3f490fda */ 263a8617a8SJordan K. Hubbard pio4lo= 3.7748947079e-08, /* 0x33222168 */ 27e96c4fd9SBruce Evans /* |tan(x)/x - t(x)| < 2**-29.2 (~[-1.73e-09, 1.724e-09]). */ 283a8617a8SJordan K. Hubbard T[] = { 29c01611e4SBruce Evans 0xaaaaa3.0p-25, /* 0.33333310485 */ 30c01611e4SBruce Evans 0x888b06.0p-26, /* 0.13334283238 */ 31c01611e4SBruce Evans 0xdc84c8.0p-28, /* 0.053837567568 */ 32c01611e4SBruce Evans 0xb9d8f1.0p-29, /* 0.022686453536 */ 33c01611e4SBruce Evans 0xcfe632.0p-31, /* 0.0063445800915 */ 34c01611e4SBruce Evans 0xeaf97e.0p-31, /* 0.0071708550677 */ 353a8617a8SJordan K. Hubbard }; 363a8617a8SJordan K. Hubbard 374ce51209SBruce Evans #ifdef INLINE_KERNEL_TANF 384ce51209SBruce Evans extern inline 394ce51209SBruce Evans #endif 4059b19ff1SAlfred Perlstein float 4159b19ff1SAlfred Perlstein __kernel_tanf(float x, float y, int iy) 423a8617a8SJordan K. Hubbard { 433a8617a8SJordan K. Hubbard float z,r,v,w,s; 443a8617a8SJordan K. Hubbard int32_t ix,hx; 45e96c4fd9SBruce Evans 463a8617a8SJordan K. Hubbard GET_FLOAT_WORD(hx,x); 47e96c4fd9SBruce Evans ix = hx&0x7fffffff; 48e96c4fd9SBruce Evans if(ix>=0x3f2ca140) { /* |x|>=0.67434 */ 493a8617a8SJordan K. Hubbard if(hx<0) {x = -x; y = -y;} 503a8617a8SJordan K. Hubbard z = pio4-x; 513a8617a8SJordan K. Hubbard w = pio4lo-y; 523a8617a8SJordan K. Hubbard x = z+w; y = 0.0; 533a8617a8SJordan K. Hubbard } 543a8617a8SJordan K. Hubbard z = x*x; 553a8617a8SJordan K. Hubbard w = z*z; 563a8617a8SJordan K. Hubbard /* Break x^5*(T[1]+x^2*T[2]+...) into 57c01611e4SBruce Evans * x^5*(T[1]+x^4*T[3]+x^8*T[5]) + 58c01611e4SBruce Evans * x^5*(x^2*(T[2]+x^4*T[4])) 593a8617a8SJordan K. Hubbard */ 60c01611e4SBruce Evans r = T[1]+w*(T[3]+w*T[5]); 61c01611e4SBruce Evans v = z*(T[2]+w*T[4]); 623a8617a8SJordan K. Hubbard s = z*x; 633a8617a8SJordan K. Hubbard r = y + z*(s*(r+v)+y); 643a8617a8SJordan K. Hubbard r += T[0]*s; 653a8617a8SJordan K. Hubbard w = x+r; 663a8617a8SJordan K. Hubbard if(ix>=0x3f2ca140) { 673a8617a8SJordan K. Hubbard v = (float)iy; 683a8617a8SJordan K. Hubbard return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r))); 693a8617a8SJordan K. Hubbard } 703a8617a8SJordan K. Hubbard if(iy==1) return w; 7158652034SBruce Evans else return -1.0/((double)x+r); 723a8617a8SJordan K. Hubbard } 73