add Berkeley specific header
[unix-history] / usr / src / lib / libm / common_source / sin.3
CommitLineData
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
17sin, cos, tan, asin, acos, atan, atan2 \- trigonometric functions
cd30a7d2 18and 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
45Sin, cos and tan
46return trigonometric functions of radian arguments x.
f411aa3f 47.PP
cd30a7d2
MAN
48Asin returns the arc sine in the range
49.Pi /2 \-
50to
51.Pi /2.
f411aa3f 52.PP
cd30a7d2
MAN
53Acos returns the arc cosine in the range 0 to
54.Pi.
f411aa3f 55.PP
cd30a7d2
MAN
56Atan returns the arc tangent in the range
57.Pi /2 \-
58to
59.Pi /2.
f411aa3f 60.PP
cd30a7d2
MAN
61On a VAX,
62.nf
63.if n \{\
64.ta \w'atan2(y,x) := 'u+2n +\w'sign(y)\(**(pi \- atan(|y/x|))'u+2n
65atan2(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
71atan2(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
78On a VAX, if |x| > 1 then asin(x) and acos(x)
79will return reserved operands and \fIerrno\fR will be set to EDOM.
dfc67a7e 80.SH NOTES
cd30a7d2
MAN
81Atan2 defines atan2(0,0) = 0 on a VAX despite that previously
82atan2(0,0) may have generated an error message.
83The reasons for assigning a value to atan2(0,0) are these:
84.IP (1) \w'\0\0\0\0'u
85Programs that test arguments to avoid computing
86atan2(0,0) must be indifferent to its value.
87Programs that require it to be invalid are vulnerable
88to diverse reactions to that invalidity on diverse computer systems.
89.IP (2) \w'\0\0\0\0'u
90Atan2 is used mostly to convert from rectangular (x,y)
91to polar
dfc67a7e 92.if n\
cd30a7d2 93(r,theta)
dfc67a7e 94.if t\
cd30a7d2
MAN
95(r,\(*h)
96coordinates that must satisfy x =
dfc67a7e 97.if n\
cd30a7d2 98r\(**cos theta
dfc67a7e 99.if t\
cd30a7d2
MAN
100r\(**cos\(*h
101and y =
dfc67a7e 102.if n\
cd30a7d2 103r\(**sin theta.
dfc67a7e 104.if t\
cd30a7d2
MAN
105r\(**sin\(*h.
106These equations are satisfied when (x=0,y=0)
107is mapped to
108.if n \
109(r=0,theta=0)
110.if t \
111(r=0,\(*h=0)
112on a VAX. In general, conversions to polar coordinates
113should 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
126The foregoing formulas need not be altered to cope in a
127reasonable way with signed zeros and infinities
128on a machine that conforms to IEEE 754;
129the versions of hypot and atan2 provided for
130such a machine are designed to handle all cases.
131That is why atan2(\(+-0,\-0) =
132.Pi , \(+-
133for instance.
134In general the formulas above are equivalent to these:
dfc67a7e 135.RS
cd30a7d2
MAN
136.nf
137.if n \
138r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
139.if t \
140r := \(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 \
147if x > 0 then theta := 2\(**atan(y/(r+x))
148.if t \
149if 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
156except if r is infinite then atan2 will yield an
157appropriate multiple of
158.Pi /4
159that would otherwise have to be obtained by taking limits.
160.SH ERROR (due to Roundoff etc.)
161Let P stand for the number stored in the computer in place of
162.Pi " = 3.14159 26535 89793 23846 26433 ... ."
163Let "trig" stand for one of "sin", "cos" or "tan". Then
164the expression "trig(x)" in a program actually produces an
165approximation to
166.Pi /P), trig(x\(**
167and "atrig(x)" approximates
168.Pi )\(**atrig(x). (P/
169The approximations are close, within 0.9 \*(ups for sin,
170cos and atan, within 2.2 \*(ups for tan, asin,
171acos and atan2 on a VAX. Moreover,
172.Pi \& "P = "
173in the codes that run on a VAX.
174
175In the codes that run on other machines, P differs from
176.Pi
177by a fraction of an \*(up; the difference matters only if the argument
178x is huge, and even then the difference is likely to be swamped by
179the uncertainty in x. Besides, every trigonometric identity that
180does not involve
181.Pi
182explicitly is satisfied equally well regardless of whether
183.Pi . "P = "
184For instance,
185.if n \
186sin(x)**2+cos(x)**2\0=\01
187.if t \
188sin\u\s62\s10\d(x)+cos\u\s62\s10\d(x)\0=\01
189and sin(2x)\0=\02\|sin(x)cos(x) to within a few \*(ups no matter how big
f9628029
KM
190x may be. Therefore the difference between P and
191.Pi
192is most unlikely to affect scientific and engineering computations.
8220ec5a
MK
193.SH SEE ALSO
194math(3M), hypot(3M), sqrt(3M), infnan(3M)
6a716ef9 195.SH AUTHOR
f9628029
KM
196Robert P. Corbett, W. Kahan, Stuart\0I.\0McDonald, Peter\0Tang and,
197for the codes for IEEE 754, Dr. Kwok\-Choi\0Ng.