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