edf.hpp
Created 2025-08-20T03:43:59.802Z, last edited 2025-08-20T10:08:02.737Z
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #pragma once #include "array.hpp" class exponential_decay final { float value{}, decay_rate; public: exponential_decay(float half_life) : decay_rate{std::powf(2, -1.0f / half_life)} {} void adjust(float v) { auto const a = (1.0f - decay_rate) * v; value = value * decay_rate + a; } float operator()() const noexcept { return value; } }; std::ostream &operator<<(std::ostream &os, exponential_decay const &ed) { return os << ed(); } template<std::size_t N> void adjust(std::array<exponential_decay, N> &a, float const v) { for (auto &ed : a) { ed.adjust(v); } } |
© 2002-2026 Kirit & Tai Sælensminde. All forum posts are copyright their respective authors.
Licensed under a Creative Commons License. Non-commercial use is fine so long as you provide attribution.

