1SIN(3M) SIN(3M)
2
3
4
6 sin, cos, tan, asin, acos, atan, atan2 - trigonometric functions and
7 their inverses
8
10 #include <math.h>
11
12 double sin(x)
13 double x;
14
15 double cos(x)
16 double x;
17
18 double tan(x)
19 double x;
20
21 double asin(x)
22 double x;
23
24 double acos(x)
25 double x;
26
27 double atan(x)
28 double x;
29
30 double atan2(y,x)
31 double y,x;
32
34 Sin, cos and tan return trigonometric functions of radian arguments x.
35
36 Asin returns the arc sine in the range -pi/2 to pi/2.
37
38 Acos returns the arc cosine in the range 0 to
39
40 Atan returns the arc tangent in the range -pi/2 to pi/2.
41
42 On a VAX,
43 atan2(y,x) := atan(y/x) if x > 0,
44 sign(y)∗(pi - atan(|y/x|)) if x < 0,
45 0 if x = y = 0, or
46 sign(y)∗pi/2 if x = 0 != y.
47
49 On a VAX, if |x| > 1 then asin(x) and acos(x) will return reserved op‐
50 erands and errno will be set to EDOM.
51
53 Atan2 defines atan2(0,0) = 0 on a VAX despite that previously
54 atan2(0,0) may have generated an error message. The reasons for
55 assigning a value to atan2(0,0) are these:
56
57 (1) Programs that test arguments to avoid computing atan2(0,0) must be
58 indifferent to its value. Programs that require it to be invalid
59 are vulnerable to diverse reactions to that invalidity on diverse
60 computer systems.
61
62 (2) Atan2 is used mostly to convert from rectangular (x,y) to polar
63 (r,theta) coordinates that must satisfy x = r∗cos theta and y =
64 r∗sin theta. These equations are satisfied when (x=0,y=0) is
65 mapped to (r=0,theta=0) on a VAX. In general, conversions to polar
66 coordinates should be computed thus:
67 r := hypot(x,y); ... := sqrt(x∗x+y∗y)
68 theta := atan2(y,x).
69
70 (3) The foregoing formulas need not be altered to cope in a reasonable
71 way with signed zeros and infinities on a machine that conforms to
72 IEEE 754; the versions of hypot and atan2 provided for such a
73 machine are designed to handle all cases. That is why atan2(±0,-0)
74 = ±pi, for instance. In general the formulas above are equivalent
75 to these:
76 r := sqrt(x∗x+y∗y); if r = 0 then x := copysign(1,x);
77 if x > 0 then theta := 2∗atan(y/(r+x))
78 else theta := 2∗atan((r-x)/y);
79 except if r is infinite then atan2 will yield an appropriate multiple
80 of pi/4 that would otherwise have to be obtained by taking limits.
81
83 Let P stand for the number stored in the computer in place of pi =
84 3.14159 26535 89793 23846 26433 ... . Let "trig" stand for one of
85 "sin", "cos" or "tan". Then the expression "trig(x)" in a program
86 actually produces an approximation to trig(x∗pi/P), and "atrig(x)"
87 approximates (P/pi)∗atrig(x). The approximations are close, within
88 0.9 ulps for sin, cos and atan, within 2.2 ulps for tan, asin, acos and
89 atan2 on a VAX. Moreover, P = pi in the codes that run on a VAX.
90
91 In the codes that run on other machines, P differs from pi by a frac‐
92 tion of an ulp; the difference matters only if the argument x is huge,
93 and even then the difference is likely to be swamped by the uncertainty
94 in x. Besides, every trigonometric identity that does not involve pi
95 explicitly is satisfied equally well regardless of whether P = pi. For
96 instance, sin(x)**2+cos(x)**2 = 1 and sin(2x) = 2sin(x)cos(x) to within
97 a few ulps no matter how big x may be. Therefore the difference
98 between P and pi is most unlikely to affect scientific and engineering
99 computations.
100
102 math(3M), hypot(3M), sqrt(3M), infnan(3M)
103
105 Robert P. Corbett, W. Kahan, Stuart I. McDonald, Peter Tang and, for
106 the codes for IEEE 754, Dr. Kwok-Choi Ng.
107
108
109
1104th Berkeley Distribution May 12, 1986 SIN(3M)