So i wanna try something basically i want to make an integer system that you can decrease,increase,compare,multiply and divide using string.
the reason is to bypass math.huge() with 100% accuracy.
i have one working right now, but im kinda stuck on divide part
for multiply its pretty easy all i need to do is to call the add function multiple times
but for division i dont know how to do it.
How it work?
Basically it converts the string to integer string (lol)
something like this :
local val = "5"
local val2 = "10"
first it convert the value to something like this
local val = "05"
local val2 = "10"
then convert them to tables like this
local val = {"0" , "5"}
local val2 = {"1" , "0"}
then just loop through the table and convert it to number and do some math stuff after that
that way it can bypass math.huge()
Script
local val = "1000"
local b = "259"
local function convert(a,b)
local lengthA = string.len(a)
local lengthB = string.len(b)
if lengthA > lengthB then
local difference = lengthA - lengthB
local newB = ""
for i = 1,difference do
newB = newB.."0"
end
newB = newB..b
b = newB
else
local difference = lengthB - lengthA
local newA = ""
for i = 1,difference do
newA = newA.."0"
end
newA = newA..a
a = newA
end
return a,b
end
local function add(a,b)
local result = ""
local increaseNum = 0
local na,nb = convert(a,b)
na = string.reverse(na)
nb = string.reverse(nb)
local splitA,splitB = string.split(na,""),string.split(nb,"")
for i,v in pairs(splitA) do
local number = 0
local num = tonumber(v)
local numB = tonumber(splitB[i])
if num and numB then
if i == #splitA then
number = num + numB + increaseNum
result = tostring(number)..result
print("breaking on "..number)
break
end
local addition = num + numB + increaseNum
print("addition is "..addition)
if addition > 9 then
local ts = tostring(addition)
local tab = string.split(ts,"")
number = tonumber(tab[#tab])
print("number is "..tab[#tab])
local icn = ""
for i,v in pairs(tab) do
if i ~= #tab then
icn = icn..v
end
end
increaseNum = tonumber(icn)
else
number = addition
increaseNum = 0
end
end
if number then
result = tostring(number)..result
end
end
return result
end
local function decrease(a,b)
local result = ""
local na,nb = convert(a,b)
na = string.reverse(na)
nb = string.reverse(nb)
local splitA,splitB = string.split(na,""),string.split(nb,"")
for i,v in pairs(splitA) do
local number = 0
local nex = splitA[i + 1]
local compareVal = splitB[i]
local num,numB
local numC = tonumber(splitB[i])
if nex then
num,numB = tonumber(v),tonumber(nex)
if (num - numC) < 0 then
numB -= 1
number = (num + 10) - numC
splitA[i + 1] = tostring(numB)
else
number = num - numC
end
else
num = tonumber(v)
number = num - numC
end
if number then
if i == #splitA then
if number ~= 0 then
result = tostring(number)..result
end
else
result = tostring(number)..result
end
end
end
return result
end
local function isMoreThan(a,b)
local result = ""
local na,nb = convert(a,b)
local splitA,splitB = string.split(na,""),string.split(nb,"")
for i,v in pairs(splitA) do
local num,numB = tonumber(v),tonumber(splitB[i])
if num and numB then
if num > numB then
return true
end
end
end
return false
end
local function isLessThan(a,b)
local result = ""
local na,nb = convert(a,b)
local splitA,splitB = string.split(na,""),string.split(nb,"")
for i,v in pairs(splitA) do
local num,numB = tonumber(v),tonumber(splitB[i])
if num and numB then
if num < numB then
return true
end
end
end
return false
end
print(decrease(val,b))