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