movavg - Generic Moving Average calculation

https://bues.ch/

Generic Moving Average calculation for the integer types

and float types

Usage

Add this to your Cargo.toml:

{.toml} [dependencies] movavg = "2.0"

Example usage:

``` {.rust} // Integers let mut avg: MovAvg = MovAvg::new(); // window size = 3 asserteq!(avg.feed(10), 10); asserteq!(avg.feed(20), 15); asserteq!(avg.feed(30), 20); asserteq!(avg.feed(40), 30); assert_eq!(avg.get(), 30);

// Floats let mut avg: MovAvg = MovAvg::new(); asserteq!(avg.feed(10.0), 10.0); asserteq!(avg.feed(20.0), 15.0); asserteq!(avg.feed(30.0), 20.0); asserteq!(avg.feed(40.0), 30.0); assert_eq!(avg.get(), 30.0);

// Bigger accumulator let mut avg: MovAvg = MovAvg::new(); asserteq!(avg.feed(100), 100); asserteq!(avg.feed(100), 100); // This would overflow an i8 accumulator ```

Rust compiler version

Requires Rust compiler version 1.51 or later.

License

Copyright (c) 2021 Michael Buesch \<m@bues.ch>

Licensed under the Apache License version 2.0 or the MIT license, at your option.