| 1 |
# atan2(y, x): ArcTangent |
| 2 |
|
| 3 |
Arctangent function or inverse tangent function. |
| 4 |
|
| 5 |
## Declaration |
| 6 |
|
| 7 |
### Syntax |
| 8 |
|
| 9 |
```fortran |
| 10 |
retval = atan2(y, x) |
| 11 |
elemental real(p) function atan2(y, x) |
| 12 |
``` |
| 13 |
### Arguments |
| 14 |
|
| 15 |
`y` the input value is the imaginary part of the complex expression |
| 16 |
|
| 17 |
$x + iy$ |
| 18 |
|
| 19 |
`x` the input value, must be real part of the complex expression. |
| 20 |
|
| 21 |
### Return values |
| 22 |
|
| 23 |
The returned value has the kind and TYPE as of the input value `y`. The |
| 24 |
principal value of the argument function of the complex expression $x + iy$ |
| 25 |
is returned. |
| 26 |
|
| 27 |
## Description |
| 28 |
|
| 29 |
**atan2(y, x)** computes the principal value of the argument function of the |
| 30 |
complex expression $x + iy$. This is used to transform from cartesian into |
| 31 |
polar coordinates and allows to determine the angle in the correct quadrant. |
| 32 |
|
| 33 |
It is also represented as: |
| 34 |
|
| 35 |
$tan^{-1}(\frac{y}{x})$ |
| 36 |
|
| 37 |
If `x` is nonzero, the result lies in the range: |
| 38 |
|
| 39 |
$-\pi <= atan(x) <= \pi$ |
| 40 |
|
| 41 |
The sign is positive if `y` is positive. |
| 42 |
|
| 43 |
If `y` is zero and `x` is strictly positive, then the result is 0. |
| 44 |
|
| 45 |
If `x` is negative and `y` is positive zero, then the result is $\pi$. |
| 46 |
|
| 47 |
If `x` is negative and `y` is negative zero, then the result is $-\pi$. |
| 48 |
|
| 49 |
If `x` is zero, then the magnitude of the result is $\frac{\pi}{2}$. |
| 50 |
|
| 51 |
If `y` is negative real zero, the result is $\frac{-\pi}{2}$. |
| 52 |
|
| 53 |
## Types |
| 54 |
|
| 55 |
Supported argument type is real. |
| 56 |
|
| 57 |
```fortran |
| 58 |
interface atan2 |
| 59 |
module procedure satan2, datan2 |
| 60 |
end interface |
| 61 |
|
| 62 |
contains |
| 63 |
|
| 64 |
interface |
| 65 |
elemental real(sp) function satan2(y, x) |
| 66 |
real(sp), intent(in) :: y, x |
| 67 |
end function |
| 68 |
|
| 69 |
elemental real(dp) function datan2(y, x) |
| 70 |
real(dp), intent(in) :: y, x |
| 71 |
end function |
| 72 |
|
| 73 |
end interface |
| 74 |
``` |
| 75 |
## Examples |
| 76 |
|
| 77 |
```fortran |
| 78 |
program intrinsics_atan2 |
| 79 |
implicit none |
| 80 |
print *, atan2(2.679676, 1.0) |
| 81 |
end program |
| 82 |
``` |
| 83 |
|
| 84 |
**Result**: |
| 85 |
|
| 86 |
``` |
| 87 |
0.699521642 |
| 88 |
``` |
| 89 |
|
| 90 |
## See Also |
| 91 |
|