Subversion Repositories Kolibri OS

Rev

Rev 4872 | Details | Compare with Previous | 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
FUNCTION
15
        <>, <>, <>, <>---sine or cosine
16
INDEX
17
sin
18
INDEX
19
sinf
20
INDEX
21
cos
22
INDEX
23
cosf
24
ANSI_SYNOPSIS
25
        #include 
26
        double sin(double <[x]>);
27
        float  sinf(float <[x]>);
28
        double cos(double <[x]>);
29
        float cosf(float <[x]>);
30
31
 
32
        #include 
33
        double sin(<[x]>)
34
        double <[x]>;
35
        float  sinf(<[x]>)
36
        float <[x]>;
37
38
 
39
        double <[x]>;
40
        float cosf(<[x]>)
41
        float <[x]>;
42
43
 
44
	<> and <> compute (respectively) the sine and cosine
45
	of the argument <[x]>.  Angles are specified in radians.
46
47
 
48
	return <> values.
49
50
 
51
 
52
	The sine or cosine of <[x]> is returned.
53
54
 
55
	<> and <> are ANSI C.
56
	<> and <> are extensions.
57
58
 
59
	sin ansi pure
60
	sinf - pure
61
*/
62
63
 
64
 * Return sine function of x.
65
 *
66
 * kernel function:
67
 *	__kernel_sin		... sine function on [-pi/4,pi/4]
68
 *	__kernel_cos		... cose function on [-pi/4,pi/4]
69
 *	__ieee754_rem_pio2	... argument reduction routine
70
 *
71
 * Method.
72
 *      Let S,C and T denote the sin, cos and tan respectively on
73
 *	[-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
74
 *	in [-pi/4 , +pi/4], and let n = k mod 4.
75
 *	We have
76
 *
77
 *          n        sin(x)      cos(x)        tan(x)
78
 *     ----------------------------------------------------------
79
 *	    0	       S	   C		 T
80
 *	    1	       C	  -S		-1/T
81
 *	    2	      -S	  -C		 T
82
 *	    3	      -C	   S		-1/T
83
 *     ----------------------------------------------------------
84
 *
85
 * Special cases:
86
 *      Let trig be any of sin, cos, or tan.
87
 *      trig(+-INF)  is NaN, with signals;
88
 *      trig(NaN)    is that NaN;
89
 *
90
 * Accuracy:
91
 *	TRIG(x) returns trig(x) nearly rounded
92
 */
93
94
 
95
96
 
97
98
 
99
	double sin(double x)
100
#else
101
	double sin(x)
102
	double x;
103
#endif
104
{
105
	double y[2],z=0.0;
106
	__int32_t n,ix;
107
108
 
109
	GET_HIGH_WORD(ix,x);
110
111
 
112
	ix &= 0x7fffffff;
113
	if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
114
115
 
116
	else if (ix>=0x7ff00000) return x-x;
117
118
 
119
	else {
120
	    n = __ieee754_rem_pio2(x,y);
121
	    switch(n&3) {
122
		case 0: return  __kernel_sin(y[0],y[1],1);
123
		case 1: return  __kernel_cos(y[0],y[1]);
124
		case 2: return -__kernel_sin(y[0],y[1],1);
125
		default:
126
			return -__kernel_cos(y[0],y[1]);
127
	    }
128
	}
129
}
130
131
 
132