Fix truncation due to integer division

Found by Michael Niedermayer.

(cherry picked from commit 4d1529dd2d6af2632bcffa91dca29113422a489c)