README.rst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. movavg - Generic Moving Average calculation
  2. ===========================================
  3. `Project home <https://bues.ch/>`_
  4. `Git repository <https://bues.ch/cgit/movavgrs.git>`_
  5. `Github repository <https://github.com/mbuesch/movavgrs>`_
  6. Generic `Moving Average <https://en.wikipedia.org/wiki/Moving_average>`_ calculation for the integer types
  7. * i8, i16, i32, i64, i128, isize
  8. * u8, u16, u32, u64, u128, usize
  9. and float types
  10. * f32, f64
  11. Example Cargo.toml dependencies
  12. ===============================
  13. Add this to your Cargo.toml:
  14. .. code:: toml
  15. [dependencies]
  16. movavg = "2"
  17. Example usage
  18. =============
  19. .. code:: rust
  20. // Integers
  21. let mut avg: MovAvg<i32, i32, 3> = MovAvg::new(); // window size = 3
  22. assert_eq!(avg.feed(10), 10);
  23. assert_eq!(avg.feed(20), 15);
  24. assert_eq!(avg.feed(30), 20);
  25. assert_eq!(avg.feed(40), 30);
  26. assert_eq!(avg.get(), 30);
  27. // Floats
  28. let mut avg: MovAvg<f64, f64, 3> = MovAvg::new();
  29. assert_eq!(avg.feed(10.0), 10.0);
  30. assert_eq!(avg.feed(20.0), 15.0);
  31. assert_eq!(avg.feed(30.0), 20.0);
  32. assert_eq!(avg.feed(40.0), 30.0);
  33. assert_eq!(avg.get(), 30.0);
  34. // Bigger accumulator
  35. let mut avg: MovAvg<i8, i32, 3> = MovAvg::new();
  36. assert_eq!(avg.feed(100), 100);
  37. assert_eq!(avg.feed(100), 100); // This would overflow an i8 accumulator
  38. Cargo Feature selections
  39. ========================
  40. no_std
  41. ------
  42. If you want to use movavg without the `std` library (often called `no_std`), then use the following Cargo.toml dependency to disable the `std` feature:
  43. .. code:: toml
  44. [dependencies]
  45. movavg = { version = "2", default-features = false }
  46. Currently the `no_std` variant supports all functionality that the default `std` variant supports. But that may change in future.
  47. fastfloat
  48. ---------
  49. The `fastfloat` feature can be used to enable much faster, but less accurate floating point calculations. Enabling this feature leads to bigger floating point rounding and cancellation errors.
  50. .. code:: toml
  51. [dependencies]
  52. movavg = { version = "2", features = ["fastfloat"] }
  53. This feature may also be used together with disabled `std` feature (see `no_std`).
  54. Rust compiler version
  55. =====================
  56. Requires Rust compiler version 1.61 or later.
  57. License
  58. =======
  59. Copyright (c) 2021-2023 Michael Büsch <m@bues.ch>
  60. Licensed under the Apache License version 2.0 or the MIT license, at your option.