Integer division truncates towards zero. Assuming (from the name of the macro, idiv) your arguments are of integer type, ((a)/(b) + 0.5)
would be truncated before you got to the + 0.5
, so you would always round down regardless.
(((a) + (b) / 2) / (b))
rounds up results greater than x.5, without using floating-point arithmetics.
Note: You tagged your question C++. In C++, you shouldn't "macro" anything, really. Check Marek's answer for a template solution (but also the caveat that it doesn't really work for negative values).