-
-
Save MikuAuahDark/257a763f43efd00012a9afbe65932770 to your computer and use it in GitHub Desktop.
32-bit unsigned integer multiplication in Lua
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 dwordMultiply(a, b) | |
a = a % 4294967296 | |
b = b % 4294967296 | |
local ah, al = math.floor(a / 65536), a % 65536 | |
local bh, bl = math.floor(b / 65536), b % 65536 | |
local high = ((ah * bl) + (al * bh)) % 65536 | |
return ((high * 65536) + (al * bl)) % 4294967296 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment