I am dealing with a large distribution of values. In your mean calculation here total overflows because you keep adding without keeping it down. May I suggest to use a running mean? Because this is anyway an approximate mean, the rounding error that occurs should be negligible.
// Mean returns the approximate arithmetic mean of the recorded values.
func (h *Histogram) Mean() float64 {
if h.totalCount == 0 {
return 0
}
var total int64
i := h.iterator()
for i.next() {
if i.countAtIdx != 0 {
total += i.countAtIdx * h.medianEquivalentValue(i.valueFromIdx)
}
}
return float64(total) / float64(h.totalCount)
}
I am dealing with a large distribution of values. In your mean calculation here
total
overflows because you keep adding without keeping it down. May I suggest to use a running mean? Because this is anyway an approximate mean, the rounding error that occurs should be negligible.