Documentation
¶
Overview ¶
Helper functions for handling floats.
Index ¶
- func Compare(x float64, y float64) (max float64, min float64)
- func Contains(slice []float64, s float64) bool
- func Cumsum(slice []float64) []float64
- func Delta(slice []float64) []float64
- func DropNan(slice []float64) []float64
- func FillNan(slice []float64, method string, prefill bool, validTime int) []float64
- func FindIndex(slice []float64, val float64) (int, bool)
- func Insert(slice []float64, idx int, val float64) []float64
- func IsEqualSlice(s1, s2 []float64) bool
- func IsSameSign(x float64, y float64) bool
- func IsValid(value float64) bool
- func MulSlices(s1, s2 []float64) []float64
- func NanSlice(size int) (nanslice []float64)
- func NumRange(start int, end int, step int) (numberrange []float64)
- func RemoveFrom(slice []float64, s int) []float64
- func ReplaceNan(value float64, replacewith float64) float64
- func ReplaceNans(values []float64, replacewith float64) []float64
- func RoundTo(val float64, digits int) float64
- func RoundToNearest(value float64, nearest float64) float64
- func Select(condition bool, i1, i2 float64) float64
- func SetDefault(defaultval float64, confval float64) float64
- func SliceOf(value float64, size int) []float64
- func SwitchIf(condition bool, i1, i2 float64) (float64, float64)
- type Rounded
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delta ¶
Returns the delta between all consecutive floats. Returned slice length is one item shorter.
func FillNan ¶
Fills NaN values with a value based on given method:
"previous" // fills the NaNs with previous value "linear" // fills the NaNs with linear interpolation
Filling starts from first valid value, thus leaving any preceding NaNs untouched. By setting prefill = true, first valid value is used to replace also the preceding NaNs.
One sample's lifetime can be set by setting validTime value to > 0. Filling is then performed for validTime samples. Using validTime overrides prefill = true -setting
func IsEqualSlice ¶ added in v0.21.0
Checks if two slices are equal, element-wise. NaN and Inf are also handled.
func IsSameSign ¶ added in v0.21.0
Checks if two values have same sign. Zero sign is ambiguous and is considered to be both positive and negative.
func NumRange ¶
Returns an evenly spaced slice of floats, between <start> and <end> with spacing <step>.
func RemoveFrom ¶ added in v0.2.3
Removes an integer from given index
func ReplaceNan ¶
Replaces given value with a new one, if given value is NaN or Inf.
func ReplaceNans ¶
Replaces all NaNs in a slice with given value.
func RoundToNearest ¶ added in v0.2.4
Rounds <value> to <nearest> value
func SetDefault ¶
Replaces default value for a parameter, if the configuration value is zero (ie. initialized empty variable). Note that the function does not make any difference, if the configuration is set to zero on purpose.
Types ¶
type Rounded ¶
type Rounded struct {
Rawvalue float64 // raw value with given digits but no prefix
Prefix string // prefix string
Value float64 // rounded value with given digits and prefix
Response string // response string as <Value> <Prefix><unit>
Prettyvalue float64 // rounded value with one decimal
Prettyresponse string // response string as <Value> <Prefix><unit> ; if value is <0.1 , shows "less than 0.1"
}
func RoundWithPrefix ¶
Returns the rounded value to given digits and correct prefix (M for Megas, k for Kilos etc.) Special case is abs(value) between 1000....10000, which is not converted to kilos (because it looks nicer) set prefix to force certain prefix, otherwise the function figures it out on its' own. These units are excluded from having a prefix
noprefixUnits := []string{"%", "cycles", "years", "°c", "°lon", "°lat", "events", "", " "}