Is there any reason for this to be unsigned, given that `i` is signed? I believe it's correct as is, but I had to think carefully to make sure that the `MIN(...)` expressions below could never be negative, which because of the mixed unsigned/signed comparison would be promoted to a large positive value...