maths

package
v1.82.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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.

Jump to

Keyboard shortcuts

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