Run NodesReferenceutils

math

Package math

import "github.com/luxfi/node/utils/math"

Functions

AbsDiff

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

Add

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

Add returns:

  1. a + b
  2. If there is overflow, an error

MaxUint

func MaxUint[T Unsigned]() T

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

Mul

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

Mul returns:

  1. a * b
  2. If there is overflow, an error

Sub

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

Sub returns:

  1. a - b
  2. If there is underflow, an error

Types

Averager

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

func NewAverager(
	initialPrediction float64,
	halflife time.Duration,
	currentTime time.Time,
) Averager
func NewSyncAverager(averager Averager) Averager
func NewUninitializedAverager(halfLife time.Duration) Averager

AveragerHeap

AveragerHeap maintains a heap of the averagers.

func NewMaxAveragerHeap() AveragerHeap

Unsigned

Unsigned is a constraint that permits any unsigned integer type.