Adds an increment to the existing mean using Kahan sumnmation algorithm. The compensation is accumulated and not applied to reduce the error
(inc float64)
| 177 | // Adds an increment to the existing mean using Kahan sumnmation algorithm. |
| 178 | // The compensation is accumulated and not applied to reduce the error |
| 179 | func (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 | |
| 199 | type averageSeries struct { |
| 200 | values []averageValue |
no test coverage detected