From 1b454c094367ddeb74936b8fc5095cca9992dda4 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 30 Aug 2019 13:57:07 -0400 Subject: [PATCH] mcu: Prevent "math domain errors" in stats calculation Signed-off-by: Kevin O'Connor --- klippy/mcu.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 2aa91691..c9f1c495 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -505,7 +505,8 @@ class MCU: c = 1.0 / (count * self._mcu_freq) self._mcu_tick_avg = tick_sum * c tick_sumsq = params['sumsq'] * self._stats_sumsq_base - self._mcu_tick_stddev = c * math.sqrt(count*tick_sumsq - tick_sum**2) + diff = count*tick_sumsq - tick_sum**2 + self._mcu_tick_stddev = c * math.sqrt(max(0., diff)) self._mcu_tick_awake = tick_sum / self._mcu_freq def _handle_shutdown(self, params): if self._is_shutdown: