Skip to content

Commit

Permalink
[math] fix filter moving average for floating-point type
Browse files Browse the repository at this point in the history
std::accumulate<T>(first, last, init) deduces the type T based on the type
of the init argument. Therefore, you need to pass the matching type.
  • Loading branch information
Artiom9 authored and chris-durand committed Sep 26, 2022
1 parent 1d6e5e8 commit 2f05530
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/modm/math/filter/moving_average.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MovingAverage
{
if constexpr(std::floating_point<T>) {
buffer[index] = input;
sum = std::accumulate(std::begin(buffer), std::end(buffer), 0);
sum = std::accumulate(std::begin(buffer), std::end(buffer), T{0});
} else {
sum -= buffer[index];
sum += input;
Expand Down

0 comments on commit 2f05530

Please sign in to comment.