Created
March 12, 2019 18:18
-
-
Save gabyfle/5abeea2890adb613d57432bf18bbf577 to your computer and use it in GitHub Desktop.
Lua integer division with rest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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