1ATAN2(3P)                  POSIX Programmer's Manual                 ATAN2(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       atan2, atan2f, atan2l — arc tangent functions
14

SYNOPSIS

16       #include <math.h>
17
18       double atan2(double y, double x);
19       float atan2f(float y, float x);
20       long double atan2l(long double y, long double x);
21

DESCRIPTION

23       The functionality described on this reference page is aligned with  the
24       ISO C  standard.  Any  conflict between the requirements described here
25       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
26       defers to the ISO C standard.
27
28       These functions shall compute the principal value of the arc tangent of
29       y/x, using the signs of both arguments to determine the quadrant of the
30       return value.
31
32       An  application  wishing to check for error situations should set errno
33       to zero and  call  feclearexcept(FE_ALL_EXCEPT)  before  calling  these
34       functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
35       FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero,  an  error  has
36       occurred.
37

RETURN VALUE

39       Upon  successful  completion, these functions shall return the arc tan‐
40       gent of y/x in the range [−π,π] radians.
41
42       If y is ±0 and x is < 0, ±π shall be returned.
43
44       If y is ±0 and x is > 0, ±0 shall be returned.
45
46       If y is < 0 and x is ±0, −π/2 shall be returned.
47
48       If y is > 0 and x is ±0, π/2 shall be returned.
49
50       If x is 0, a pole error shall not occur.
51
52       If either x or y is NaN, a NaN shall be returned.
53
54       If the correct value would cause underflow, a range  error  may  occur,
55       and  atan(),  atan2f(),  and  atan2l()  shall return an implementation-
56       defined value no  greater  in  magnitude  than  DBL_MIN,  FLT_MIN,  and
57       LDBL_MIN, respectively.
58
59       If  the  IEC  60559  Floating-Point  option is supported, y/x should be
60       returned.
61
62       If y is ±0 and x is −0, ±π shall be returned.
63
64       If y is ±0 and x is +0, ±0 shall be returned.
65
66       For finite values of ±y > 0, if x is −Inf, ±π shall be returned.
67
68       For finite values of ±y > 0, if x is +Inf, ±0 shall be returned.
69
70       For finite values of x, if y is ±Inf, ±π/2 shall be returned.
71
72       If y is ±Inf and x is −Inf, ±3π/4 shall be returned.
73
74       If y is ±Inf and x is +Inf, ±π/4 shall be returned.
75
76       If both arguments are 0, a domain error shall not occur.
77

ERRORS

79       These functions may fail if:
80
81       Range Error The result underflows.
82
83                   If the integer expression (math_errhandling  &  MATH_ERRNO)
84                   is  non-zero,  then errno shall be set to [ERANGE].  If the
85                   integer expression (math_errhandling &  MATH_ERREXCEPT)  is
86                   non-zero, then the underflow floating-point exception shall
87                   be raised.
88
89       The following sections are informative.
90

EXAMPLES

92   Converting Cartesian to Polar Coordinates System
93       The function below uses atan2() to convert a  2d  vector  expressed  in
94       cartesian  coordinates  (x,y)  to  the  polar  coordinates (rho,theta).
95       There are other ways to compute the angle theta, using  asin()  acos(),
96       or atan().  However, atan2() presents here two advantages:
97
98        *  The angle's quadrant is automatically determined.
99
100        *  The singular cases (0,y) are taken into account.
101
102       Finally,  this example uses hypot() rather than sqrt() since it is bet‐
103       ter for special cases; see hypot() for more information.
104
105           #include <math.h>
106
107           void
108           cartesian_to_polar(const double x, const double y,
109                              double *rho, double *theta
110               )
111           {
112               *rho   = hypot (x,y); /* better than sqrt(x*x+y*y) */
113               *theta = atan2 (y,x);
114           }
115

APPLICATION USAGE

117       On  error,  the  expressions  (math_errhandling   &   MATH_ERRNO)   and
118       (math_errhandling  & MATH_ERREXCEPT) are independent of each other, but
119       at least one of them must be non-zero.
120

RATIONALE

122       None.
123

FUTURE DIRECTIONS

125       None.
126

SEE ALSO

128       acos(),  asin(),  atan(),  feclearexcept(),  fetestexcept(),   hypot(),
129       isnan(), sqrt(), tan()
130
131       The Base Definitions volume of POSIX.1‐2008, Section 4.19, Treatment of
132       Error Conditions for Mathematical Functions, <math.h>
133
135       Portions of this text are reprinted and reproduced in  electronic  form
136       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
137       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
138       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
139       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
140       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
141       event of any discrepancy between this version and the original IEEE and
142       The  Open Group Standard, the original IEEE and The Open Group Standard
143       is the referee document. The original Standard can be  obtained  online
144       at http://www.unix.org/online.html .
145
146       Any  typographical  or  formatting  errors that appear in this page are
147       most likely to have been introduced during the conversion of the source
148       files  to  man page format. To report such errors, see https://www.ker
149       nel.org/doc/man-pages/reporting_bugs.html .
150
151
152
153IEEE/The Open Group                  2013                            ATAN2(3P)
Impressum