From 089e7eb6b33b0481f053ed87db22b51589cbd7ef Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Fri, 15 Apr 2016 10:17:57 -0700 Subject: [PATCH] Don't truncate time when accumulating, and then divide by non-truncated. --- libraries/shared/src/shared/RateCounter.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/shared/src/shared/RateCounter.h b/libraries/shared/src/shared/RateCounter.h index 754439ec15..e24b1e6eca 100644 --- a/libraries/shared/src/shared/RateCounter.h +++ b/libraries/shared/src/shared/RateCounter.h @@ -22,10 +22,10 @@ class RateCounter { public: void increment(size_t count = 1) { auto now = usecTimestampNow(); - auto currentIntervalMs = (uint32_t)((now - _start) / USECS_PER_MSEC); - if (currentIntervalMs > INTERVAL) { + float currentIntervalMs = (now - _start) / (float) USECS_PER_MSEC; + if (currentIntervalMs > (float) INTERVAL) { float currentCount = _count; - float intervalSeconds = (float)currentIntervalMs / (float)MSECS_PER_SECOND; + float intervalSeconds = currentIntervalMs / (float) MSECS_PER_SECOND; _rate = roundf(currentCount / intervalSeconds * _scale) / _scale; _start = now; _count = 0;