MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / getAverage

Method getAverage

libraries/RunningAverage/RunningAverage.cpp:73–86  ·  view source on GitHub ↗

returns the average of the data-set added so far, NAN if no elements.

Source from the content-addressed store, hash-verified

71
72// returns the average of the data-set added so far, NAN if no elements.
73float 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

Callers 1

unittestFunction · 0.45

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.36