aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2019-03-09 19:08:21 -0500
committerMitch Riedstra <mitch@riedstra.us>2019-03-09 19:08:21 -0500
commita2245a9a1653dc25e899ea8b090d2c6be48b00a3 (patch)
tree68d8d316c7c734f71ff46d9c8c227caa72af58d1
parent7f208a0c1ec60f97e4bdd81aea0490cf247c6020 (diff)
downloadstats-a2245a9a1653dc25e899ea8b090d2c6be48b00a3.tar.gz
stats-a2245a9a1653dc25e899ea8b090d2c6be48b00a3.tar.xz
Add min and max
-rw-r--r--print.go4
-rw-r--r--stats.go9
2 files changed, 12 insertions, 1 deletions
diff --git a/print.go b/print.go
index 2a39c71..8bdeea3 100644
--- a/print.go
+++ b/print.go
@@ -7,12 +7,14 @@ import (
// Prints each calculated statistic on a line with one tab preceding it
func (s *Stats) PrettyStats() string {
return fmt.Sprintf(`
+ Min: %.2f
+ Max: %.2f
Mean: %.2f
Variance: %.2f
Standard Deviation: %.2f
Skewness: %.2f
Kurtosis: %.2f
-`, s.Mean(), s.Variance(), s.StandardDeviation(), s.Skewness(), s.Kurtosis())
+`, s.Min, s.Max, s.Mean(), s.Variance(), s.StandardDeviation(), s.Skewness(), s.Kurtosis())
}
// Returns a string containing all of the data within the struct
diff --git a/stats.go b/stats.go
index ffe94eb..46ddc99 100644
--- a/stats.go
+++ b/stats.go
@@ -40,6 +40,8 @@ import (
// several methods are exposed in order to make your life easy
type Stats struct {
n, m1, m2, m3, m4 float64
+ Max float64
+ Min float64
}
// Zeros out the struct for re-use
@@ -53,6 +55,13 @@ func (s *Stats) Clear() {
func (s *Stats) Push(x float64) {
var delta, delta_n, delta_n2, term1, n1 float64
+ if x >= s.Max {
+ s.Max = x
+ }
+ if x <= s.Min {
+ s.Min = x
+ }
+
n1 = s.n
s.n++
delta = x - s.m1