MySQL 26.10.0
Source Code Documentation
fx_stats_util.cc File Reference
#include "fx_stats_util.h"
#include <cmath>
#include <utility>

Functions

double mean_average (const Series &series, int lo, int hi)
 Compute the arithmetic mean of a subsequence of samples. More...
 
int64_t postmod (int64_t a, int64_t m)
 Compute a modulo with a non-negative result ("positive modulo"). More...
 

Function Documentation

◆ mean_average()

double mean_average ( const Series &  series,
int  lo,
int  hi 
)

Compute the arithmetic mean of a subsequence of samples.

Parameters
seriesThe full time series (vector of samples).
loInclusive start index within the series.
hiInclusive end index within the series.
Returns
The mean for the inclusive range [lo, hi], or 0.0 if the range is invalid.
Note
Used for initializing Holt-Winters state (level and detrended season).

◆ postmod()

int64_t postmod ( int64_t  a,
int64_t  m 
)

Compute a modulo with a non-negative result ("positive modulo").

In C++, the % operator can yield negative remainders if the dividend is negative, which is unsuitable for indexing arrays. This helper ensures the result is always in the range [0, m-1].

Parameters
aThe integer value (can be negative).
mThe modulus (must be positive).
Returns
int64_t The remainder of a divided by m, guaranteed non-negative.
Note
Commonly used to wrap seasonal indices in Holt-Winters, ensuring valid access into the seasonal component array.
postmod(5, 4); // returns 1
postmod(-1, 4); // returns 3
postmod(-5, 4); // returns 3
int64_t postmod(int64_t a, int64_t m)
Compute a modulo with a non-negative result ("positive modulo").
Definition: fx_stats_util.cc:63