k_tanf.c revision 97413
12116Sjkh/* k_tanf.c -- float version of k_tan.c 22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 32116Sjkh */ 42116Sjkh 52116Sjkh/* 62116Sjkh * ==================================================== 72116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 82116Sjkh * 92116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 102116Sjkh * Permission to use, copy, modify, and distribute this 118870Srgrimes * software is freely granted, provided that this notice 122116Sjkh * is preserved. 132116Sjkh * ==================================================== 142116Sjkh */ 152116Sjkh 162116Sjkh#ifndef lint 1750476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/k_tanf.c 97413 2002-05-28 18:15:04Z alfred $"; 182116Sjkh#endif 192116Sjkh 202116Sjkh#include "math.h" 212116Sjkh#include "math_private.h" 228870Srgrimesstatic const float 232116Sjkhone = 1.0000000000e+00, /* 0x3f800000 */ 242116Sjkhpio4 = 7.8539812565e-01, /* 0x3f490fda */ 252116Sjkhpio4lo= 3.7748947079e-08, /* 0x33222168 */ 262116SjkhT[] = { 272116Sjkh 3.3333334327e-01, /* 0x3eaaaaab */ 282116Sjkh 1.3333334029e-01, /* 0x3e088889 */ 292116Sjkh 5.3968254477e-02, /* 0x3d5d0dd1 */ 302116Sjkh 2.1869488060e-02, /* 0x3cb327a4 */ 312116Sjkh 8.8632395491e-03, /* 0x3c11371f */ 322116Sjkh 3.5920790397e-03, /* 0x3b6b6916 */ 332116Sjkh 1.4562094584e-03, /* 0x3abede48 */ 342116Sjkh 5.8804126456e-04, /* 0x3a1a26c8 */ 352116Sjkh 2.4646313977e-04, /* 0x398137b9 */ 362116Sjkh 7.8179444245e-05, /* 0x38a3f445 */ 372116Sjkh 7.1407252108e-05, /* 0x3895c07a */ 382116Sjkh -1.8558637748e-05, /* 0xb79bae5f */ 392116Sjkh 2.5907305826e-05, /* 0x37d95384 */ 402116Sjkh}; 412116Sjkh 4297413Salfredfloat 4397413Salfred__kernel_tanf(float x, float y, int iy) 442116Sjkh{ 452116Sjkh float z,r,v,w,s; 462116Sjkh int32_t ix,hx; 472116Sjkh GET_FLOAT_WORD(hx,x); 482116Sjkh ix = hx&0x7fffffff; /* high word of |x| */ 492116Sjkh if(ix<0x31800000) /* x < 2**-28 */ 502116Sjkh {if((int)x==0) { /* generate inexact */ 512116Sjkh if((ix|(iy+1))==0) return one/fabsf(x); 522116Sjkh else return (iy==1)? x: -one/x; 532116Sjkh } 542116Sjkh } 552116Sjkh if(ix>=0x3f2ca140) { /* |x|>=0.6744 */ 562116Sjkh if(hx<0) {x = -x; y = -y;} 572116Sjkh z = pio4-x; 582116Sjkh w = pio4lo-y; 592116Sjkh x = z+w; y = 0.0; 602116Sjkh } 612116Sjkh z = x*x; 622116Sjkh w = z*z; 632116Sjkh /* Break x^5*(T[1]+x^2*T[2]+...) into 642116Sjkh * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + 652116Sjkh * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) 662116Sjkh */ 672116Sjkh r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11])))); 682116Sjkh v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12]))))); 692116Sjkh s = z*x; 702116Sjkh r = y + z*(s*(r+v)+y); 712116Sjkh r += T[0]*s; 722116Sjkh w = x+r; 732116Sjkh if(ix>=0x3f2ca140) { 742116Sjkh v = (float)iy; 752116Sjkh return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r))); 762116Sjkh } 772116Sjkh if(iy==1) return w; 788870Srgrimes else { /* if allow error up to 2 ulp, 792116Sjkh simply return -1.0/(x+r) here */ 802116Sjkh /* compute -1.0/(x+r) accurately */ 812116Sjkh float a,t; 822116Sjkh int32_t i; 832116Sjkh z = w; 842116Sjkh GET_FLOAT_WORD(i,z); 852116Sjkh SET_FLOAT_WORD(z,i&0xfffff000); 862116Sjkh v = r-(z - x); /* z+v = r+x */ 872116Sjkh t = a = -(float)1.0/w; /* a = -1.0/w */ 882116Sjkh GET_FLOAT_WORD(i,t); 892116Sjkh SET_FLOAT_WORD(t,i&0xfffff000); 902116Sjkh s = (float)1.0+t*z; 912116Sjkh return t+a*(s+t*v); 922116Sjkh } 932116Sjkh} 94