1.\" Copyright (c) 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)atan2.3 8.1 (Berkeley) 06/04/93 7.\" 8.Dd 9.Dt ATAN2 3 10.Os 11.Sh NAME 12.Nm atan2 13.Nd arc tangent function of two variables 14.Sh SYNOPSIS 15.Fd #include <math.h> 16.Ft double 17.Fn atan2 "double y" "double x" 18.Sh DESCRIPTION 19The 20.Xr atan2 21function computes the principal value of the arc tangent of 22.Ar y/ Ns Ar x , 23using the signs of both arguments to determine the quadrant of 24the return value. 25.Sh RETURN VALUES 26The 27.Xr atan2 28function, if successful, 29returns the arc tangent of 30.Ar y/ Ns Ar x 31in the range 32.Bk -words 33.Bq \&- Ns \*(Pi , \&+ Ns \*(Pi 34.Ek 35radians. 36If both 37.Ar x 38and 39.Ar y 40are zero, the global variable 41.Va errno 42is set to 43.Er EDOM . 44On the 45.Tn VAX : 46.Bl -column atan_(y,x)_:=____ sign(y)_(Pi_atan2(Xy_xX))___ 47.It Fn atan2 y x No := Ta 48.Fn atan y/x Ta 49if 50.Ar x 51> 0, 52.It Ta sign( Ns Ar y Ns )*(\*(Pi - 53.Fn atan "\\*(Bay/x\\*(Ba" ) Ta 54if 55.Ar x 56< 0, 57.It Ta 58.No 0 Ta 59if x = y = 0, or 60.It Ta 61.Pf sign( Ar y Ns )*\\*(Pi/2 Ta 62if 63.Ar x 64= 0 \*(!= 65.Ar y . 66.El 67.Sh NOTES 68The function 69.Fn atan2 70defines "if x > 0," 71.Fn atan2 0 0 72= 0 on a 73.Tn VAX 74despite that previously 75.Fn atan2 0 0 76may have generated an error message. 77The reasons for assigning a value to 78.Fn atan2 0 0 79are these: 80.Bl -enum -offset indent 81.It 82Programs that test arguments to avoid computing 83.Fn atan2 0 0 84must be indifferent to its value. 85Programs that require it to be invalid are vulnerable 86to diverse reactions to that invalidity on diverse computer systems. 87.It 88The 89.Fn atan2 90function is used mostly to convert from rectangular (x,y) 91to polar 92.if n\ 93(r,theta) 94.if t\ 95(r,\(*h) 96coordinates that must satisfy x = 97.if n\ 98r\(**cos theta 99.if t\ 100r\(**cos\(*h 101and y = 102.if n\ 103r\(**sin theta. 104.if t\ 105r\(**sin\(*h. 106These equations are satisfied when (x=0,y=0) 107is mapped to 108.if n \ 109(r=0,theta=0) 110.if t \ 111(r=0,\(*h=0) 112on a VAX. In general, conversions to polar coordinates 113should be computed thus: 114.Bd -unfilled -offset indent 115.if n \{\ 116r := hypot(x,y); ... := sqrt(x\(**x+y\(**y) 117theta := atan2(y,x). 118.\} 119.if t \{\ 120r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d) 121\(*h := atan2(y,x). 122.\} 123.Ed 124.It 125The foregoing formulas need not be altered to cope in a 126reasonable way with signed zeros and infinities 127on a machine that conforms to 128.Tn IEEE 754 ; 129the versions of 130.Xr hypot 3 131and 132.Fn atan2 133provided for 134such a machine are designed to handle all cases. 135That is why 136.Fn atan2 \(+-0 \-0 137= \(+-\*(Pi 138for instance. 139In general the formulas above are equivalent to these: 140.Bd -unfilled -offset indent 141.if n \ 142r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x); 143.if t \ 144r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x); 145.Ed 146.El 147.Sh SEE ALSO 148.Xr acos 3 , 149.Xr asin 3 , 150.Xr atan 3 , 151.Xr cos 3 , 152.Xr cosh 3 , 153.Xr sin 3 , 154.Xr sinh 3 , 155.Xr tan 3 , 156.Xr tanh 3 , 157.Xr math 3 , 158.Sh STANDARDS 159The 160.Fn atan2 161function conforms to 162.St -ansiC . 163