To do rounding up in truncating arithmetic, simply add (denom-1)
to the numerator.
Example, rounding down:
N/2
M/5
K/16
Example, rounding up:
(N+1)/2
(M+4)/5
(K+15)/16
To do round-to-nearest, add (denom/2)
to the numerator (halves will round up):
(N+1)/2
(M+2)/5
(K+8)/16
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…