x - The type and kind type parameter shall be the same as y. If y is zero, then x must be nonzero.

Return value

The return value has the same type and kind type parameter as y. It is the principal value of the complex number $X+iY$. If x is nonzero, then it lies in the range $-\pi \le atan(x)\le \pi $. The sign is positive if y is positive. If y is zero, then the return value is zero if x is positive and $\pi $ if x is negative. Finally, if x is zero, then the magnitude of the result is $\pi /2$.

Example

program test_atan2real(4)::x=1.e0_4,y=0.5e0_4x=atan2(y,x)endprogram test_atan2

Note: In Return value, NNemec changed the first $\le $ to $<$. Joe Krahn reverted the edit, following F2008 specs.