mathx

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 4 Imported by: 54

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtLeast added in v1.6.3

func AtLeast[T Numerical](x, lower T) T

AtLeast returns the greater of x or lower.

func AtMost added in v1.6.3

func AtMost[T Numerical](x, upper T) T

AtMost returns the smaller of x or upper.

func Between added in v1.6.3

func Between[T Numerical](x, lower, upper T) T

Between returns the value of x clamped to the range [lower, upper].

func CalcEntropy

func CalcEntropy(m map[any]int) float64

CalcEntropy calculates the entropy of m.

func MaxInt

func MaxInt(a, b int) int

MaxInt returns the larger one of a and b.

func MinInt

func MinInt(a, b int) int

MinInt returns the smaller one of a and b.

Types

type Numerical added in v1.6.5

type Numerical interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type Proba

type Proba struct {
	// contains filtered or unexported fields
}

A Proba is used to test if true on given probability.

func NewProba

func NewProba() *Proba

NewProba returns a Proba.

func (*Proba) TrueOnProba

func (p *Proba) TrueOnProba(proba float64) (truth bool)

TrueOnProba checks if true on given probability.

type Unstable

type Unstable struct {
	// contains filtered or unexported fields
}

An Unstable is used to generate random value around the mean value base on given deviation.

func NewUnstable

func NewUnstable(deviation float64) Unstable

NewUnstable returns an Unstable.

func (Unstable) AroundDuration

func (u Unstable) AroundDuration(base time.Duration) time.Duration

AroundDuration returns a random duration with given base and deviation.

func (Unstable) AroundInt

func (u Unstable) AroundInt(base int64) int64

AroundInt returns a random int64 with given base and deviation.

Jump to

Keyboard shortcuts

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