MCPcopy
hub / github.com/grafana/tempo / add

Method add

pkg/traceql/engine_metrics_average.go:179–197  ·  view source on GitHub ↗

Adds an increment to the existing mean using Kahan sumnmation algorithm. The compensation is accumulated and not applied to reduce the error

(inc float64)

Source from the content-addressed store, hash-verified

177// Adds an increment to the existing mean using Kahan sumnmation algorithm.
178// The compensation is accumulated and not applied to reduce the error
179func (a *averageValue) add(inc float64) {
180 if math.IsInf(a.mean, 0) {
181 if math.IsInf(inc, 0) && (a.mean > 0) == (inc > 0) {
182 // The `mean` and `ic` values are `Inf` of the same sign. They
183 // can't be subtracted, but the value of `mean` is correct
184 // already.
185 return
186 }
187 if !math.IsInf(inc, 0) && !math.IsNaN(inc) {
188 // At this stage, the mean is an infinite. If the added
189 // value is neither an Inf or a Nan, we can keep that mean
190 // value.
191 return
192 }
193 }
194 val, c := kahanSumInc(inc, a.mean, a.compensation)
195 a.mean = val
196 a.compensation = c
197}
198
199type averageSeries struct {
200 values []averageValue

Callers 2

addIncrementMeanMethod · 0.45
addWeigthedMeanMethod · 0.45

Calls 1

kahanSumIncFunction · 0.85

Tested by

no test coverage detected