.TH SIN 3M "6 August 1985"
sin, cos, tan, asin, acos, atan, atan2 \- trigonometric functions
return trigonometric functions of radian arguments x.
Asin returns the arc sine in the range
Acos returns the arc cosine in the range 0 to
Atan returns the arc tangent in the range
.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,
sign(y)\(**pi/2 if x = 0 != y. \}
.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,
sign(y)\(**\(*p/2 if x = 0 \(!= y. \}
intro(3M), hypot(3M), sqrt(3M), infnan(3M)
On a VAX, if |x| > 1 then asin(x) and acos(x)
will return reserved operands and \fIerrno\fR will be set to EDOM.
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:
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.
Atan2 is used mostly to convert from rectangular (x,y)
coordinates that must satisfy x =
These equations are satisfied when (x=0,y=0)
on a VAX. In general, conversions to polar coordinates
.ta 1iR +1n +\w' := hypot(x,y);'u+0.5i
r := hypot(x,y); ... := sqrt(x\(**x+y\(**y)
r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
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) =
In general the formulas above are equivalent to these:
r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
.ta \w'if x > 0'u+2n +\w'then'u+2n
if x > 0 then theta := 2\(**atan(y/(r+x))
if x > 0 then \(*h := 2\(**atan(y/(r+x))
else theta := 2\(**atan((r\-x)/y);
else \(*h := 2\(**atan((r\-x)/y);
except if r is infinite then atan2 will yield an
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
and "atrig(x)" approximates
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,
in the codes that run on a VAX.
In the codes that run on other machines, P differs from
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
explicitly is satisfied equally well regardless of whether
sin(x)**2+cos(x)**2\0=\01
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 scientific and engineering calculations
are most unlikely to be affected by the difference between P and
Robert P. Corbett, W. Kahan, Stuart I. McDonald, Kwok\-Choi\0Ng