Multiply, do not divide
transcript
A fast average and a slow average. Is the fast one above the slow one? Be exact.
The fast window sums to seven. It holds two prices. The slow window sums to ten over three.
The true averages are different. Three and a half beats three and a third. Whole-number division floors both to three.
Multiply the fast sum by the slow count. Multiply the slow sum by the fast count. Twenty-one is greater than twenty.
It is the same as comparing the fractions. Every value stays a whole number. So nothing is rounded.
Multiplying makes bigger numbers. They can pass two billion. So use sixty-four bits.
Take the prices three, two, five, two and eight. The fast window is two days, the slow window three. Whole division finds zero days where the fast average wins. Multiplying finds two.
Sometimes the two averages are exactly equal. The statement counts only strictly above. So use a strict greater-than test.
Never divide to compare. Equal averages do not count. Full breakdown in the lecture.