• API
• FAQ
• Tools
• Archive
daily pastebin goal
42%
SHARE
TWEET

# Untitled

a guest Jan 17th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. double
2. _DEFUN (sine, (double, int),
3.         double x _AND
4.         int cosine)
5. {
6.   int sgn, N;
7.   double y, XN, g, R, res;
8.   double YMAX = 210828714.0;
9.
10.   switch (numtest (x))
11.     {
12.       case NAN:
13.         errno = EDOM;
14.         return (x);
15.       case INF:
16.         errno = EDOM;
17.         return (z_notanum.d);
18.     }
19.
20.   /* Use sin and cos properties to ease computations. */
21.   if (cosine)
22.     {
23.       sgn = 1;
24.       y = fabs (x) + HALF_PI;
25.     }
26.   else
27.     {
28.       if (x < 0.0)
29.         {
30.           sgn = -1;
31.           y = -x;
32.         }
33.       else
34.         {
35.           sgn = 1;
36.           y = x;
37.         }
38.     }
39.
40.   /* Check for values of y that will overflow here. */
41.   if (y > YMAX)
42.     {
43.       errno = ERANGE;
44.       return (x);
45.     }
46.
47.   /* Calculate the exponent. */
48.   if (y < 0.0)
49.     N = (int) (y * ONE_OVER_PI - 0.5);
50.   else
51.     N = (int) (y * ONE_OVER_PI + 0.5);
52.   XN = (double) N;
53.
54.   if (N & 1)
55.     sgn = -sgn;
56.
57.   if (cosine)
58.     XN -= 0.5;
59.
60.   y = fabs (x) - XN * __PI;
61.
62.   if (-z_rooteps < y && y < z_rooteps)
63.     res = y;
64.
65.   else
66.     {
67.       g = y * y;
68.
69.       /* Calculate the Taylor series. */
70.       R = (((((((r[6] * g + r[5]) * g + r[4]) * g + r[3]) * g + r[2]) * g + r[1]) * g + r[0]) * g);
71.
72.       /* Finally, compute the result. */
73.       res = y + y * R;
74.     }
75.
76.   res *= sgn;
77.
78.   return (res);
79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top