PROGRAM Roundoff_Errors
!-----------------------------------------------------------------------
! Program to show inexact representation of reals by showing that for
! some real values X, X * (1.0 / X) is not equal to 1.  Variables
! used are:
!  
!    X:  a real number entered by the user
!    Y:  X * (1.0 / X)
! Input:   X
! Output:  The value of X, the value of Y = X * (1.0 / X), and a
!          message indicating whether Y is equal to 1
!-----------------------------------------------------------------------

  IMPLICIT NONE
  REAL :: X, Y

  ! Get an arbitrary nonzero real number X
  PRINT *, "Enter nonzero real number:"
  READ *, X

  ! Calculate product of X and 1/X, display it and difference 
  ! between it and 1
  Y = X * (1.0 / X)
  PRINT *, "X =", X, "     Y = X * (1 / X) =", Y
  PRINT *, "1.0 - Y =", 1.0 - Y

  ! Check if product is 1 and display appropriate message
  IF (Y == 1.0) THEN
     PRINT *, "Y equals 1"
  ELSE
     PRINT *, "Due to roundoff error, Y does not equal 1"
  END IF
  STOP
END PROGRAM Roundoff_Errors
