Integer Division Properties

is the following integer arithmetic property satisfied?

(m/n)/l == m/(n*l) 
At first I thought I knew the answer (I can’t hold it), but now I’m not sure. Whether it is saved for all numbers or only for certain conditions, i.e. n > l ?

the question relates to computer arithmetic, namely q = n/m, q*m != n , ignoring overflow.

+7
algorithm integer theory division
Apr 14 2018-10-14T00:
source share
2 answers
 Case1 assume m = kn+b (b<n), left = (m/n)/l = ((kn+b)/n)/l = (k+b/n)/l = k/l (b/n=0, because b<n) right = (kn+b)/(n*l) = k/l + b/(n*l) = k/l (b/(n*l)=0, because b<n) => left = right Case2 assume m = kn, left = (m/n)/l = (kn/n)/l = k/l right = kn/(n*l) = k/l => left = right So, (m/n)/l == m/(n*l) 
+12
Apr 14 2018-10-14T00:
source share

Are you talking about mathematical integers? Or fixed-width integers in a programming language?

Both equations are identical to mathematical integers, but the two functions have different types of overflow if you use fixed-width integers.

For example, suppose integers are 32-bit

 (1310720000/65536)/65537 = 20000/65537 = 0 

However, 65536 * 65537 overflows with a 32-bit integer and will be equal to 65536, therefore

 1310720000/(65536*65537) = 1310720000/65536 = 20000 
+5
Apr 14 2018-10-10T00:
source share



All Articles