X
X

Integer division

The new intdiv function allows us to do integer divisions and return the amount of successful divides. For example a we could have 10 integer divide by 3. Well we know that three doesn’t go into ten exactly, but we can do some divisions here. So in this case 10 integer divide by 3 would return 3…

3 x 3 = 9

We can successfully have 3 divisions of 3 until we run out leaving us a remainder of one. So unlike a regular divide which would return a floating point recursive number…

3.3333333333...

… Instead using integer divide we get 3 returned it’s not interested in fractional or decimal numbers. Also please do note this is integer divide, floating point numbers will be converted into integers when passed to the intdiv function for example…

intdiv( 10.67 , 3.22  )

… Would give the same result as…

intdiv( 10 , 3  )

It doesn’t round the parameters 10.67 and 3.22 at all; it simply removes the decimal place and all fractional numbers turning 10.67 into 10 and turning 3.22 into 3. Then it will do the division process and give you the answer of the amount of successful whole divisions it managed to do.

This is a simple feature and is quite useful when wanting to do simple whole integer divisions and if passed floating point numbers it’ll change them into integers to prevent errors.

Latest Posts