In this case the order of operations dictates that the expression be evaluated as:Very often I want to do a calculation such as:
R = A / B * C;
Assume that all variables are 16-bit unsigned integers and values do not result in overflows.
I want to make sure that I get the best precision in the result R.
Since I have no idea how the compile will choose the order of operations, I force the compiler to do it in the manner I want.
Hence I would break up the calculation as follows.
R = A * C;
R = R / B;
To be honest, I don't even know if doing this is necessary or what would an optimizing compiler choose to do. The only way to find out is to look at the ASM code generated by the compiler. Time to go check this out.
R = (A / B) * C;
Since / and * are of the same precedence and left associative.
So if you want it to evaluate it as (A * C) / B, then just do:
R = A * C / B;
Either way you have some concerns. With A/B first you have the potential for round off issues, with A*C first you have potential issues with overflow.