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:
parent
984793d445
commit
ad70a85426
1 changed files with 4 additions and 1 deletions
|
@ -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
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue