1
Fork 0
mirror of https://github.com/RGBCube/superfreq synced 2025-07-27 17:07:44 +00:00

daemon: use integer arithmetic to avoid precision loss

This commit is contained in:
NotAShelf 2025-05-18 07:43:01 +03:00
parent 984793d445
commit ad70a85426
No known key found for this signature in database
GPG key ID: 29D95B64378DB4BF

View file

@ -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 { let blended_interval = if let Some(cached) = system_history.last_computed_interval {
// Use a weighted average: 70% previous value, 30% new value // Use a weighted average: 70% previous value, 30% new value
// This smooths out drastic changes in polling frequency // 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 { } else {
new_interval new_interval
}; };