xref: /openbsd-src/lib/libm/man/atan2.3 (revision db3296cf5c1dd9058ceecc3a29fe4aaa0bd26000)
1.\"	$OpenBSD: atan2.3,v 1.9 2003/06/02 20:18:41 millert 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. Neither the name of the University nor the names of its contributors
14.\"    may be used to endorse or promote products derived from this software
15.\"    without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.\"     from: @(#)atan2.3	5.1 (Berkeley) 5/2/91
30.\"
31.Dd May 2, 1991
32.Dt ATAN2 3
33.Os
34.Sh NAME
35.Nm atan2 ,
36.Nm atan2f
37.Nd arc tangent functions of two variables
38.Sh SYNOPSIS
39.Fd #include <math.h>
40.Ft double
41.Fn atan2 "double y" "double x"
42.Ft float
43.Fn atan2f "float y" "float x"
44.Sh DESCRIPTION
45The
46.Fn atan2
47function computes the principal value of the arc tangent of
48.Ar y/ Ns Ar x ,
49using the signs of both arguments to determine the quadrant of
50the return value.
51The
52.Fn atan2f
53function is a single precision version of
54.Fn atan2 .
55.Sh RETURN VALUES
56The
57.Fn atan2
58and
59.Fn atan2f
60functions, if successful,
61return 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