program Example1 ! This file: http://ftp.aset.psu.edu/pub/ger/fortran/hdk/example1.f90 ! ! !=== Example of numeric breakdown; ! For example try: A=10000., X=0.00001 ! and see P computed as: -68.7 in Single Precision ! or: -119.2. in Double Precision. ! Note that P is algebraically equal to 1.0 for all A and X<>0. ! ! Penn State Information Technology Services ! Graduate Education and Research Services (GEaRS) ! Skip Knoble - 1981 integer, parameter :: PRECISION = selected_real_kind(6) ! integer, parameter :: PRECISION = selected_real_kind(15) ! real(kind=PRECISION) :: P,A,X DO PRINT *, "Evaluating P=((A+X)**2 - A**2 - 2*A*X)/X**2" PRINT *, "Please enter A and X (or Zeros to Quit):" READ *, A,X IF (A == 0 .OR. X == 0) EXIT P=((A+X)**2 - A**2 - 2.0*A*X)/X**2 print *, "P is algebraically equal to 1." print *, "P=",P," A=",A," X=",X END DO print *, "** Example 1 Ended **" end program Example1