ad5d8c21ea1ecd0a30719fc3fe919eb3326db746
[dragonfly.git] / lib / libm / man / atan2.3
1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     from: @(#)atan2.3       5.1 (Berkeley) 5/2/91
29 .\"     $NetBSD: atan2.3,v 1.16 2003/08/07 16:44:46 agc Exp $
30 .\"     $DragonFly: src/lib/libm/man/atan2.3,v 1.2 2005/12/10 00:22:29 swildner Exp $
31 .\"
32 .Dd May 2, 1991
33 .Dt ATAN2 3
34 .Os
35 .Sh NAME
36 .Nm atan2 ,
37 .Nm atan2f
38 .Nd arc tangent function of two variables
39 .Sh LIBRARY
40 .Lb libm
41 .Sh SYNOPSIS
42 .In math.h
43 .Ft double
44 .Fn atan2 "double y" "double x"
45 .Ft float
46 .Fn atan2f "float y" "float x"
47 .Sh DESCRIPTION
48 The
49 .Fn atan2
50 and
51 .Fn atan2f
52 functions compute the principal value of the arc tangent of
53 .Ar y/ Ns Ar x ,
54 using the signs of both arguments to determine the quadrant of
55 the return value.
56 .Sh RETURN VALUES
57 The
58 .Fn atan2
59 function, if successful,
60 returns the arc tangent of
61 .Ar y/ Ns Ar x
62 in the range
63 .Bk -words
64 .Bq \&- Ns \*(Pi , \&+ Ns \*(Pi
65 .Ek
66 radians.
67 If both
68 .Ar x
69 and
70 .Ar y
71 are zero, the global variable
72 .Va errno
73 is set to
74 .Er EDOM .
75 On the
76 .Tn VAX :
77 .Bl -column atan_(y,x)_:=____  sign(y)_(Pi_atan2(Xy_xX))___
78 .It Fn atan2 y x No := Ta
79 .Fn atan y/x Ta
80 if
81 .Ar x
82 \*[Gt] 0,
83 .It Ta sign( Ns Ar y Ns )*(\*(Pi -
84 .Fn atan "\\*(Bay/x\\*(Ba" ) Ta
85 if
86 .Ar x
87 \*[Lt] 0,
88 .It Ta
89 .No 0 Ta
90 if x = y = 0, or
91 .It Ta
92 .Pf sign( Ar y Ns )*\\*(Pi/2 Ta
93 if
94 .Ar x
95 = 0 \*(Ne
96 .Ar y .
97 .El
98 .Sh NOTES
99 The function
100 .Fn atan2
101 defines "if x \*[Gt] 0,"
102 .Fn atan2 0 0
103 = 0 on a
104 .Tn VAX
105 despite that previously
106 .Fn atan2 0 0
107 may have generated an error message.
108 The reasons for assigning a value to
109 .Fn atan2 0 0
110 are these:
111 .Bl -enum -offset indent
112 .It
113 Programs that test arguments to avoid computing
114 .Fn atan2 0 0
115 must be indifferent to its value.
116 Programs that require it to be invalid are vulnerable
117 to diverse reactions to that invalidity on diverse computer systems.
118 .It
119 The
120 .Fn atan2
121 function is used mostly to convert from rectangular (x,y)
122 to polar
123 .if n\
124 (r,theta)
125 .if t\
126 (r,\(*h)
127 coordinates that must satisfy x =
128 .if n\
129 r\(**cos theta
130 .if t\
131 r\(**cos\(*h
132 and y =
133 .if n\
134 r\(**sin theta.
135 .if t\
136 r\(**sin\(*h.
137 These equations are satisfied when (x=0,y=0)
138 is mapped to
139 .if n \
140 (r=0,theta=0)
141 .if t \
142 (r=0,\(*h=0)
143 on a VAX.
144 In general, conversions to polar coordinates should be computed thus:
145 .Bd -unfilled -offset indent
146 .if n \{\
147 r       := hypot(x,y);  ... := sqrt(x\(**x+y\(**y)
148 theta   := atan2(y,x).
149 .\}
150 .if t \{\
151 r       := hypot(x,y);  ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
152 \(*h    := atan2(y,x).
153 .\}
154 .Ed
155 .It
156 The foregoing formulas need not be altered to cope in a
157 reasonable way with signed zeros and infinities
158 on a machine that conforms to
159 .Tn IEEE 754 ;
160 the versions of
161 .Xr hypot 3
162 and
163 .Fn atan2
164 provided for
165 such a machine are designed to handle all cases.
166 That is why
167 .Fn atan2 \(+-0 \-0
168 = \(+-\*(Pi
169 for instance.
170 In general the formulas above are equivalent to these:
171 .Bd -unfilled -offset indent
172 .if n \
173 r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
174 .if t \
175 r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
176 .Ed
177 .El
178 .Sh SEE ALSO
179 .Xr acos 3 ,
180 .Xr asin 3 ,
181 .Xr atan 3 ,
182 .Xr cos 3 ,
183 .Xr cosh 3 ,
184 .Xr math 3 ,
185 .Xr sin 3 ,
186 .Xr sinh 3 ,
187 .Xr tan 3 ,
188 .Xr tanh 3
189 .Sh STANDARDS
190 The
191 .Fn atan2
192 function conforms to
193 .St -ansiC .