xref: /csrg-svn/lib/libm/common_source/atan2.3 (revision 61283)
1*61283Sbostic.\" Copyright (c) 1991, 1993
2*61283Sbostic.\"	The Regents of the University of California.  All rights reserved.
348919Scael.\"
448919Scael.\" %sccs.include.redist.man%
548919Scael.\"
6*61283Sbostic.\"     @(#)atan2.3	8.1 (Berkeley) 06/04/93
748919Scael.\"
848919Scael.Dd
948919Scael.Dt ATAN2 3
1048919Scael.Os
1148919Scael.Sh NAME
1248919Scael.Nm atan2
1348919Scael.Nd arc tangent function of two variables
1448919Scael.Sh SYNOPSIS
1548919Scael.Fd #include <math.h>
1648919Scael.Ft double
1748919Scael.Fn atan2 "double y" "double x"
1848919Scael.Sh DESCRIPTION
1948919ScaelThe
2048919Scael.Xr atan2
2148919Scaelfunction computes the principal value of the arc tangent of
2248919Scael.Ar y/ Ns Ar x ,
2348919Scaelusing the signs of both arguments to determine the quadrant of
2448919Scaelthe return value.
2548919Scael.Sh RETURN VALUES
2648919ScaelThe
2748919Scael.Xr atan2
2848919Scaelfunction, if successful,
2948919Scaelreturns the arc tangent of
3048919Scael.Ar y/ Ns Ar x
3148919Scaelin the range
3248919Scael.Bk -words
3348919Scael.Bq \&- Ns \*(Pi , \&+ Ns \*(Pi
3448919Scael.Ek
3548919Scaelradians.
3648919ScaelIf both
3748919Scael.Ar x
3848919Scaeland
3948919Scael.Ar y
4048919Scaelare zero, the global variable
4148919Scael.Va errno
4248919Scaelis set to
4348919Scael.Er EDOM .
4448919ScaelOn the
4548919Scael.Tn VAX :
4648919Scael.Bl -column atan_(y,x)_:=____  sign(y)_(Pi_atan2(Xy_xX))___
4748919Scael.It Fn atan2 y x No := Ta
4848919Scael.Fn atan y/x Ta
4948919Scaelif
5048919Scael.Ar x
5148919Scael> 0,
5248919Scael.It Ta sign( Ns Ar y Ns )*(\*(Pi -
5348919Scael.Fn atan "\\*(Bay/x\\*(Ba" ) Ta
5448919Scaelif
5548919Scael.Ar x
5648919Scael< 0,
5748919Scael.It Ta
5848919Scael.No 0 Ta
5948919Scaelif x = y = 0, or
6048919Scael.It Ta
6148919Scael.Pf sign( Ar y Ns )*\\*(Pi/2 Ta
6248919Scaelif
6348919Scael.Ar x
6448919Scael= 0 \*(!=
6548919Scael.Ar y .
6648919Scael.El
6748919Scael.Sh NOTES
6848919ScaelThe function
6948919Scael.Fn atan2
7048919Scaeldefines "if x > 0,"
7148919Scael.Fn atan2 0 0
7248919Scael= 0 on a
7348919Scael.Tn VAX
7448919Scaeldespite that previously
7548919Scael.Fn atan2 0 0
7648919Scaelmay have generated an error message.
7748919ScaelThe reasons for assigning a value to
7848919Scael.Fn atan2 0 0
7948919Scaelare these:
8048919Scael.Bl -enum -offset indent
8148919Scael.It
8248919ScaelPrograms that test arguments to avoid computing
8348919Scael.Fn atan2 0 0
8448919Scaelmust be indifferent to its value.
8548919ScaelPrograms that require it to be invalid are vulnerable
8648919Scaelto diverse reactions to that invalidity on diverse computer systems.
8748919Scael.It
8848919ScaelThe
8948919Scael.Fn atan2
9048919Scaelfunction is used mostly to convert from rectangular (x,y)
9148919Scaelto polar
9248919Scael.if n\
9348919Scael(r,theta)
9448919Scael.if t\
9548919Scael(r,\(*h)
9648919Scaelcoordinates that must satisfy x =
9748919Scael.if n\
9848919Scaelr\(**cos theta
9948919Scael.if t\
10048919Scaelr\(**cos\(*h
10148919Scaeland y =
10248919Scael.if n\
10348919Scaelr\(**sin theta.
10448919Scael.if t\
10548919Scaelr\(**sin\(*h.
10648919ScaelThese equations are satisfied when (x=0,y=0)
10748919Scaelis mapped to
10848919Scael.if n \
10948919Scael(r=0,theta=0)
11048919Scael.if t \
11148919Scael(r=0,\(*h=0)
11248919Scaelon a VAX.  In general, conversions to polar coordinates
11348919Scaelshould be computed thus:
11448919Scael.Bd -unfilled -offset indent
11548919Scael.if n \{\
11648919Scaelr	:= hypot(x,y);  ... := sqrt(x\(**x+y\(**y)
11748919Scaeltheta	:= atan2(y,x).
11848919Scael.\}
11948919Scael.if t \{\
12048919Scaelr	:= hypot(x,y);  ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
12148919Scael\(*h	:= atan2(y,x).
12248919Scael.\}
12348919Scael.Ed
12448919Scael.It
12548919ScaelThe foregoing formulas need not be altered to cope in a
12648919Scaelreasonable way with signed zeros and infinities
12748919Scaelon a machine that conforms to
12848919Scael.Tn IEEE 754 ;
12948919Scaelthe versions of
13048919Scael.Xr hypot 3
13148919Scaeland
13248919Scael.Fn atan2
13348919Scaelprovided for
13448919Scaelsuch a machine are designed to handle all cases.
13548919ScaelThat is why
13648919Scael.Fn atan2 \(+-0 \-0
13748919Scael= \(+-\*(Pi
13848919Scaelfor instance.
13948919ScaelIn general the formulas above are equivalent to these:
14048919Scael.Bd -unfilled -offset indent
14148919Scael.if n \
14248919Scaelr := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
14348919Scael.if t \
14448919Scaelr := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
14548919Scael.Ed
14648919Scael.El
14748919Scael.Sh SEE ALSO
14848919Scael.Xr acos 3 ,
14948919Scael.Xr asin 3 ,
15048919Scael.Xr atan 3 ,
15148919Scael.Xr cos 3 ,
15248919Scael.Xr cosh 3 ,
15348919Scael.Xr sin 3 ,
15448919Scael.Xr sinh 3 ,
15548919Scael.Xr tan 3 ,
15648919Scael.Xr tanh 3 ,
15748919Scael.Xr math 3 ,
15848919Scael.Sh STANDARDS
15948919ScaelThe
16048919Scael.Fn atan2
16148919Scaelfunction conforms to
16248919Scael.St -ansiC .
163