numf

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(x float64, y float64) (max float64, min float64)

Compare returns maximum and minimum of two floats taking NaNs into account

func Delta

func Delta(floats []float64) []float64

Delta returns the delta between all consecutive floats

func DropNan

func DropNan(slice []float64) []float64

Dropna drop NaNs from a slice

func FillNan

func FillNan(slice []float64, method string, prefill bool, validTime int) []float64

Fillna Fills NaN values with a value base on method. method "previous" fills with previous value,method "linear" fills the NaNs with linear interpolation If no previous value found for filling, first valid value can be used by setting prefill=true validTime (higher number than 1) sets the sample's lifetime. If the sample "dies", NaN is written. This overrides prefill = true -setting

func FindIndex

func FindIndex(slice []float64, val float64) (int, bool)

FindIndex finds the index of first occurrence of the given value

func Insert added in v0.2.3

func Insert(slice []float64, idx int, val float64) []float64

Insert inserts given value to given index into a slice

func IsValid

func IsValid(value float64) bool

IsValid checks whether the given float is a valid number instead of NaN or Inf

func NanSlice

func NanSlice(size int) (nanslice []float64)

NaNSlice Create a slice of NaNs of given size

func NumRange

func NumRange(start int, end int, step int) (numberrange []float64)

NumRange creates a float slice with from start to end, with given step

func RemoveFrom added in v0.2.3

func RemoveFrom(slice []float64, s int) []float64

RemoveFrom removes an integer from given index

func ReplaceNan

func ReplaceNan(value float64, replacewith float64) float64

ReplaceNan If <value> is NaN or Inf, replaces <value> with <replacewith>

func ReplaceNans

func ReplaceNans(values []float64, replacewith float64) []float64

ReplaceNanSlice Replace NaNs in a slice with given value

func RoundTo

func RoundTo(val float64, digits int) float64

RoundTo rounds the number to given digits

func SetDefault

func SetDefault(defaultval float64, confval float64) float64

SetDefault set default value for a parameter, if the configuration value is zero (=initialized empty variable)

Types

type Rounded

type Rounded struct {
	Rawvalue float64 // raw value with given digits
	Prefix   string  // prefix string
	Value    float64 // rounded value with given digits and prefix
	Response string  // response as <Value> <Prefix><unit>
}

func RoundWithPrefix

func RoundWithPrefix(v float64, digits int, unit string, prefix string) Rounded

RoundPrefix returns the rounded value to given digits and correct prefix (Megas, Kilos etc.) Special case is abs value between 1000....10000 which is not converted to kilos (because I like it like that) set prefix to force certain prefix, otherwise the function figures it out on its' own.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL