xref: /csrg-svn/lib/libm/common_source/sin.3 (revision 23564)
SIN 3M "8 May 1985"
C 4
NAME
sin, cos, tan, asin, acos, atan, atan2 - trigonometric functions
SYNOPSIS
 #include <math.h> 

double sin(x) double x;

double cos(x) double x;

double tan(x) double x;

double asin(x) double x;

double acos(x) double x;

double atan(x) double x;

double atan2(y, x) double y, x;

DESCRIPTION
Sin, cos and tan return trigonometric functions of radian arguments.

Asin returns the arc sin in the range -\(*p/2 to \(*p/2.

Acos returns the arc cosine in the range 0 to \(*p.

Atan returns the arc tangent of x in the range -\(*p/2 to \(*p/2.

Atan2 returns atan(y/x) if x > 0,

sign(y)*(\(*p - atan(|y/x|)) if x < 0,

zero if x = y = 0 and

sign(y)*\(*p/2 if x = 0 but y not equal to 0.

SEE ALSO
intro(3M), hypot(3M), sqrt(3M)
DIAGNOSTICS
Arguments of magnitude greater than 1 cause asin and acos to return the reserved operand on the VAX; errno is set to EDOM.
NOTES
Atan2 defines atan2(0,0) = 0 on the 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:
(1)
Any program that already tests whether y = x = 0 before computing atan2(y,x) will be indifferent to whether atan2(0,0) = 0 or not. Any program that expects atan2(0,0) to be invalid is dubious because the consequence of that invalidity will vary from one computer system to another.
(2)
The principal use for atan2 is conversion between rectangular (x, y) and polar (r, theta) \(*h) coordinates that must satisfy

x = r \(** cos theta \(*h and y = r \(** sin theta. \(*h. Then mapping (x = 0, y = 0) to (r = 0, theta \(*h = 0) without fuss saves a programmer from nuisance tests. In general, given x and y the conversion should be effected by computing

r = hypot(x,y) ... := sqrt(x**2+y**2) sqrt(x\u\s82\s10\d+y\u\s82\s10\d)

theta \(*h = atan2(y,x).

(3)
On a machine that conforms to IEEE 754, the foregoing conversion has to cope with signed zeroes and infinities. For that purpose the formula above is compatible with the following:

if x \(>= 0 then theta \(*h = 2\(**atan(y/(r+x)) else I theta \(*h = 2\(**atan((r-x)/y)

except if r = 0 then replace x by copysign(1,x) here, and if r is infinite take limits to get a multiple of pi/4 \(*p/4 for theta. \(*h.

AUTHOR
Robert P. Corbett, W. Kahan, Stuart McDonald, Kwok-Choi Ng