summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobi Oetiker <tobi@oetiker.ch>2007-09-11 08:12:01 +0200
committerTobi Oetiker <tobi@oetiker.ch>2007-09-11 08:12:01 +0200
commit3586889c03cae00263de98129b1662e9abc7b14a (patch)
tree4fd7ee65bf78c5b254b4037bca73a2dfb64c1098
parentfa5abd5d25b193c47400f116c852c0a0b176322a (diff)
downloadsmokeping-3586889c03cae00263de98129b1662e9abc7b14a.tar.gz
smokeping-3586889c03cae00263de98129b1662e9abc7b14a.tar.xz
rounding error fix for sqrt
-rw-r--r--CHANGES2
-rw-r--r--lib/Smokeping/RRDhelpers.pm3
2 files changed, 4 insertions, 1 deletions
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);
}