From ad70a8542655338cd385bea65d7eccf9bc987a07 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 18 May 2025 07:43:01 +0300 Subject: [PATCH] daemon: use integer arithmetic to avoid precision loss --- src/daemon.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/daemon.rs b/src/daemon.rs index f7ef7cb..16b3548 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -124,7 +124,10 @@ fn compute_new(params: &IntervalParams, system_history: &SystemHistory) -> u64 { let blended_interval = if let Some(cached) = system_history.last_computed_interval { // Use a weighted average: 70% previous value, 30% new value // This smooths out drastic changes in polling frequency - (cached as f32).mul_add(0.7, new_interval as f32 * 0.3).round() as u64 + // We use integer arithmetic to avoid precision loss with large interval values + // I think Clippy warned me about this at some point and I ignored it. Now I come + // crawling back to it... + (cached * 7 + new_interval * 3) / 10 } else { new_interval };