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

NAME

12       atan2, atan2f, atan2l — arc tangent functions
13

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

91   Converting Cartesian to Polar Coordinates System
92       The function below uses atan2() to convert a  2d  vector  expressed  in
93       cartesian  coordinates  (x,y)  to  the  polar  coordinates (rho,theta).
94       There are other ways to compute the angle theta, using  asin()  acos(),
95       or atan().  However, atan2() presents here two advantages:
96
97        *  The angle's quadrant is automatically determined.
98
99        *  The singular cases (0,y) are taken into account.
100
101       Finally,  this example uses hypot() rather than sqrt() since it is bet‐
102       ter for special cases; see hypot() for more information.
103
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‐2017, Section 4.20, 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-2017, Standard for Information Technology -- Por‐
137       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
138       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
139       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
140       event of any discrepancy between this version and the original IEEE and
141       The Open Group Standard, the original IEEE and The Open Group  Standard
142       is  the  referee document. The original Standard can be obtained online
143       at http://www.opengroup.org/unix/online.html .
144
145       Any typographical or formatting errors that appear  in  this  page  are
146       most likely to have been introduced during the conversion of the source
147       files to man page format. To report such errors,  see  https://www.ker
148       nel.org/doc/man-pages/reporting_bugs.html .
149
150
151
152IEEE/The Open Group                  2017                            ATAN2(3P)
Impressum