Rearrange the arithmetic operations in statistics update
by avoiding small differences of large numbers.

Signed-off-by: Klaus Aehlig <[email protected]>
---
 src/Ganeti/Utils.hs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Ganeti/Utils.hs b/src/Ganeti/Utils.hs
index bf0708e..fa8ccd7 100644
--- a/src/Ganeti/Utils.hs
+++ b/src/Ganeti/Utils.hs
@@ -197,7 +197,7 @@ updateStatistics (SumStatistics s) (x, y) = SumStatistics $ 
s +  (y - x)
 updateStatistics (StdDevStatistics n s var) (x, y) =
   let !ds = y - x
       !dss = y * y - x * x
-      !dnnvar = n * dss - (2 * s + ds) * ds
+      !dnnvar = (n * dss - 2 * s * ds) - ds * ds
       !s' = s + ds
       !var' = max 0 $ var + dnnvar / (n * n)
   in StdDevStatistics n s' var'
-- 
2.2.0.rc0.207.ga3a616c

Reply via email to