(a * b) / c MulDiv and dealing with overflow from intermediate multiplication
问题 I need to do the following arithmetic: long a,b,c; long result = a*b/c; While the result is guaranteed to fit in long , the multiplication is not, so it can overflow. I tried to do it step by step (first multiply and then divide) while dealing with the overflow by splitting the intermediate result of a*b into an int array in size of max 4 ( much like the BigInteger is using its int[] mag variable). Here I got stuck with the division. I cannot get my head around the bitwise shifts required to