Re: PI number in fortran
I am new in Fortran. I have seen an exercise in a book (Fortran 95 2003 for Scientists and Engineers) and the problem states, we want to calculate tangent of an angle, but since the tangent is simply sin(x) / cos(x), if we have cos(x) < 10^(-20) give an error message, otherwise calculate it by using tan(x) function. Even if I enter 90 degree, since cos(x) < 10^(-20) it could give me error message. Here is the code:
PROGRAM EX3632
IMPLICIT NONE
! VARIABLES
REAL :: THETA
REAL, PARAMETER :: PI = 3.14159265358979323846264338327950288419716939937510
! EXECUTION
WRITE(*,*) "WRITE THE ANGLE IN DEGREE FORMAT TO CALCULATE"
WRITE(*,*) "TANGENT?"
READ(*,*) THETA
IF(ABS( COS(PI*THETA/180) ) > 1E-20) THEN
WRITE(*,*) TAN(PI*THETA/180.)
WRITE(*,*) TAN((16*ATAN(1./5.) - 4*ATAN(1./239.))*THETA/180)
ELSE
WRITE(*,*) "ERROR, COS(x) IS TOO SMALL TO CALCULATE"
END IF
END PROGRAM EX3632