minmax

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: BSD-3-Clause Imports: 2 Imported by: 34

Documentation

Overview

Package minmax provides a struct that holds Min and Max values.

Index

Constants

View Source
const (
	MaxFloat32 float32 = 3.402823466e+38
	MinFloat32 float32 = 1.175494351e-38
)
View Source
const (
	MaxFloat64 float64 = 1.7976931348623158e+308
	MinFloat64 float64 = 2.2250738585072014e-308
)

Variables

This section is empty.

Functions

func NiceRoundNumber

func NiceRoundNumber(x float64, below bool) float64

NiceRoundNumber returns the closest nice round number either above or below the given number, based on the observation that numbers 1, 2, 5 at any power are "nice". This is used for choosing graph labels, and auto-scaling ranges to contain a given value. if below == true then returned number is strictly less than given number otherwise it is strictly larger.

Types

type AvgMax32

type AvgMax32 struct {
	Avg float32
	Max float32

	// sum for computing average
	Sum float32

	// index of max item
	MaxIndex int32

	// number of items in sum
	N int32
	// contains filtered or unexported fields
}

AvgMax holds average and max statistics

func (*AvgMax32) CalcAvg

func (am *AvgMax32) CalcAvg()

CalcAvg computes the average given the current Sum and N values

func (*AvgMax32) CopyFrom

func (am *AvgMax32) CopyFrom(oth *AvgMax32)

CopyFrom copies from other AvgMax32

func (*AvgMax32) Init

func (am *AvgMax32) Init()

Init initializes prior to new updates

func (*AvgMax32) String

func (am *AvgMax32) String() string

func (*AvgMax32) UpdateFrom

func (am *AvgMax32) UpdateFrom(oth *AvgMax32)

UpdateFrom updates these values from other AvgMax32 values

func (*AvgMax32) UpdateFromOther

func (am *AvgMax32) UpdateFromOther(oSum, oMax float32, oN, oMaxIndex int32)

UpdateFromOther updates these values from other AvgMax32 values

func (*AvgMax32) UpdateValue

func (am *AvgMax32) UpdateValue(val float32, idx int32)

UpdateVal updates stats from given value

type AvgMax64

type AvgMax64 struct {
	Avg float64
	Max float64

	// sum for computing average
	Sum float64

	// index of max item
	MaxIndex int32

	// number of items in sum
	N int32
}

AvgMax holds average and max statistics

func (*AvgMax64) CalcAvg

func (am *AvgMax64) CalcAvg()

CalcAvg computes the average given the current Sum and N values

func (*AvgMax64) CopyFrom

func (am *AvgMax64) CopyFrom(oth *AvgMax64)

CopyFrom copies from other AvgMax64

func (*AvgMax64) Init

func (am *AvgMax64) Init()

Init initializes prior to new updates

func (*AvgMax64) UpdateFrom

func (am *AvgMax64) UpdateFrom(oth *AvgMax64)

UpdateFrom updates these values from other AvgMax64

func (*AvgMax64) UpdateValue

func (am *AvgMax64) UpdateValue(val float64, idx int)

UpdateVal updates stats from given value

type F32

type F32 struct {
	Min float32
	Max float32
	// contains filtered or unexported fields
}

F32 represents a min / max range for float32 values. Supports clipping, renormalizing, etc

func (*F32) ClipNormValue

func (mr *F32) ClipNormValue(val float32) float32

ClipNormVal clips then normalizes given value within 0-1 Note: a NaN will remain as a NaN

func (*F32) ClipValue

func (mr *F32) ClipValue(val float32) float32

ClipVal clips given value within Min / Max range Note: a NaN will remain as a NaN

func (*F32) FitInRange

func (mr *F32) FitInRange(oth F32) bool

FitInRange adjusts our Min, Max to fit within those of other F32 returns true if we had to adjust to fit.

func (*F32) FitValInRange

func (mr *F32) FitValInRange(val float32) bool

FitValInRange adjusts our Min, Max to fit given value within Min, Max range returns true if we had to adjust to fit.

func (*F32) InRange

func (mr *F32) InRange(val float32) bool

InRange tests whether value is within the range (>= Min and <= Max)

func (*F32) IsHigh

func (mr *F32) IsHigh(val float32) bool

IsHigh tests whether value is higher than the maximum

func (*F32) IsLow

func (mr *F32) IsLow(val float32) bool

IsLow tests whether value is lower than the minimum

func (*F32) IsValid

func (mr *F32) IsValid() bool

IsValid returns true if Min <= Max

func (*F32) Midpoint

func (mr *F32) Midpoint() float32

Midpoint returns point halfway between Min and Max

func (*F32) NormValue

func (mr *F32) NormValue(val float32) float32

NormVal normalizes value to 0-1 unit range relative to current Min / Max range Clips the value within Min-Max range first.

func (*F32) ProjValue

func (mr *F32) ProjValue(val float32) float32

ProjVal projects a 0-1 normalized unit value into current Min / Max range (inverse of NormVal)

func (*F32) Range

func (mr *F32) Range() float32

Range returns Max - Min

func (*F32) Scale

func (mr *F32) Scale() float32

Scale returns 1 / Range -- if Range = 0 then returns 0

func (*F32) Set

func (mr *F32) Set(mn, mx float32)

Set sets the min and max values

func (*F32) SetInfinity

func (mr *F32) SetInfinity()

SetInfinity sets the Min to +MaxFloat, Max to -MaxFloat -- suitable for iteratively calling Fit*InRange

func (*F32) String

func (mr *F32) String() string

type F64

type F64 struct {
	Min float64
	Max float64
}

F64 represents a min / max range for float64 values. Supports clipping, renormalizing, etc

