Subversion Repositories Kolibri OS

Rev

Rev 4872 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
 
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 */
12
13
 
14
 
15
16
 
17
        <>, <>---tangent
18
19
 
20
tan
21
INDEX
22
tanf
23
24
 
25
        #include 
26
        double tan(double <[x]>);
27
        float tanf(float <[x]>);
28
29
 
30
        #include 
31
        double tan(<[x]>)
32
        double <[x]>;
33
34
 
35
        float <[x]>;
36
37
 
38
 
39
<> computes the tangent of the argument <[x]>.
40
Angles are specified in radians.
41
42
 
43
44
 
45
The tangent of <[x]> is returned.
46
47
 
48
<> is ANSI. <> is an extension.
49
*/
50
51
 
52
 * Return tangent function of x.
53
 *
54
 * kernel function:
55
 *	__kernel_tan		... tangent function on [-pi/4,pi/4]
56
 *	__ieee754_rem_pio2	... argument reduction routine
57
 *
58
 * Method.
59
 *      Let S,C and T denote the sin, cos and tan respectively on
60
 *	[-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
61
 *	in [-pi/4 , +pi/4], and let n = k mod 4.
62
 *	We have
63
 *
64
 *          n        sin(x)      cos(x)        tan(x)
65
 *     ----------------------------------------------------------
66
 *	    0	       S	   C		 T
67
 *	    1	       C	  -S		-1/T
68
 *	    2	      -S	  -C		 T
69
 *	    3	      -C	   S		-1/T
70
 *     ----------------------------------------------------------
71
 *
72
 * Special cases:
73
 *      Let trig be any of sin, cos, or tan.
74
 *      trig(+-INF)  is NaN, with signals;
75
 *      trig(NaN)    is that NaN;
76
 *
77
 * Accuracy:
78
 *	TRIG(x) returns trig(x) nearly rounded
79
 */
80
81
 
82
83
 
84
85
 
86
	double tan(double x)
87
#else
88
	double tan(x)
89
	double x;
90
#endif
91
{
92
	double y[2],z=0.0;
93
	__int32_t n,ix;
94
95
 
96
	GET_HIGH_WORD(ix,x);
97
98
 
99
	ix &= 0x7fffffff;
100
	if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
101
102
 
103
	else if (ix>=0x7ff00000) return x-x;		/* NaN */
104
105
 
106
	else {
107
	    n = __ieee754_rem_pio2(x,y);
108
	    return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even
109
							-1 -- n odd */
110
	}
111
}
112
113
 
114