Help us shape the future of Go! Take the 2026 Go Developer Survey

math

package
v1.28.31 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 6 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOverflow  = errors.New("overflow")
	ErrUnderflow = errors.New("underflow")

	// Deprecated: Add64 is deprecated. Use Add[uint64] instead.
	Add64 = Add[uint64]

	// Deprecated: Mul64 is deprecated. Use Mul[uint64] instead.
	Mul64 = Mul[uint64]
)

Functions

func AbsDiff added in v0.1.1

func AbsDiff[T Unsigned](a, b T) T

func Add added in v0.1.1

func Add[T Unsigned](a, b T) (T, error)

Add returns: 1) a + b 2) If there is overflow, an error

func MaxUint added in v0.1.1

func MaxUint[T Unsigned]() T

MaxUint returns the maximum value of an unsigned integer of type T.

func Mul added in v0.1.1

func Mul[T Unsigned](a, b T) (T, error)

Mul returns: 1) a * b 2) If there is overflow, an error

func Sub added in v0.1.1

func Sub[T Unsigned](a, b T) (T, error)

Sub returns: 1) a - b 2) If there is underflow, an error

Types

type Averager added in v0.1.1

type Averager interface {
	// Observe the value at the given time
	Observe(value float64, currentTime time.Time)

	// Read returns the average of the provided values.
	Read() float64
}

Averager tracks a continuous time exponential moving average of the provided values.

func NewAverager added in v0.1.1

func NewAverager(
	initialPrediction float64,
	halflife time.Duration,
	currentTime time.Time,
) Averager

func NewSyncAverager added in v0.1.1

func NewSyncAverager(averager Averager) Averager

func NewUninitializedAverager added in v0.1.1

func NewUninitializedAverager(halfLife time.Duration) Averager

NewUninitializedAverager creates a new averager with the given halflife. If [Read] is called before [Observe], the zero value will be returned. When [Observe] is called the first time, the averager will be initialized with [value] at that time.

type AveragerHeap added in v0.1.1

type AveragerHeap interface {
	// Add the average to the heap. If [nodeID] is already in the heap, the
	// average will be replaced and the old average will be returned. If there
	// was not an old average, false will be returned.
	Add(nodeID ids.NodeID, averager Averager) (Averager, bool)
	// Remove attempts to remove the average that was added with the provided
	// [nodeID], if none is contained in the heap, [false] will be returned.
	Remove(nodeID ids.NodeID) (Averager, bool)
	// Pop attempts to remove the node with either the largest or smallest
	// average, depending on if this is a max heap or a min heap, respectively.
	Pop() (ids.NodeID, Averager, bool)
	// Peek attempts to return the node with either the largest or smallest
	// average, depending on if this is a max heap or a min heap, respectively.
	Peek() (ids.NodeID, Averager, bool)
	// Len returns the number of nodes that are currently in the heap.
	Len() int
}

AveragerHeap maintains a heap of the averagers.

func NewMaxAveragerHeap added in v0.1.1

func NewMaxAveragerHeap() AveragerHeap

NewMaxAveragerHeap returns a new empty max heap. The returned heap is not thread safe.

type Unsigned added in v1.22.76

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Unsigned is a constraint that permits any unsigned integer type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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