Calculate sum using BIQUAD:
(This should produce the exact same result as a standard sum function)
DIM _SUM_F[13]
_SUM_F[0]=1
_SUM_F[3]=-1
DEF SUM(A)
DIM TEMP[LEN(A)]
_SUM_F[7]=0
BIQUAD TEMP,A,_SUM_F
RETURN TEMP[LEN(A)-1]
END
Internally this uses the algorithm:
TEMP[n] = TEMP[n-1]*1 - A[n]*-1, where
_SUM_F[7] is used for
TEMP[-1]
obsolete
You can use FFT to calculate the average of an array
(Note: this is slower and less accurate than SUM(A)/LEN(A))
DEF AVG(A)
IF LEN(A)==2 THEN RETURN (A[0]+A[1])/2
VAR L=1<<CEIL(LOG(LEN(A),2))
DIM T[L]
COPY T,A
FFT T,T,T,T
RETURN T[0]*(L/LEN(A))
END
This won't give the *exact* same result as the standard way of calculating average, but it's pretty close, and faster for long arrays.