* add.f - compensated addition by the Kahan algorithm
SUBROUTINE ADD (X, N, R)
IMPLICIT NONE
INTEGER N
REAL X, R
DIMENSION X(N)
INTEGER K
DOUBLE PRECISION S, C, Y, T
S = 0.
C = 0.
DO K = 1, N
Y = X(K) - C
T = S + Y
C = (T - S) - Y
S = T
END DO
R = SNGL(S)
RETURN
END ! of ADD
* same thing in double precision
SUBROUTINE DADD (X, N, S)
IMPLICIT NONE
INTEGER N
DOUBLE PRECISION X, S
DIMENSION X(N)
INTEGER K
DOUBLE PRECISION C, Y, T
S = 0.
C = 0.
DO K = 1, N
Y = X(K) - C
T = S + Y
C = (T - S) - Y
S = T
END DO
RETURN
END ! of DADD
*+++++++++++++++++++++++++ End of file add.f +++++++++++++++++++++++++++