fortran66のブログ

fortran について書きます。

ソース

      module m_kahan
        implicit none
      contains
        function sum_kahan(xx) result(s)
        real, intent(in) :: xx(:)
        real :: c, s, x, t
        integer :: i
        c = 0.0
        s = 0.0
        do i = 1, size(xx)
          x = xx(i) - c
          t = s + x
          c = (t - s) - x
          s = t
        end do
        return
        end function sum_kahan
      end module m_kahan