Assume alignment a
---(k-1)a-----------x--------------ka--------- <----r----><-----(ar)--->
where k is an integer (therefore ka is a multiple of alignment)
First find the rest
r = x%a
then increment x to the next edge
y = x + (ar)
But if r = 0, then y = x
So finally
r = x%a; y = r? x + (a - r) : x;
source share