Skip to content

Instantly share code, notes, and snippets.

@gabyfle
Created March 12, 2019 18:18
Show Gist options
  • Save gabyfle/5abeea2890adb613d57432bf18bbf577 to your computer and use it in GitHub Desktop.
Save gabyfle/5abeea2890adb613d57432bf18bbf577 to your computer and use it in GitHub Desktop.
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
end
return quotient, rest
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment