I use a combination of modulus to nullify the addition of the remainder if x
is already a multiple:
int round_up(int x, int div)
{
return x + (div - x % div) % div;
}
We find the inverse of the remainder then modulus that with the divisor again to nullify it if it is the divisor itself then add x
.
round_up(19, 3) = 21