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