diff options
| author | Will Hawkins <[email protected]> | 2022-11-05 20:37:48 -0400 |
|---|---|---|
| committer | Will Hawkins <[email protected]> | 2022-11-05 20:39:40 -0400 |
| commit | 4508e87a57c54675ac9d94818ea5e0f4c0f7d4e6 (patch) | |
| tree | a884bbdb461f12406ace8b8b8a79ae8b9c00c206 /utilities/utilities.go | |
| parent | 1f36afaf4e2c79aa4bc80f9bc8320ea28cc51f6f (diff) | |
[Refactor] Rename/update MovingAverage to MathematicalSeries
We want the MovingAverage functionality to be more generic and useful
than just doing a moving average calculation. The new functionality
allows for the calculation of the standard deviation and supports a
generic type (so it can be used with integers and floats).
Diffstat (limited to 'utilities/utilities.go')
| -rw-r--r-- | utilities/utilities.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/utilities/utilities.go b/utilities/utilities.go index 5143da5..01e2cdd 100644 --- a/utilities/utilities.go +++ b/utilities/utilities.go @@ -24,23 +24,34 @@ import ( "strings" "sync/atomic" "time" + + "golang.org/x/exp/constraints" ) +func Iota(low int, high int) (made []int) { + + made = make([]int, high-low) + for counter := low; counter < high; counter++ { + made[counter-low] = counter + } + return +} + func IsInterfaceNil(ifc interface{}) bool { return ifc == nil || (reflect.ValueOf(ifc).Kind() == reflect.Ptr && reflect.ValueOf(ifc).IsNil()) } -func SignedPercentDifference( - current float64, - previous float64, +func SignedPercentDifference[T constraints.Float | constraints.Integer]( + current T, + previous T, ) (difference float64) { //return ((current - previous) / (float64(current+previous) / 2.0)) * float64( //100, // ) - return ((current - previous) / previous) * float64( - 100, - ) + fCurrent := float64(current) + fPrevious := float64(previous) + return ((fCurrent - fPrevious) / fPrevious) * 100.0 } func AbsPercentDifference( |
