Skip to content
This repository was archived by the owner on Jan 29, 2018. It is now read-only.

Commit 58a73e5

Browse files
committed
more shit
1 parent 00da671 commit 58a73e5

File tree

6 files changed

+1062
-162
lines changed

6 files changed

+1062
-162
lines changed

src/BitInt.lua

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
repeat wait() until _G.BU ~= nil
2+
BitInt = _G.BU
3+
4+
BitInt = {bits = 0, number="", dec=0}
5+
6+
function check(num1, num2)
7+
if num1.bits < num2.bits then
8+
error("Bit overflow!")
9+
end
10+
end
11+
12+
function BitInt.inherit(bits, number) -- Expects binary if string.
13+
if type(number) == "number" then
14+
15+
if(not bits) then
16+
bits = _G.BU.Log2(number)
17+
end
18+
if BU.Log2(number) > bits then
19+
error("Bit overflow!")
20+
end
21+
bin = _G.BU.Dec2Bin(number, bits)
22+
dec = _G.BU.Bin2Dec(number, bits)
23+
24+
elseif type(bit) == "string" then bits = number:len()
25+
else error("Not very descriptive error, just to make you mad.") end
26+
27+
o = setmetatable({"isabitint", bits = bits, number = bin, dec = dec }, {__index = BitInt}) -- Don't change the first argument.
28+
return o
29+
end
30+
31+
function BitInt.clonebitwidth(constrainedint)
32+
return BitInt.inherit(constrainedint.bit, 0)
33+
end
34+
35+
setmetatable(BitInt, { -- KEEP number IN BINARY!
36+
__add = function(num, num2) check(num,num2) return BitInt.inherit(false, tonumber(_G.BU.Bin2Dec(num.number))+tonumber(_G.BU.Bin2Dec(num2.number))) end,
37+
__sub = function(num, num2) check(num,num2) return BitInt.inherit(false, tonumber(_G.BU.Bin2Dec(num.number))-tonumber(_G.BU.Bin2Dec(num2.number))) end,
38+
__mul = function(num, num2) check(num,num2) return BitInt.inherit(false, tonumber(_G.BU.Bin2Dec(num.number))*tonumber(_G.BU.Bin2Dec(num2.number))) end,
39+
--__mod = function(num, num2) check(num,num2) return tonumber(Bin2Dec(num.number))%tonumber(Bin2Dec(num2.number)) end, nawh man
40+
__equ = function(num, num2) check(num,num2) if _G.BU.Bin2Dec(num.number) == _G.BU.Bin2Dec(num2.number) then return true end end,
41+
--__concat = function(num, num2) check(num,num2) num.number = num2.number end, -- (Could be) used like the equals sign.})
42+
43+
_G.BitInt = BitInt
44+
return BitInt

0 commit comments

Comments
 (0)