returns the average of the data-set added so far, NAN if no elements.
| 71 | |
| 72 | // returns the average of the data-set added so far, NAN if no elements. |
| 73 | float RunningAverage::getAverage() |
| 74 | { |
| 75 | if (_count == 0) |
| 76 | { |
| 77 | return NAN; |
| 78 | } |
| 79 | // OPTIMIZE local variable for sum. |
| 80 | _sum = 0; |
| 81 | for (uint16_t i = 0; i < _count; i++) |
| 82 | { |
| 83 | _sum += _array[i]; |
| 84 | } |
| 85 | return _sum / _count; // multiplication is faster ==> extra admin |
| 86 | } |
| 87 | |
| 88 | |
| 89 | // the larger the size of the internal buffer |