Lahey/Fujitsu Fortran

ATAN2 Function


The ATAN2 function returns the arctangent of y/x, expressed as radians. The ATAN2 function is able to return a greater range of values than the ATAN function, because it considers the sign of x and y.


ATAN2 (y, x)


y is an INTENT(IN) scalar or array of type REAL.

x is INTENT(IN) and of the same kind as y. If y is an array, x must be an array conformable to y. If y is zero, x cannot be zero.


The result is of the same kind as y. Its value is a REAL representation, expressed in radians, of the principal value of the argument of the complex number x + iy. The result falls within the range -Π < x ≤ Π .

If y is positive, the result is positive. If y is negative, the result is negative. If y is zero and x > 0 , the result is zero. If y is zero and x < 0 , the result is pi. If x is zero, the result is a representation of the value Π/2 having the sign of y.


real :: y=1.,x=1. write(*,*) atan2(y,x) ! writes 0.78539818 write(*,*) atan2(-y,x) ! writes -0.78539818 write(*,*) atan2(y,-x) ! writes 2.3561945 write(*,*) atan2(-y,-x) ! writes -2.3561945 write(*,*) atan2(0.,x) ! writes 0.0000000 write(*,*) atan2(0.,-x) ! writes 3.1415927 write(*,*) atan2(y,0.) ! writes 1.5707963 write(*,*) atan2(-y,0.) ! writes -1.5707963