Simplify the weighted average computation
As per #19, this patch just makes it so that `(w1 + w2)` doesn't get repeated in the denominator.
- Id
- 487d789a7ba1839bd21a974139323f538c1d45e3
- Author
- Caio
- Commit time
- 2018-07-31T17:49:01+02:00
Modified tdigest.go
if x1 > x2 {
x1, x2, w1, w2 = x2, x1, w2, w1
}
- result := x1*w1/(w1+w2) + x2*w2/(w1+w2)
+ result := (x1*w1 + x2*w2) / (w1 + w2)
return math.Max(x1, math.Min(result, x2))
}