k_tanf.c revision 152647
159158Sache/* k_tanf.c -- float version of k_tan.c 259158Sache * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 359158Sache */ 459158Sache 559158Sache/* 659158Sache * ==================================================== 759158Sache * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. 859158Sache * 959158Sache * Permission to use, copy, modify, and distribute this 1059158Sache * software is freely granted, provided that this notice 1159158Sache * is preserved. 1259158Sache * ==================================================== 1359158Sache */ 1459158Sache 1559158Sache#ifndef INLINE_KERNEL_TANF 1659158Sache#ifndef lint 1759158Sachestatic char rcsid[] = "$FreeBSD: head/lib/msun/src/k_tanf.c 152647 2005-11-21 04:57:12Z bde $"; 1859158Sache#endif 1959158Sache#endif 2059158Sache 2159158Sache#include "math.h" 2259158Sache#include "math_private.h" 2359158Sache 2459158Sachestatic const float 2559158Sachepio4 = 7.8539812565e-01, /* 0x3f490fda */ 2659158Sachepio4lo= 3.7748947079e-08, /* 0x33222168 */ 2759158Sache/* |tan(x)/x - t(x)| < 2**-29.2 (~[-1.73e-09, 1.724e-09]). */ 2859158SacheT[] = { 2959158Sache 0xaaaaa3.0p-25, /* 0.33333310485 */ 3059158Sache 0x888b06.0p-26, /* 0.13334283238 */ 3159158Sache 0xdc84c8.0p-28, /* 0.053837567568 */ 3259158Sache 0xb9d8f1.0p-29, /* 0.022686453536 */ 3359158Sache 0xcfe632.0p-31, /* 0.0063445800915 */ 3459158Sache 0xeaf97e.0p-31, /* 0.0071708550677 */ 3559158Sache}; 3659158Sache 3759158Sache#ifdef INLINE_KERNEL_TANF 3859158Sacheextern inline 3959158Sache#endif 4059158Sachefloat 4159158Sache__kernel_tanf(float x, float y, int iy) 4259158Sache{ 4359158Sache float z,r,v,w,s; 4459158Sache int32_t ix,hx; 4559158Sache 4659158Sache GET_FLOAT_WORD(hx,x); 4759158Sache ix = hx&0x7fffffff; 4859158Sache if(ix>=0x3f2ca140) { /* |x|>=0.67434 */ 4959158Sache if(hx<0) {x = -x; y = -y;} 5059158Sache z = pio4-x; 5159158Sache w = pio4lo-y; 5259158Sache x = z+w; y = 0.0; 5359158Sache } 5459158Sache z = x*x; 5559158Sache w = z*z; 5659158Sache /* Break x^5*(T[1]+x^2*T[2]+...) into 5759158Sache * x^5*(T[1]+x^4*T[3]+x^8*T[5]) + 5859158Sache * x^5*(x^2*(T[2]+x^4*T[4])) 5959158Sache */ 6059158Sache r = T[1]+w*(T[3]+w*T[5]); 6159158Sache v = z*(T[2]+w*T[4]); 6259158Sache s = z*x; 6359158Sache r = y + z*(s*(r+v)+y); 6459158Sache r += T[0]*s; 6559158Sache w = x+r; 6659158Sache if(ix>=0x3f2ca140) { 6759158Sache v = (float)iy; 6859158Sache return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r))); 6959158Sache } 7059158Sache if(iy==1) return w; 7159158Sache else return -1.0/((double)x+r); 7259158Sache} 7359158Sache