I m trying to avoid long long
s and integer overflow in some calculations, so I came up with the function below to calculate (a * b) / c
(order is important due to truncating integer division).
unsigned muldiv(unsigned a, unsigned b, unsigned c)
{
return a * (b / c) + (a * (b % c)) / c;
}
是否有任何最优的案例,这些案例会像预期的那样赢得工作?