func (*F64) ClipNormValue

func (mr *F64) ClipNormValue(val float64) float64

ClipNormVal clips then normalizes given value within 0-1 Note: a NaN will remain as a NaN

func (*F64) ClipValue

func (mr *F64) ClipValue(val float64) float64

ClipVal clips given value within Min / Max range Note: a NaN will remain as a NaN

func (*F64) FitInRange

func (mr *F64) FitInRange(oth F64) bool

FitInRange adjusts our Min, Max to fit within those of other F64 returns true if we had to adjust to fit.

func (*F64) FitValInRange

func (mr *F64) FitValInRange(val float64) bool

FitValInRange adjusts our Min, Max to fit given value within Min, Max range returns true if we had to adjust to fit.

func (*F64) InRange

func (mr *F64) InRange(val float64) bool

InRange tests whether value is within the range (>= Min and <= Max)

func (*F64) IsHigh

func (mr *F64) IsHigh(val float64) bool

IsHigh tests whether value is higher than the maximum

func (*F64) IsLow

func (mr *F64) IsLow(val float64) bool

IsLow tests whether value is lower than the minimum

func (*F64) IsValid

func (mr *F64) IsValid() bool

IsValid returns true if Min <= Max

func (*F64) Midpoint

func (mr *F64) Midpoint() float64

Midpoint returns point halfway between Min and Max

func (*F64) NormValue

func (mr *F64) NormValue(val float64) float64

NormVal normalizes value to 0-1 unit range relative to current Min / Max range Clips the value within Min-Max range first.

func (*F64) ProjValue

func (mr *F64) ProjValue(val float64) float64

ProjVal projects a 0-1 normalized unit value into current Min / Max range (inverse of NormVal)

func (*F64) Range

func (mr *F64) Range() float64

Range returns Max - Min

func (*F64) Scale

func (mr *F64) Scale() float64

Scale returns 1 / Range -- if Range = 0 then returns 0

func (*F64) Set

func (mr *F64) Set(mn, mx float64)

Set sets the min and max values

func (*F64) SetInfinity

func (mr *F64) SetInfinity()

SetInfinity sets the Min to +MaxFloat, Max to -MaxFloat -- suitable for iteratively calling Fit*InRange

type Int

type Int struct {
	Min int
	Max int
}

Int represents a min / max range for int values. Supports clipping, renormalizing, etc

func (*Int) ClipNormValue

func (mr *Int) ClipNormValue(val int) float32

ClipNormVal clips then normalizes given value within 0-1

func (*Int) ClipValue

func (mr *Int) ClipValue(val int) int

ClipVal clips given value within Min / Max rangee

func (*Int) FitInRange

func (mr *Int) FitInRange(oth Int) bool

FitInRange adjusts our Min, Max to fit within those of other Int returns true if we had to adjust to fit.

func (*Int) FitValInRange

func (mr *Int) FitValInRange(val int) bool

FitValInRange adjusts our Min, Max to fit given value within Min, Max range returns true if we had to adjust to fit.

func (*Int) InRange

func (mr *Int) InRange(val int) bool

InRange tests whether value is within the range (>= Min and <= Max)

func (*Int) IsHigh

func (mr *Int) IsHigh(val int) bool

IsHigh tests whether value is higher than the maximum

func (*Int) IsLow

func (mr *Int) IsLow(val int) bool

IsLow tests whether value is lower than the minimum

func (*Int) IsValid

func (mr *Int) IsValid() bool

IsValid returns true if Min <= Max

func (*Int) Midpoint

func (mr *Int) Midpoint() float32

Midpoint returns point halfway between Min and Max

func (*Int) NormValue

func (mr *Int) NormValue(val int) float32

NormVal normalizes value to 0-1 unit range relative to current Min / Max range Clips the value within Min-Max range first.

func (*Int) ProjValue

func (mr *Int) ProjValue(val float32) float32

ProjVal projects a 0-1 normalized unit value into current Min / Max range (inverse of NormVal)

func (*Int) Range

func (mr *Int) Range() int

Range returns Max - Min

func (*Int) Scale

func (mr *Int) Scale() float32

Scale returns 1 / Range -- if Range = 0 then returns 0

func (*Int) Set

func (mr *Int) Set(mn, mx int)

Set sets the min and max values

func (*Int) SetInfinity

func (mr *Int) SetInfinity()

SetInfinity sets the Min to +MaxFloat, Max to -MaxFloat -- suitable for iteratively calling Fit*InRange

type Range32

type Range32 struct {

	// Min and Max range values
	F32

	// fix the minimum end of the range
	FixMin bool

	// fix the maximum end of the range
	FixMax bool
}

Range32 represents a range of values for plotting, where the min or max can optionally be fixed

func (*Range32) Range

func (rr *Range32) Range() float32

Range returns Max - Min

func (*Range32) SetMax

func (rr *Range32) SetMax(mx float32)

SetMax sets a fixed max value

func (*Range32) SetMin

func (rr *Range32) SetMin(mn float32)

SetMin sets a fixed min value

type Range64

type Range64 struct {

	// Min and Max range values
	F64

	// fix the minimum end of the range
	FixMin bool

	// fix the maximum end of the range
	FixMax bool
}

Range64 represents a range of values for plotting, where the min or max can optionally be fixed

func (*Range64) Range

func (rr *Range64) Range() float64

Range returns Max - Min

func (*Range64) SetMax

func (rr *Range64) SetMax(mx float64)

SetMax sets a fixed max value

func (*Range64) SetMin

func (rr *Range64) SetMin(mn float64)

SetMin sets a fixed min value

Jump to

Keyboard shortcuts

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