]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/msun/man/atan2.3
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.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 .\" 4. 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 .\" $FreeBSD$
30 .\"
31 .Dd July 31, 2008
32 .Dt ATAN2 3
33 .Os
34 .Sh NAME
35 .Nm atan2 ,
36 .Nm atan2f ,
37 .Nm atan2l ,
38 .Nm carg ,
39 .Nm cargf ,
40 .Nm cargl
41 .Nd arc tangent and complex phase angle functions
42 .Sh LIBRARY
43 .Lb libm
44 .Sh SYNOPSIS
45 .In math.h
46 .Ft double
47 .Fn atan2 "double y" "double x"
48 .Ft float
49 .Fn atan2f "float y" "float x"
50 .Ft long double
51 .Fn atan2l "long double y" "long double x"
52 .In complex.h
53 .Ft double
54 .Fn carg "double complex z"
55 .Ft float
56 .Fn cargf "float complex z"
57 .Ft long double
58 .Fn cargl "long double complex z"
59 .Sh DESCRIPTION
60 The
61 .Fn atan2 ,
62 .Fn atan2f ,
63 and
64 .Fn atan2l
65 functions compute the principal value of the arc tangent of
66 .Fa y/ Ns Ar x ,
67 using the signs of both arguments to determine the quadrant of
68 the return value.
69 .ie '\*[.T]'utf8' \{\
70 .  ds Th \[*h]
71 .\}
72 .el \{\
73 .  ds Th theta
74 .\}
75 .Pp
76 The
77 .Fn carg ,
78 .Fn cargf ,
79 and
80 .Fn cargl
81 functions compute the complex argument (or phase angle) of
82 .Fa z .
83 The complex argument is the number \*(Th such that
84 .Li z = r * e^(I * \*(Th) ,
85 where
86 .Li r = cabs(z) .
87 The call
88 .Li carg(z)
89 is equivalent to
90 .Li atan2(cimag(z), creal(z)) ,
91 and similarly for
92 .Fn cargf
93 and
94 .Fn cargl .
95 .Sh RETURN VALUES
96 The
97 .Fn atan2 ,
98 .Fn atan2f ,
99 and
100 .Fn atan2l
101 functions, if successful,
102 return the arc tangent of
103 .Fa y/ Ns Ar x
104 in the range
105 .Bk -words
106 .Bq \&- Ns \*(Pi , \&+ Ns \*(Pi
107 .Ek
108 radians.
109 Here are some of the special cases:
110 .Bl -column atan_(y,x)_:=____  sign(y)_(Pi_atan2(Xy_xX))___
111 .It Fn atan2 y x No := Ta
112 .Fn atan y/x Ta
113 if
114 .Ar x
115 > 0,
116 .It Ta sign( Ns Ar y Ns )*(\*(Pi -
117 .Fn atan "\\*(Bay/x\\*(Ba" ) Ta
118 if
119 .Ar x
120 < 0,
121 .It Ta
122 .No 0 Ta
123 if x = y = 0, or
124 .It Ta
125 .Pf sign( Ar y Ns )*\\*(Pi/2 Ta
126 if
127 .Ar x
128 = 0 \(!=
129 .Ar y .
130 .El
131 .Sh NOTES
132 The function
133 .Fn atan2
134 defines "if x > 0,"
135 .Fn atan2 0 0
136 = 0 despite that previously
137 .Fn atan2 0 0
138 may have generated an error message.
139 The reasons for assigning a value to
140 .Fn atan2 0 0
141 are these:
142 .Bl -enum -offset indent
143 .It
144 Programs that test arguments to avoid computing
145 .Fn atan2 0 0
146 must be indifferent to its value.
147 Programs that require it to be invalid are vulnerable
148 to diverse reactions to that invalidity on diverse computer systems.
149 .It
150 The
151 .Fn atan2
152 function is used mostly to convert from rectangular (x,y)
153 to polar
154 .if n\
155 (r,theta)
156 .if t\
157 (r,\(*h)
158 coordinates that must satisfy x =
159 .if n\
160 r\(**cos theta
161 .if t\
162 r\(**cos\(*h
163 and y =
164 .if n\
165 r\(**sin theta.
166 .if t\
167 r\(**sin\(*h.
168 These equations are satisfied when (x=0,y=0)
169 is mapped to
170 .if n \
171 (r=0,theta=0).
172 .if t \
173 (r=0,\(*h=0).
174 In general, conversions to polar coordinates
175 should be computed thus:
176 .Bd -unfilled -offset indent
177 .if n \{\
178 r       := hypot(x,y);  ... := sqrt(x\(**x+y\(**y)
179 theta   := atan2(y,x).
180 .\}
181 .if t \{\
182 r       := hypot(x,y);  ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
183 \(*h    := atan2(y,x).
184 .\}
185 .Ed
186 .It
187 The foregoing formulas need not be altered to cope in a
188 reasonable way with signed zeros and infinities
189 on a machine that conforms to
190 .Tn IEEE 754 ;
191 the versions of
192 .Xr hypot 3
193 and
194 .Fn atan2
195 provided for
196 such a machine are designed to handle all cases.
197 That is why
198 .Fn atan2 \(+-0 \-0
199 = \(+-\*(Pi
200 for instance.
201 In general the formulas above are equivalent to these:
202 .Bd -unfilled -offset indent
203 .if n \
204 r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
205 .if t \
206 r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
207 .Ed
208 .El
209 .Sh SEE ALSO
210 .Xr acos 3 ,
211 .Xr asin 3 ,
212 .Xr atan 3 ,
213 .Xr cabs 3 ,
214 .Xr cos 3 ,
215 .Xr cosh 3 ,
216 .Xr math 3 ,
217 .Xr sin 3 ,
218 .Xr sinh 3 ,
219 .Xr tan 3 ,
220 .Xr tanh 3
221 .Sh STANDARDS
222 The
223 .Fn atan2 ,
224 .Fn atan2f ,
225 .Fn atan2l ,
226 .Fn carg ,
227 .Fn cargf ,
228 and
229 .Fn cargl
230 functions conform to
231 .St -isoC-99 .