303. round_ties_even — round() Pushes Every Half Up, and Your Totals Drift
round() sends every .5 away from zero — so summing rounded values drifts upward. round_ties_even rounds ties to the even neighbor and the bias cancels out.
Round a batch of exact midpoints with round() and watch the total inflate:
| |
round() uses “half away from zero”: every tie moves in the same direction, so the errors all point the same way and accumulate. round_ties_even — banker’s rounding — sends ties to whichever neighbor is even, so roughly half go down and half go up:
| |
Only exact ties behave differently — 2.4999 and 2.5001 round the same either way:
| |
This is the rounding mode IEEE 754 uses by default for a reason: it’s statistically unbiased over many operations. It’s also what Python’s built-in round does — if a value “rounds wrong” when porting Python code to Rust, this is why. Stable since Rust 1.77.