Skip to content

Instantly share code, notes, and snippets.

@MikuAuahDark
Created December 17, 2018 12:07
Show Gist options
  • Save MikuAuahDark/257a763f43efd00012a9afbe65932770 to your computer and use it in GitHub Desktop.
Save MikuAuahDark/257a763f43efd00012a9afbe65932770 to your computer and use it in GitHub Desktop.
32-bit unsigned integer multiplication in Lua
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