Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / msun / 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. 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 .\"     from: @(#)atan2.3       5.1 (Berkeley) 5/2/91
33 .\" $FreeBSD: src/lib/msun/man/atan2.3,v 1.6.2.4 2001/12/17 10:08:36 ru Exp $
34 .\" $DragonFly: src/lib/msun/man/Attic/atan2.3,v 1.2 2003/06/17 04:26:52 dillon Exp $
35 .\"
36 .Dd May 2, 1991
37 .Dt ATAN2 3
38 .Os
39 .Sh NAME
40 .Nm atan2 ,
41 .Nm atan2f
42 .Nd arc tangent functions of two variables
43 .Sh LIBRARY
44 .Lb libm
45 .Sh SYNOPSIS
46 .In math.h
47 .Ft double
48 .Fn atan2 "double y" "double x"
49 .Ft float
50 .Fn atan2f "float y" "float x"
51 .Sh DESCRIPTION
52 The
53 .Fn atan2
54 and the
55 .Fn atan2f
56 functions compute the principal value of the arc tangent of
57 .Fa y/ Ns Ar x ,
58 using the signs of both arguments to determine the quadrant of
59 the return value.
60 .Sh RETURN VALUES
61 The
62 .Fn atan2
63 and the
64 .Fn atan2f
65 functions, if successful,
66 return the arc tangent of
67 .Fa y/ Ns Ar x
68 in the range
69 .Bk -words
70 .Bq \&- Ns \*(Pi , \&+ Ns \*(Pi
71 .Ek
72 radians.
73 If both
74 .Fa x
75 and
76 .Fa y
77 are zero, the global variable
78 .Va errno
79 is set to
80 .Er EDOM .
81 On the
82 .Tn VAX :
83 .Bl -column atan_(y,x)_:=____  sign(y)_(Pi_atan2(Xy_xX))___
84 .It Fn atan2 y x No := Ta
85 .Fn atan y/x Ta
86 if
87 .Ar x
88 > 0,
89 .It Ta sign( Ns Ar y Ns )*(\*(Pi -
90 .Fn atan "\\*(Bay/x\\*(Ba" ) Ta
91 if
92 .Ar x
93 < 0,
94 .It Ta
95 .No 0 Ta
96 if x = y = 0, or
97 .It Ta
98 .Pf sign( Ar y Ns )*\\*(Pi/2 Ta
99 if
100 .Ar x
101 = 0 \(!=
102 .Ar y .
103 .El
104 .Sh NOTES
105 The function
106 .Fn atan2
107 defines "if x > 0,"
108 .Fn atan2 0 0
109 = 0 on a
110 .Tn VAX
111 despite that previously
112 .Fn atan2 0 0
113 may have generated an error message.
114 The reasons for assigning a value to
115 .Fn atan2 0 0
116 are these:
117 .Bl -enum -offset indent
118 .It
119 Programs that test arguments to avoid computing
120 .Fn atan2 0 0
121 must be indifferent to its value.
122 Programs that require it to be invalid are vulnerable
123 to diverse reactions to that invalidity on diverse computer systems.
124 .It
125 The
126 .Fn atan2
127 function is used mostly to convert from rectangular (x,y)
128 to polar
129 .if n\
130 (r,theta)
131 .if t\
132 (r,\(*h)
133 coordinates that must satisfy x =
134 .if n\
135 r\(**cos theta
136 .if t\
137 r\(**cos\(*h
138 and y =
139 .if n\
140 r\(**sin theta.
141 .if t\
142 r\(**sin\(*h.
143 These equations are satisfied when (x=0,y=0)
144 is mapped to
145 .if n \
146 (r=0,theta=0)
147 .if t \
148 (r=0,\(*h=0)
149 on a VAX.  In general, conversions to polar coordinates
150 should be computed thus:
151 .Bd -unfilled -offset indent
152 .if n \{\
153 r       := hypot(x,y);  ... := sqrt(x\(**x+y\(**y)
154 theta   := atan2(y,x).
155 .\}
156 .if t \{\
157 r       := hypot(x,y);  ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
158 \(*h    := atan2(y,x).
159 .\}
160 .Ed
161 .It
162 The foregoing formulas need not be altered to cope in a
163 reasonable way with signed zeros and infinities
164 on a machine that conforms to
165 .Tn IEEE 754 ;
166 the versions of
167 .Xr hypot 3
168 and
169 .Fn atan2
170 provided for
171 such a machine are designed to handle all cases.
172 That is why
173 .Fn atan2 \(+-0 \-0
174 = \(+-\*(Pi
175 for instance.
176 In general the formulas above are equivalent to these:
177 .Bd -unfilled -offset indent
178 .if n \
179 r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
180 .if t \
181 r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
182 .Ed
183 .El
184 .Sh SEE ALSO
185 .Xr acos 3 ,
186 .Xr asin 3 ,
187 .Xr atan 3 ,
188 .Xr cos 3 ,
189 .Xr cosh 3 ,
190 .Xr math 3 ,
191 .Xr sin 3 ,
192 .Xr sinh 3 ,
193 .Xr tan 3 ,
194 .Xr tanh 3
195 .Sh STANDARDS
196 The
197 .Fn atan2
198 function conforms to
199 .St -isoC .