Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double
- _DEFUN (sine, (double, int),
- double x _AND
- int cosine)
- {
- int sgn, N;
- double y, XN, g, R, res;
- double YMAX = 210828714.0;
- switch (numtest (x))
- {
- case NAN:
- errno = EDOM;
- return (x);
- case INF:
- errno = EDOM;
- return (z_notanum.d);
- }
- /* Use sin and cos properties to ease computations. */
- if (cosine)
- {
- sgn = 1;
- y = fabs (x) + HALF_PI;
- }
- else
- {
- if (x < 0.0)
- {
- sgn = -1;
- y = -x;
- }
- else
- {
- sgn = 1;
- y = x;
- }
- }
- /* Check for values of y that will overflow here. */
- if (y > YMAX)
- {
- errno = ERANGE;
- return (x);
- }
- /* Calculate the exponent. */
- if (y < 0.0)
- N = (int) (y * ONE_OVER_PI - 0.5);
- else
- N = (int) (y * ONE_OVER_PI + 0.5);
- XN = (double) N;
- if (N & 1)
- sgn = -sgn;
- if (cosine)
- XN -= 0.5;
- y = fabs (x) - XN * __PI;
- if (-z_rooteps < y && y < z_rooteps)
- res = y;
- else
- {
- g = y * y;
- /* Calculate the Taylor series. */
- R = (((((((r[6] * g + r[5]) * g + r[4]) * g + r[3]) * g + r[2]) * g + r[1]) * g + r[0]) * g);
- /* Finally, compute the result. */
- res = y + y * R;
- }
- res *= sgn;
- return (res);
- }
Add Comment
Please, Sign In to add comment