Gin
Loading...
Searching...
No Matches
Public Member Functions | List of all members
RollingAverage Class Reference

Maintains a rolling average of a series of numbers. More...

#include <gin_util.h>

Public Member Functions

 RollingAverage (int numVals_)
 Creates a RollingAverage with the specified weighting factor.
 
double average (double nextValue)
 Updates the rolling average with a new value and returns the new average.
 
double getAverage ()
 Returns the current rolling average value.
 
void setAverage (double avg)
 Sets the current rolling average to a specific value.
 

Detailed Description

Maintains a rolling average of a series of numbers.

This class computes a running average that incorporates new values while maintaining a weighted influence from previous values. Useful for smoothing time-series data.

See also
average, getAverage, setAverage

Constructor & Destructor Documentation

◆ RollingAverage()

RollingAverage::RollingAverage ( int  numVals_)

Creates a RollingAverage with the specified weighting factor.

Parameters
numVals_The number of values to weight the current average by when incorporating new values. Higher values give more weight to the existing average.

Member Function Documentation

◆ average()

double RollingAverage::average ( double  nextValue)

Updates the rolling average with a new value and returns the new average.

Parameters
nextValueThe new value to incorporate into the average
Returns
The updated rolling average

◆ getAverage()

double RollingAverage::getAverage ( )

Returns the current rolling average value.

Returns
The current average

◆ setAverage()

void RollingAverage::setAverage ( double  avg)

Sets the current rolling average to a specific value.

Parameters
avgThe new average value

The documentation for this class was generated from the following file: