2 /* @(#)z_sine.c 1.0 98/08/13 */
3 /******************************************************************
4 * The following routines are coded directly from the algorithms
5 * and coefficients given in "Software Manual for the Elementary
6 * Functions" by William J. Cody, Jr. and William Waite, Prentice
8 ******************************************************************/
12 <<sin>>, <<cos>>, <<sine>>, <<sinf>>, <<cosf>>, <<sinef>>---sine or cosine
23 double sin(double <[x]>);
24 float sinf(float <[x]>);
25 double cos(double <[x]>);
26 float cosf(float <[x]>);
29 <<sin>> and <<cos>> compute (respectively) the sine and cosine
30 of the argument <[x]>. Angles are specified in radians.
32 The sine or cosine of <[x]> is returned.
35 <<sin>> and <<cos>> are ANSI C.
36 <<sinf>> and <<cosf>> are extensions.
43 /******************************************************************
47 * x - floating point value
48 * cosine - indicates cosine value
54 * This routine calculates sines and cosines.
56 *****************************************************************/
61 #ifndef _DOUBLE_IS_32BITS
63 static const double HALF_PI
= 1.57079632679489661923;
64 static const double ONE_OVER_PI
= 0.31830988618379067154;
65 static const double r
[] = { -0.16666666666666665052,
66 0.83333333333331650314e-02,
67 -0.19841269841201840457e-03,
68 0.27557319210152756119e-05,
69 -0.25052106798274584544e-07,
70 0.16058936490371589114e-09,
71 -0.76429178068910467734e-12,
72 0.27204790957888846175e-14 };
79 double y
, XN
, g
, R
, res
;
80 double YMAX
= 210828714.0;
92 /* Use sin and cos properties to ease computations. */
96 y
= fabs (x
) + HALF_PI
;
112 /* Check for values of y that will overflow here. */
119 /* Calculate the exponent. */
121 N
= (int) (y
* ONE_OVER_PI
- 0.5);
123 N
= (int) (y
* ONE_OVER_PI
+ 0.5);
132 y
= fabs (x
) - XN
* __PI
;
134 if (-z_rooteps
< y
&& y
< z_rooteps
)
141 /* Calculate the Taylor series. */
142 R
= (((((((r
[6] * g
+ r
[5]) * g
+ r
[4]) * g
+ r
[3]) * g
+ r
[2]) * g
+ r
[1]) * g
+ r
[0]) * g
);
144 /* Finally, compute the result. */
153 #endif /* _DOUBLE_IS_32BITS */