]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/msun/src/k_tanf.c
This commit was generated by cvs2svn to compensate for changes in r126380,
[FreeBSD/FreeBSD.git] / lib / msun / src / k_tanf.c
1 /* k_tanf.c -- float version of k_tan.c
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  */
4
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
9  * Developed at SunPro, a Sun Microsystems, Inc. business.
10  * Permission to use, copy, modify, and distribute this
11  * software is freely granted, provided that this notice
12  * is preserved.
13  * ====================================================
14  */
15
16 #ifndef lint
17 static char rcsid[] = "$FreeBSD$";
18 #endif
19
20 #include "math.h"
21 #include "math_private.h"
22 static const float
23 one   =  1.0000000000e+00, /* 0x3f800000 */
24 pio4  =  7.8539812565e-01, /* 0x3f490fda */
25 pio4lo=  3.7748947079e-08, /* 0x33222168 */
26 T[] =  {
27   3.3333334327e-01, /* 0x3eaaaaab */
28   1.3333334029e-01, /* 0x3e088889 */
29   5.3968254477e-02, /* 0x3d5d0dd1 */
30   2.1869488060e-02, /* 0x3cb327a4 */
31   8.8632395491e-03, /* 0x3c11371f */
32   3.5920790397e-03, /* 0x3b6b6916 */
33   1.4562094584e-03, /* 0x3abede48 */
34   5.8804126456e-04, /* 0x3a1a26c8 */
35   2.4646313977e-04, /* 0x398137b9 */
36   7.8179444245e-05, /* 0x38a3f445 */
37   7.1407252108e-05, /* 0x3895c07a */
38  -1.8558637748e-05, /* 0xb79bae5f */
39   2.5907305826e-05, /* 0x37d95384 */
40 };
41
42 float
43 __kernel_tanf(float x, float y, int iy)
44 {
45         float z,r,v,w,s;
46         int32_t ix,hx;
47         GET_FLOAT_WORD(hx,x);
48         ix = hx&0x7fffffff;     /* high word of |x| */
49         if(ix<0x31800000)                       /* x < 2**-28 */
50             {if((int)x==0) {                    /* generate inexact */
51                 if((ix|(iy+1))==0) return one/fabsf(x);
52                 else return (iy==1)? x: -one/x;
53             }
54             }
55         if(ix>=0x3f2ca140) {                    /* |x|>=0.6744 */
56             if(hx<0) {x = -x; y = -y;}
57             z = pio4-x;
58             w = pio4lo-y;
59             x = z+w; y = 0.0;
60         }
61         z       =  x*x;
62         w       =  z*z;
63     /* Break x^5*(T[1]+x^2*T[2]+...) into
64      *    x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
65      *    x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
66      */
67         r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
68         v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
69         s = z*x;
70         r = y + z*(s*(r+v)+y);
71         r += T[0]*s;
72         w = x+r;
73         if(ix>=0x3f2ca140) {
74             v = (float)iy;
75             return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r)));
76         }
77         if(iy==1) return w;
78         else {          /* if allow error up to 2 ulp,
79                            simply return -1.0/(x+r) here */
80      /*  compute -1.0/(x+r) accurately */
81             float a,t;
82             int32_t i;
83             z  = w;
84             GET_FLOAT_WORD(i,z);
85             SET_FLOAT_WORD(z,i&0xfffff000);
86             v  = r-(z - x);     /* z+v = r+x */
87             t = a  = -(float)1.0/w;     /* a = -1.0/w */
88             GET_FLOAT_WORD(i,t);
89             SET_FLOAT_WORD(t,i&0xfffff000);
90             s  = (float)1.0+t*z;
91             return t+a*(s+t*v);
92         }
93 }