Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Lua integer division with rest
function integerDivision(dividend, divider)
if divider == 0 then error("Stupid! You can't divide by 0!") end
local rest = dividend
local quotient = 0
while rest >= divider do
dividend = dividend - divider
rest = dividend
quotient = quotient + 1
return quotient, rest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.