Commit | Line | Data |
---|---|---|
f9628029 KM |
1 | .\" Copyright (c) 1985 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
8220ec5a | 5 | .\" @(#)sin.3 6.6 (Berkeley) %G% |
f9628029 KM |
6 | .\" |
7 | .TH SIN 3M "" | |
6a716ef9 | 8 | .UC 4 |
cd30a7d2 MAN |
9 | .de Pi \" PI stuff sign |
10 | .if n \\ | |
11 | \\$2pi\\$1 | |
12 | .if t \\ | |
13 | \\$2\\(*p\\$1 | |
14 | .. | |
15 | .ds up \fIulp\fR | |
f411aa3f KM |
16 | .SH NAME |
17 | sin, cos, tan, asin, acos, atan, atan2 \- trigonometric functions | |
cd30a7d2 | 18 | and their inverses |
f411aa3f KM |
19 | .SH SYNOPSIS |
20 | .nf | |
21 | .B #include <math.h> | |
22 | .PP | |
23 | .B double sin(x) | |
24 | .B double x; | |
25 | .PP | |
26 | .B double cos(x) | |
27 | .B double x; | |
28 | .PP | |
6a716ef9 MAN |
29 | .B double tan(x) |
30 | .B double x; | |
31 | .PP | |
f411aa3f KM |
32 | .B double asin(x) |
33 | .B double x; | |
34 | .PP | |
35 | .B double acos(x) | |
36 | .B double x; | |
37 | .PP | |
38 | .B double atan(x) | |
39 | .B double x; | |
40 | .PP | |
cd30a7d2 MAN |
41 | .B double atan2(y,x) |
42 | .B double y,x; | |
f411aa3f KM |
43 | .fi |
44 | .SH DESCRIPTION | |
cd30a7d2 MAN |
45 | Sin, cos and tan |
46 | return trigonometric functions of radian arguments x. | |
f411aa3f | 47 | .PP |
cd30a7d2 MAN |
48 | Asin returns the arc sine in the range |
49 | .Pi /2 \- | |
50 | to | |
51 | .Pi /2. | |
f411aa3f | 52 | .PP |
cd30a7d2 MAN |
53 | Acos returns the arc cosine in the range 0 to |
54 | .Pi. | |
f411aa3f | 55 | .PP |
cd30a7d2 MAN |
56 | Atan returns the arc tangent in the range |
57 | .Pi /2 \- | |
58 | to | |
59 | .Pi /2. | |
f411aa3f | 60 | .PP |
cd30a7d2 MAN |
61 | On a VAX, |
62 | .nf | |
63 | .if n \{\ | |
64 | .ta \w'atan2(y,x) := 'u+2n +\w'sign(y)\(**(pi \- atan(|y/x|))'u+2n | |
65 | atan2(y,x) := atan(y/x) if x > 0, | |
66 | sign(y)\(**(pi \- atan(|y/x|)) if x < 0, | |
67 | 0 if x = y = 0, or | |
68 | sign(y)\(**pi/2 if x = 0 != y. \} | |
69 | .if t \{\ | |
70 | .ta \w'atan2(y,x) := 'u+2n +\w'sign(y)\(**(\(*p \- atan(|y/x|))'u+2n | |
71 | atan2(y,x) := atan(y/x) if x > 0, | |
72 | sign(y)\(**(\(*p \- atan(|y/x|)) if x < 0, | |
73 | 0 if x = y = 0, or | |
74 | sign(y)\(**\(*p/2 if x = 0 \(!= y. \} | |
75 | .ta | |
76 | .fi | |
f411aa3f | 77 | .SH DIAGNOSTICS |
cd30a7d2 MAN |
78 | On a VAX, if |x| > 1 then asin(x) and acos(x) |
79 | will return reserved operands and \fIerrno\fR will be set to EDOM. | |
dfc67a7e | 80 | .SH NOTES |
cd30a7d2 MAN |
81 | Atan2 defines atan2(0,0) = 0 on a VAX despite that previously |
82 | atan2(0,0) may have generated an error message. | |
83 | The reasons for assigning a value to atan2(0,0) are these: | |
84 | .IP (1) \w'\0\0\0\0'u | |
85 | Programs that test arguments to avoid computing | |
86 | atan2(0,0) must be indifferent to its value. | |
87 | Programs that require it to be invalid are vulnerable | |
88 | to diverse reactions to that invalidity on diverse computer systems. | |
89 | .IP (2) \w'\0\0\0\0'u | |
90 | Atan2 is used mostly to convert from rectangular (x,y) | |
91 | to polar | |
dfc67a7e | 92 | .if n\ |
cd30a7d2 | 93 | (r,theta) |
dfc67a7e | 94 | .if t\ |
cd30a7d2 MAN |
95 | (r,\(*h) |
96 | coordinates that must satisfy x = | |
dfc67a7e | 97 | .if n\ |
cd30a7d2 | 98 | r\(**cos theta |
dfc67a7e | 99 | .if t\ |
cd30a7d2 MAN |
100 | r\(**cos\(*h |
101 | and y = | |
dfc67a7e | 102 | .if n\ |
cd30a7d2 | 103 | r\(**sin theta. |
dfc67a7e | 104 | .if t\ |
cd30a7d2 MAN |
105 | r\(**sin\(*h. |
106 | These equations are satisfied when (x=0,y=0) | |
107 | is mapped to | |
108 | .if n \ | |
109 | (r=0,theta=0) | |
110 | .if t \ | |
111 | (r=0,\(*h=0) | |
112 | on a VAX. In general, conversions to polar coordinates | |
113 | should be computed thus: | |
114 | .nf | |
115 | .ta 1iR +1n +\w' := hypot(x,y);'u+0.5i | |
116 | .if n \{\ | |
117 | r := hypot(x,y); ... := sqrt(x\(**x+y\(**y) | |
118 | theta := atan2(y,x). | |
119 | .ta \} | |
120 | .if t \{\ | |
121 | r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d) | |
122 | \(*h := atan2(y,x). | |
123 | .ta \} | |
124 | .fi | |
125 | .IP (3) \w'\0\0\0\0'u | |
126 | The foregoing formulas need not be altered to cope in a | |
127 | reasonable way with signed zeros and infinities | |
128 | on a machine that conforms to IEEE 754; | |
129 | the versions of hypot and atan2 provided for | |
130 | such a machine are designed to handle all cases. | |
131 | That is why atan2(\(+-0,\-0) = | |
132 | .Pi , \(+- | |
133 | for instance. | |
134 | In general the formulas above are equivalent to these: | |
dfc67a7e | 135 | .RS |
cd30a7d2 MAN |
136 | .nf |
137 | .if n \ | |
138 | r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x); | |
139 | .if t \ | |
140 | r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x); | |
dfc67a7e | 141 | .br |
cd30a7d2 MAN |
142 | .if n \ |
143 | .ta 1i | |
144 | .if t \ | |
145 | .ta \w'if x > 0'u+2n +\w'then'u+2n | |
146 | .if n \ | |
147 | if x > 0 then theta := 2\(**atan(y/(r+x)) | |
148 | .if t \ | |
149 | if x > 0 then \(*h := 2\(**atan(y/(r+x)) | |
150 | .if n \ | |
151 | else theta := 2\(**atan((r\-x)/y); | |
152 | .if t \ | |
153 | else \(*h := 2\(**atan((r\-x)/y); | |
154 | .fi | |
dfc67a7e | 155 | .RE |
cd30a7d2 MAN |
156 | except if r is infinite then atan2 will yield an |
157 | appropriate multiple of | |
158 | .Pi /4 | |
159 | that would otherwise have to be obtained by taking limits. | |
160 | .SH ERROR (due to Roundoff etc.) | |
161 | Let P stand for the number stored in the computer in place of | |
162 | .Pi " = 3.14159 26535 89793 23846 26433 ... ." | |
163 | Let "trig" stand for one of "sin", "cos" or "tan". Then | |
164 | the expression "trig(x)" in a program actually produces an | |
165 | approximation to | |
166 | .Pi /P), trig(x\(** | |
167 | and "atrig(x)" approximates | |
168 | .Pi )\(**atrig(x). (P/ | |
169 | The approximations are close, within 0.9 \*(ups for sin, | |
170 | cos and atan, within 2.2 \*(ups for tan, asin, | |
171 | acos and atan2 on a VAX. Moreover, | |
172 | .Pi \& "P = " | |
173 | in the codes that run on a VAX. | |
174 | ||
175 | In the codes that run on other machines, P differs from | |
176 | .Pi | |
177 | by a fraction of an \*(up; the difference matters only if the argument | |
178 | x is huge, and even then the difference is likely to be swamped by | |
179 | the uncertainty in x. Besides, every trigonometric identity that | |
180 | does not involve | |
181 | .Pi | |
182 | explicitly is satisfied equally well regardless of whether | |
183 | .Pi . "P = " | |
184 | For instance, | |
185 | .if n \ | |
186 | sin(x)**2+cos(x)**2\0=\01 | |
187 | .if t \ | |
188 | sin\u\s62\s10\d(x)+cos\u\s62\s10\d(x)\0=\01 | |
189 | and sin(2x)\0=\02\|sin(x)cos(x) to within a few \*(ups no matter how big | |
f9628029 KM |
190 | x may be. Therefore the difference between P and |
191 | .Pi | |
192 | is most unlikely to affect scientific and engineering computations. | |
8220ec5a MK |
193 | .SH SEE ALSO |
194 | math(3M), hypot(3M), sqrt(3M), infnan(3M) | |
6a716ef9 | 195 | .SH AUTHOR |
f9628029 KM |
196 | Robert P. Corbett, W. Kahan, Stuart\0I.\0McDonald, Peter\0Tang and, |
197 | for the codes for IEEE 754, Dr. Kwok\-Choi\0Ng. |