diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-01-23 13:44:24 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-01-23 13:44:24 -0500 |
| commit | 8702a4095f0d86949b69d379f587f4037d6516fd (patch) | |
| tree | 005d5c2ade491ee2464d67dce92e3341854c3e06 /stats.go | |
| parent | a2245a9a1653dc25e899ea8b090d2c6be48b00a3 (diff) | |
| download | stats-8702a4095f0d86949b69d379f587f4037d6516fd.tar.gz stats-8702a4095f0d86949b69d379f587f4037d6516fd.tar.xz | |
Add working tests. Fix issue with min/max.
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 +} |
