ntest& = 0
ntest& = ntest& + 1
a(q&) = ntest& / 2 + .125
AverageArrayNS a
(), LBOUND(a
), ntest&
, average#
PRINT "numerically stable "; ntest&; average#; f0!
- s0!
AverageStandardX a
(), LBOUND(a
), ntest&
, averagx#
PRINT "standard not stable"; ntest&; averagx#; f1!
- s1!
ntest& = ntest& * 2
'****************
'* this method is subject to truncation/overflow errors -- fails at large N.
'****************
sum# = 0
sum# = sum# + a(c&)
a# = sum# / (finish - start + 1)
'****************
'* a numerically stable way to calculate the average of elements in an array without the dreaded overflow.
'****************
DIM StatN
AS LONG: StatN
= finish
- start
+ 1
aa_temp = a(c&) + aa_temp
aa_int = aa_int + 1
aa_temp = aa_temp - StatN
average = aa_int + aa_temp / StatN