4.3BSD/usr/man/man3/sin.3m

.\" 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 3M  "May 12, 1986"
.UC 4
.de Pi		\" PI stuff sign
.if n \\
\\$2pi\\$1
.if t \\
\\$2\\(*p\\$1
..
.ds up \fIulp\fR
.SH NAME
sin, cos, tan, asin, acos, atan, atan2 \- trigonometric functions
and their inverses
.SH SYNOPSIS
.nf
.B #include <math.h>
.PP
.B double sin(x)
.B double x;
.PP
.B double cos(x)
.B double x;
.PP
.B double tan(x)
.B double x;
.PP
.B double asin(x)
.B double x;
.PP
.B double acos(x)
.B double x;
.PP
.B double atan(x)
.B double x;
.PP
.B double atan2(y,x)
.B double y,x;
.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
On a VAX,
.nf
.if n \{\
.ta \w'atan2(y,x) := 'u+2n +\w'sign(y)\(**(pi \- atan(|y/x|))'u+2n
atan2(y,x) := 	atan(y/x)	if x > 0,
	sign(y)\(**(pi \- atan(|y/x|))	if x < 0,
	0	if x = y = 0, or
	sign(y)\(**pi/2	if x = 0 != y.  \}
.if t \{\
.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
On a VAX, if |x| > 1 then asin(x) and acos(x)
will return reserved operands and \fIerrno\fR will be set to EDOM.
.SH NOTES
Atan2 defines atan2(0,0) = 0 on a VAX despite that previously
atan2(0,0) may have generated an error message.
The reasons for assigning a value to atan2(0,0) are these:
.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:
.nf
.ta 1iR +1n +\w' := hypot(x,y);'u+0.5i
.if n \{\
	r	:= hypot(x,y);	... := sqrt(x\(**x+y\(**y)
	theta	:= atan2(y,x).
.ta \}
.if t \{\
	r	:= hypot(x,y);	... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
	\(*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:
.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 t \
.ta \w'if x > 0'u+2n +\w'then'u+2n
.if n \
if x > 0	then theta := 2\(**atan(y/(r+x))
.if t \
if x > 0	then	\(*h := 2\(**atan(y/(r+x))
.if n \
	else theta := 2\(**atan((r\-x)/y);
.if t \
	else	\(*h := 2\(**atan((r\-x)/y);
.fi
.RE
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.)
Let P stand for the number stored in the computer in place of
.Pi " = 3.14159 26535 89793 23846 26433 ... ."
Let "trig" stand for one of "sin", "cos" or "tan".  Then
the expression "trig(x)" in a program actually produces an
approximation to
.Pi /P), trig(x\(**
and "atrig(x)" approximates
.Pi )\(**atrig(x). (P/
The approximations are close,  within 0.9 \*(ups for sin,
cos and atan, within 2.2 \*(ups for tan, asin,
acos and atan2 on a VAX.  Moreover,
.Pi \& "P = "
in the codes that run on a VAX.

In the codes that run on other machines, P differs from
.Pi
by a fraction of an \*(up; the difference matters only if the argument
x is huge, and even then the difference is likely to be swamped by
the uncertainty in x.  Besides, every trigonometric identity that
does not involve
.Pi
explicitly is satisfied equally well regardless of whether
.Pi . "P = "
For instance,
.if n \
sin(x)**2+cos(x)**2\0=\01
.if t \
sin\u\s62\s10\d(x)+cos\u\s62\s10\d(x)\0=\01
and sin(2x)\0=\02\|sin(x)cos(x) to within a few \*(ups no matter how big
x may be.  Therefore the difference between P and
.Pi
is most unlikely to affect scientific and engineering computations.
.SH SEE ALSO
math(3M), hypot(3M), sqrt(3M), infnan(3M)
.SH AUTHOR
Robert P. Corbett, W. Kahan, Stuart\0I.\0McDonald, Peter\0Tang and,
for the codes for IEEE 754, Dr. Kwok\-Choi\0Ng.