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

Method add

libraries/Statistic/Statistic.h:154–181  ·  view source on GitHub ↗

returns value actually added

Source from the content-addressed store, hash-verified

152
153 // returns value actually added
154 value_type add(const value_type value) {
155 value_type previousSum = _sum;
156 if (_cnt == 0)
157 {
158 _min = value;
159 _max = value;
160 } else {
161 if (value < _min) _min = value;
162 else if (value > _max) _max = value;
163 }
164 _sum += value;
165 _cnt++;
166
167 if (_useStdDev && (_cnt > 1))
168 {
169 value_type _store = (_sum / _cnt - value);
170 _extra.ssqdif(_extra.ssqdif() + _cnt * _store * _store / (_cnt - 1));
171
172 // NOTE: pre 1.0.0 code
173 // ~10% faster but limits the amount of samples to 65K as _cnt*_cnt overflows
174 // value_type _store = _sum - _cnt * value;
175 // _ssqdif = _ssqdif + _store * _store / (_cnt*_cnt - _cnt);
176 //
177 // solution: TODO verify
178 // _ssqdif = _ssqdif + (_store * _store / _cnt) / (_cnt - 1);
179 }
180 return _sum - previousSum;
181 }
182
183
184 // returns the number of values added

Callers 1

unittestFunction · 0.45

Calls 1

ssqdifMethod · 0.45

Tested by 1

unittestFunction · 0.36