.\" Copyright (c) 1985 Regents of the University of California. .\" All rights reserved. The Berkeley software License Agreement .\" specifies the terms and conditions for redistribution. .\" .\" @(#)sin.3m 6.6 (Berkeley) 5/12/86 .\" .TH SIN 3 "May 12, 1986" .UC 4 .de Pi \" PI stuff sign .if n \\$2pi\\$1 .if t \\$2\\(*p\\$1 .. .if n .ds != != .if t .ds != \(!= .ds up \fIulp\fR .SH NAME sin, cos, tan, asin, acos, atan, atan2 \- trigonometric functions and their inverses .SH SYNOPSIS .nf .ft B #include double sin(double \fIx\fP) double cos(double \fIx\fP) double tan(double \fIx\fP) double asin(double \fIx\fP) double acos(double \fIx\fP) double atan(double \fIx\fP) double atan2(double \fIy\fP, double \fIx\fP) .ft R .fi .SH DESCRIPTION Sin, cos and tan return trigonometric functions of radian arguments x. .PP Asin returns the arc sine in the range .Pi /2 \- to .Pi /2. .PP Acos returns the arc cosine in the range 0 to .Pi. .PP Atan returns the arc tangent in the range .Pi /2 \- to .Pi /2. .PP .nf .ta \w'atan2(y, x) := 'u+2n +\w'sign(y)\(**(\(*p \- atan(|y/x|))'u+2n atan2(y, x) := atan(y/x) if x > 0, sign(y)\(**(\(*p \- atan(|y/x|)) if x < 0, 0 if x = y = 0, or sign(y)\(**\(*p/2 if x = 0 \*(!= y. .ta .fi .SH DIAGNOSTICS sin(\(+-Inf) = cos(\(+-Inf) = tan(\(+-Inf) = NaN with signal. .br sin(NaN) = cos(NaN) = tan(NaN) = that NaN. .PP asin(NaN) = acos(NaN) = NaN. .br asin(x) = acos(x) = NaN with invalid signal if |x| > 1. .PP atan2([anything], NaN) = NaN; .br atan2(NaN , [anything]) = NaN; .br atan2(\(+-0, +[anything but NaN]) = \(+-0 ; .br atan2(\(+-0, \-[anything but NaN]) = \(+-\(*p ; .br atan2(\(+-[anything but 0 and NaN], 0) = \(+-\(*p/2; .br atan2(\(+-[anything but Inf and NaN], +Inf) = \(+-0 ; .br atan2(\(+-[anything but Inf and NaN], \-Inf) = \(+-\(*p; .br atan2(\(+-Inf, +Inf) = \(+-\(*p/4 ; .br atan2(\(+-Inf, \-Inf) = \(+-3\(*p/4; .br atan2(\(+-Inf, [anything but, 0, NaN, and Inf]) = \(+-\(*p/2; .SH NOTES Atan2 defines atan2(0, 0) = 0 for the following reasons: .IP (1) \w'\0\0\0\0'u Programs that test arguments to avoid computing atan2(0, 0) must be indifferent to its value. Programs that require it to be invalid are vulnerable to diverse reactions to that invalidity on diverse computer systems. .IP (2) \w'\0\0\0\0'u Atan2 is used mostly to convert from rectangular (x, y) to polar .if n (r, theta) .if t (r, \(*h) coordinates that must satisfy x = .if n r\(**cos theta .if t r\(**cos\(*h and y = .if n r\(**sin theta. .if t r\(**sin\(*h. These equations are satisfied when (x=0, y=0) is mapped to .if n (r=0, theta=0) .if t (r=0, \(*h=0) on a VAX. In general, conversions to polar coordinates should be computed thus: .sp 0.4 .nf .if n .ta 4n +1n +\w' := hypot(x, y);'u+0.5i .if n \& \& r := hypot(x, y); ... := sqrt(x\(**x+y\(**y) .if n \& theta := atan2(y, x). .if t .ta 1iR +1n +\w' := hypot(x, y);'u+0.5i .if t \& r := hypot(x, y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d) .if t \& \(*h := atan2(y, x). .ta .fi .IP (3) \w'\0\0\0\0'u The foregoing formulas need not be altered to cope in a reasonable way with signed zeros and infinities on a machine that conforms to IEEE 754; the versions of hypot and atan2 provided for such a machine are designed to handle all cases. That is why atan2(\(+-0, \-0) = .Pi , \(+- for instance. In general the formulas above are equivalent to these: .sp 0.4 .RS .nf .if n r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1, x); .if t r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1, x); .br .if n .ta 1i .if n if x > 0 then theta := 2\(**atan(y/(r+x)) .if n \& else theta := 2\(**atan((r\-x)/y); .if t .ta \w'if x > 0'u+2n +\w'then'u+2n .if t if x > 0 then \(*h := 2\(**atan(y/(r+x)) .if t \& else \(*h := 2\(**atan((r\-x)/y); .fi .RE .sp 0.4 except if r is infinite then atan2 will yield an appropriate multiple of .Pi /4 that would otherwise have to be obtained by taking limits. .SH "ERROR (due to Roundoff etc.)" Sin, cos, and tan return the nearly rounded result of the true mathematical function, so they approximate within 1 \*(up. .SH SEE ALSO .BR math (3), .BR hypot (3), .BR sqrt (3). .SH AUTHOR Robert P. Corbett, W. Kahan, Stuart\0I.\0McDonald, Peter\0Tang and, for the codes for IEEE 754, Dr. Kwok\-Choi\0Ng.