File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -54,21 +54,20 @@ class FastAvg {
5454};
5555
5656/* *
57- * Calculates a moving average of unknown length
57+ * Calculates a moving average of variable length
5858 * Can periodically get and reset a value to average for an unknown amount of data points
5959 * If len != 0 calculates an exponential moving average with length len.
60- * If len = 0 length equals the current amount of samples.
60+ * If len = 0 length equals the current amount of samples up to 0x7FFFFFFF .
6161 */
6262template <class T >
6363class FastMovingAverage {
6464public:
65- FastMovingAverage (int32_t len = 0 ) : fixedLen(len), count(0 ){};
65+ FastMovingAverage (int32_t len = 0 ) : fixedLen(len > 0 ? len : INT32_MAX ), count(0 ){};
6666 ~FastMovingAverage (){};
6767
6868 void clear (){
6969 curAvg = 0 ;
70- if (!fixedLen)
71- count=0 ;
70+ count=0 ;
7271 }
7372 /* *
7473 * Gets current average and clears current average and counter
@@ -89,7 +88,7 @@ class FastMovingAverage{
8988 * Adds a value and returns current average
9089 */
9190 T addValue (T v){
92- if (!fixedLen || count < fixedLen)
91+ if (count < fixedLen)
9392 count++;
9493 curAvg += (v - curAvg)/count;
9594 return curAvg;
You can’t perform that action at this time.
0 commit comments