in algebird-core/src/main/scala/com/twitter/algebird/MomentsGroup.scala [324:335]
def getCombinedMean(n: Long, an: Double, k: Long, ak: Double): Double =
if (n < k) getCombinedMean(k, ak, n, an)
else
(n + k) match {
case 0L => 0.0
case newCount if newCount == n => an
case newCount =>
val scaling = k.toDouble / newCount
// a_n + (a_k - a_n)*(k/(n+k)) is only stable if n is not approximately k
if (scaling < STABILITY_CONSTANT) an + (ak - an) * scaling
else (n * an + k * ak) / newCount
}