title: Real vs. Integer in Fortran
body: <p>I have a program which loops over one variable and computes a value at each step:</p>
  
  <pre><code>  program cpout
  
    implicit none
  
    !declarations
      integer, parameter :: dp = selected_real_kind(15)
                  ! kind value for double precision
  
      real(dp), parameter :: Ru = 8.314472_dp    
      real(dp) :: cp
      integer :: loT, hiT, i
      real(dp) :: iT
      real(dp),dimension(14) :: ic8a
      real(dp) :: ic8t
      real(dp) :: ic8c
  
      loT = 300
      hiT = 3000
  
  ! ic8a is populated using a subroutine call
  ! I have checked, it reads in reals as it is supposed to
  
      do i = loT, hiT, 1
  
        iT = real(i,dp)
  
        if (iT &gt; ic8t) then
          ic8c = Ru*(ic8a(1) + ic8a(2)*iT + ic8a(3)*(iT**2)
   *                 + ic8a(4)*(iT**3) + ic8a(5)*(iT**4))
        else
          ic8c = Ru*(ic8a(8) + ic8a(9)*iT + ic8a(10)*(iT**2)
   *                 + ic8a(11)*(iT**3) + ic8a(12)*(iT**4))
        end if
  
      end do
  
    end program cpout
  </code></pre>
  
  <p>In my first attempt, I used <code>iT</code> as the integer loop counter, and then used it directly in the formula.  This produced a piecewise graph for <code>iT</code> > <code>ic8t</code>.  When I added <code>i</code> as the counter, and converted <code>iT</code> to real before using it in the formula, the graph came out smooth as it should.  Why should it matter whether <code>iT</code> is real or integer when plugging in to the formula?  My compiler is g77.</p>
  
  <p>EDIT:  The formula gives some inaccurate values for <code>iT</code> &lt; <code>ic8t</code> as well.</p>