Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

integer division properties

does the following integer arithmetic property hold?

(m/n)/l == m/(n*l)

At first I thought I knew answer (does not hold), but now am not sure. Does it hold for all numbers or only for certain conditions, i.e. n > l?

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

like image 879
Anycorn Avatar asked Apr 14 '10 02:04

Anycorn


People also ask

What are the properties of Division?

Let us look at the properties of division of integers. When an integer 'x' is divided by another integer 'y', the integer 'x' is divided into 'y' number of equal parts. If 'y' divides 'x' without any remainder, then 'x' is evenly divisible by 'y'.

What are the dividing integers properties?

With the Dividing Integers Properties, you can easily simplify and answer the series of operations. Refer to various properties of the division of integers and apply them while solving the problems. Scroll to the below sections to know more details regarding the division of integer properties.

What is the closure property of integer division?

Closure Under Division Property Generally, the closure property is, if there are 2 integers, then the addition or subtraction of those integer results in an integer. But integers division does not follow closure property.

What is an example of division of integers?

Example 2: 6 × 9 = 54 ; (–5) × (3) = −15, which are integers. Division of integers doesn’t follow the closure property, i.e. the quotient of any two integers x and y, may or may not be an integer. Example 3: (−3) ÷ (−6) = ½, is not an integer.


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)
like image 60
zs2020 Avatar answered Sep 19 '22 09:09

zs2020


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

The two equations are identical with mathematical integers, but the two functions have different overflow behaviors if you are using fixed-width integers.

For example, suppose integers are 32-bit

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

However, 65536 * 65537 will overflow a 32-bit integer, and will equal 65536, so

1310720000/(65536*65537) = 1310720000/65536 = 20000
like image 35
Chi Avatar answered Sep 19 '22 09:09

Chi