From 3586889c03cae00263de98129b1662e9abc7b14a Mon Sep 17 00:00:00 2001 From: Tobi Oetiker Date: Tue, 11 Sep 2007 06:12:01 +0000 Subject: rounding error fix for sqrt --- CHANGES | 2 ++ lib/Smokeping/RRDhelpers.pm | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index e0e2ae8..0b27331 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +* fixed problem with rounding error in calculating stddev + 2007/9/06 -- released version 2.2.3 * alter ajax grapher mode to use seconds timestamps and not iso dates this prevents timezone problems with the browser -- tobi diff --git a/lib/Smokeping/RRDhelpers.pm b/lib/Smokeping/RRDhelpers.pm index 3f4fa5b..e491a5c 100644 --- a/lib/Smokeping/RRDhelpers.pm +++ b/lib/Smokeping/RRDhelpers.pm @@ -52,7 +52,8 @@ sub get_stddev{ } } return undef unless $cnt; - return sqrt( 1.0 / $cnt * ( $sqsum - $sum**2 / $cnt )) + my $sqdev = 1.0 / $cnt * ( $sqsum - $sum**2 / $cnt ); + return $sqdev < 0.0 ? 0.0 : sqrt($sqdev); } -- cgit v1.2.3-24-g4f1b