Running ave.txt

Warning: if you clip this code into your program, look out for possible html code slipping in.

REM Running average
REM ss 10/98

REM The running average routine uses a minimum number of variables
REM to average over any number of samples by weighting the running
REM average and averaging in the next sample.

REM The algorithm is easy to implement in floating point as simply
REM     running_average = ((99.0 * running_average)+new_sample)/100.0

REM This is the implementation in integer math for positive numbers.
REM Insure that integer overflow does not take place.

GLOBAL running_average AS INTEGER
GLOBAL remainder AS INTEGER, next_sample AS INTEGER

remainder = remainder + ((99 * running_average)+next_sample)\100
running_average = ((99 * running_average)+next_sample)/100
IF remainder > 99
	remainder = remainder - 100
	running_average = running_average + 1
ENDIF