* the last number a_n was replaced by b) may be computed in O(1) time in terms
* of n, q, a_n, b, and S as
*
- * q' = q + d * s - (2 * S + d) * d / n,
+ * q' = q + d * s - (2 * S + d) * d / n
+ * = q + d * (s - 2 * S / n - d /n),
*
* where d = b - a_n, and s = b + a_n.
*
{
int64_t delta = new_val - old_val;
int64_t sigma = new_val + old_val;
- return old_qd + delta * sigma - (2 * old_sum + delta) * delta / n;
+ return old_qd + delta * (sigma - 2 * old_sum / n - delta / n);
}
static int update_afs_statistics(struct afs_info *old_afsi, struct afs_info *new_afsi)