diff options
Diffstat (limited to 'stats.go')
| -rw-r--r-- | stats.go | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -40,8 +40,7 @@ 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 + max, min *float64 } // Zeros out the struct for re-use @@ -55,11 +54,11 @@ 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 s.max == nil || x >= *s.max { + s.max = &x } - if x <= s.Min { - s.Min = x + if s.min == nil || x <= *s.min { + s.min = &x } n1 = s.n @@ -97,3 +96,11 @@ func (s *Stats) Skewness() float64 { func (s *Stats) Kurtosis() float64 { return s.n*s.m4/(s.m2*s.m2) - 3 } + +func (s *Stats) Min() float64 { + return *s.min +} + +func (s *Stats) Max() float64 { + return *s.max +} |
