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