tailscale.comtailscale.com/maths Index | Files

package maths

import "tailscale.com/maths"

Package maths contains additional mathematical functions or structures not found in the standard library.

Index

Types

type EWMA

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

EWMA is an exponentially weighted moving average supporting updates at irregular intervals with at most nanosecond resolution. The zero value will compute a half-life of 1 second. It is not safe for concurrent use. TODO(raggi): de-duplicate with tstime/rate.Value, which has a more complex and synchronized interface and does not provide direct access to the stable value.

func NewEWMA

func NewEWMA(halfLifeSeconds float64) *EWMA

NewEWMA creates a new EWMA with the specified half-life. If halfLifeSeconds is 0, it defaults to 1.

func (*EWMA) Get

func (e *EWMA) Get() float64

Get returns the current value of the average

func (*EWMA) Reset

func (e *EWMA) Reset()

Reset clears the EWMA to its initial state

func (*EWMA) Update

func (e *EWMA) Update(value float64, t time.Time)

Update adds a new sample to the average. If t is zero or precedes the last update, the update is ignored.

Source Files

ewma.go

Version
v1.84.0 (latest)
Published
May 21, 2025
Platform
linux/amd64
Imports
2 packages
Last checked
4 hours ago

Tools for package owners.