getAvg() gives devision by zero

#15 · closed · 1 comments

View on GitHub ↗

Chris-42

if no samples are inserted the call of getAvg() causes a devision by zero error. Will be great if it is returning 0 in this case.

Comments

JChristensen

It can be argued that would be mathematically incorrect, but if that is the desired behavior, then I would recommend something like: ```c++ movingAvg ma(10); int myAvg = ma.getCount() ? ma.getAvg() : 0; ``` See also #7.