1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
28 .\" from: @(#)atan2.3 5.1 (Berkeley) 5/2/91
41 .Nd arc tangent and complex phase angle functions
47 .Fn atan2 "double y" "double x"
49 .Fn atan2f "float y" "float x"
51 .Fn atan2l "long double y" "long double x"
54 .Fn carg "double complex z"
56 .Fn cargf "float complex z"
58 .Fn cargl "long double complex z"
65 functions compute the principal value of the arc tangent of
67 using the signs of both arguments to determine the quadrant of
81 functions compute the complex argument (or phase angle) of
83 The complex argument is the number \*(Th such that
84 .Li z = r * e^(I * \*(Th) ,
90 .Li atan2(cimag(z), creal(z)) ,
101 functions, if successful,
102 return the arc tangent of
106 .Bq \&- Ns \*(Pi , \&+ Ns \*(Pi
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
116 .It Ta sign( Ns Ar y Ns )*(\*(Pi -
117 .Fn atan "\\*(Bay/x\\*(Ba" ) Ta
125 .Pf sign( Ar y Ns )*\\*(Pi/2 Ta
136 = 0 despite that previously
138 may have generated an error message.
139 The reasons for assigning a value to
142 .Bl -enum -offset indent
144 Programs that test arguments to avoid computing
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.
152 function is used mostly to convert from rectangular (x,y)
158 coordinates that must satisfy x =
168 These equations are satisfied when (x=0,y=0)
174 In general, conversions to polar coordinates
175 should be computed thus:
176 .Bd -unfilled -offset indent
178 r := hypot(x,y); ... := sqrt(x\(**x+y\(**y)
182 r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
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
196 such a machine are designed to handle all cases.
201 In general the formulas above are equivalent to these:
202 .Bd -unfilled -offset indent
204 r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
206 r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);