-- made by idontthinkofacool
--BigNum mode in EternityNum. Used for <10^10^308 accurate calculation.
local xN = {}
function xN.short(bnum)
bnum = xN.errorcorrection(bnum)
local SNumber = bnum[2]
local SNumber1 = bnum[1]
local leftover = math.fmod(SNumber, 3)
SNumber = math.floor(SNumber / 3)
SNumber = SNumber - 1
if SNumber <= -1 then
return math.floor(xN.bnumtofloat(bnum) * 100) / 100
end
local FirstOnes = {"", "U","D","T","Qd","Qn","Sx","Sp","Oc","No"}
local SecondOnes = {"", "De","Vt","Tg","qg","Qg","sg","Sg","Og","Ng"}
local ThirdOnes = {"", "Ce", "Du","Tr","Qa","Qi","Se","Si","Ot","Ni"}
local MultOnes = {"", "Mi","Mc","Na","Pi","Fm","At","Zp","Yc", "Xo", "Ve", "Me", "Due", "Tre", "Te", "Pt", "He", "Hp", "Oct", "En", "Ic", "Mei", "Dui", "Tri", "Teti", "Pti", "Hei", "Hp", "Oci", "Eni", "Tra","TeC","MTc","DTc","TrTc","TeTc","PeTc","HTc","HpT","OcT","EnT","TetC","MTetc","DTetc","TrTetc","TeTetc","PeTetc","HTetc","HpTetc","OcTetc","EnTetc","PcT","MPcT","DPcT","TPCt","TePCt","PePCt","HePCt","HpPct","OcPct","EnPct","HCt","MHcT","DHcT","THCt","TeHCt","PeHCt","HeHCt","HpHct","OcHct","EnHct","HpCt","MHpcT","DHpcT","THpCt","TeHpCt","PeHpCt","HeHpCt","HpHpct","OcHpct","EnHpct","OCt","MOcT","DOcT","TOCt","TeOCt","PeOCt","HeOCt","HpOct","OcOct","EnOct","Ent","MEnT","DEnT","TEnt","TeEnt","PeEnt","HeEnt","HpEnt","OcEnt","EnEnt","Hect", "MeHect"}
if bnum[2] == 1/0 then
if bnum[1] < 0 then
return "-Infinity"
else
return "Infinity"
end
end
-- suffix part
if SNumber == 0 then
return math.floor(SNumber1 * 10^leftover * 100)/100 .. "k"
elseif SNumber == 1 then
return math.floor(SNumber1 * 10^leftover * 100)/100 .. "M"
elseif SNumber == 2 then
return math.floor(SNumber1 * 10^leftover * 100)/100 .. "B"
end
local txt = ""
local function suffixpart(n)
local Hundreds = math.floor(n/100)
n = math.fmod(n, 100)
local Tens = math.floor(n/10)
n = math.fmod(n, 10)
local Ones = math.floor(n/1)
txt = txt .. FirstOnes[Ones + 1]
txt = txt .. SecondOnes[Tens + 1]
txt = txt .. ThirdOnes[Hundreds + 1]
end
local function suffixpart2(n)
if n > 0 then
n = n + 1
end
if n > 1000 then
n = math.fmod(n, 1000)
end
local Hundreds = math.floor(n/100)
n = math.fmod(n, 100)
local Tens = math.floor(n/10)
n = math.fmod(n, 10)
local Ones = math.floor(n/1)
txt = txt .. FirstOnes[Ones + 1]
txt = txt .. SecondOnes[Tens + 1]
txt = txt .. ThirdOnes[Hundreds + 1]
end
if SNumber < 1000 then
suffixpart(SNumber)
return math.floor(SNumber1 * 10^leftover * 100)/100 .. txt
end
for i=#MultOnes,0,-1 do
if SNumber >= 10^(i*3) then
suffixpart2(math.floor(SNumber / 10^(i*3))- 1)
txt = txt .. MultOnes[i+1]
SNumber = math.fmod(SNumber, 10^(i*3))
end
end
return math.floor(SNumber1 * 10^leftover * 100)/100 .. txt
end
function xN.strtobnum(str)
local Synapse = string.find(str, "e")
return {tonumber(string.sub(str, 1, Synapse-1)), tonumber(string.sub(str, Synapse+1))}
end
function xN.bnumtofloat(bnum)
return tonumber(xN.bnumtostr(bnum))
end
function xN.convert(str)
if tonumber(str) == nil then
local V,Uw = pcall(function()
return xN.strtobnum(str)
end)
if V then
return xN.strtobnum(str)
else
return "0"
end
end
if type(str) == "number" then
if tonumber(str) == 1/0 or tonumber(str) == -1/0 then
return {1, 1.797693e308}
end
end
if tonumber(str) == 1/0 or tonumber(str) == -1/0 then
return xN.strtobnum(str)
elseif tostring(tonumber(str)) == "nil" then
return xN.strtobnum(str)
else
return xN.floattobnum(tonumber(str))
end
end
function xN.new(man,exp)
return {man, exp}
end
function xN.floattobnum(float)
local ZeN = tostring(float)
local Synapse = string.find(ZeN, "+")
if Synapse then
return xN.strtobnum(string.sub(ZeN, 1, Synapse-1) .. string.sub(ZeN, Synapse+1))
elseif string.find(ZeN, "e") then
return xN.strtobnum(ZeN)
else
return xN.errorcorrection(xN.strtobnum(ZeN .. "e0") )
end
end
function xN.bnumtostr(bnum)
return tostring(bnum[1]) .. "e" .. tostring(bnum[2])
end
function xN.errorcorrection(bnum)
local signal = "+"
if bnum[1] == 0 then
return {0, 0}
end
if bnum[1] < 0 then
signal = "-"
end
if signal == "-" then
bnum[1] = bnum[1] * -1
end
local signal2 = "+"
if bnum[2] < 0 then
signal2 = "-"
bnum[2] = bnum[2] * -1
end
if math.fmod(bnum[2], 1) > 0 and signal2 == "-" then
bnum[1] = bnum[1] * (10^ (1 - math.fmod(bnum[2], 1)))
bnum[2] = math.floor(bnum[2]) + 1
elseif math.fmod(bnum[2], 1) > 0 and signal2 == "+" then
bnum[1] = bnum[1] * (10^ math.fmod(bnum[2], 1))
bnum[2] = math.floor(bnum[2])
end
if signal2 == "-" then
bnum[2] = bnum[2] * -1
end
local DgAmo = math.log10(bnum[1])
DgAmo = math.floor(DgAmo)
bnum[1] = bnum[1] / 10^DgAmo
bnum[2] = bnum[2] + DgAmo
bnum[2] = math.floor(bnum[2])
if signal == "-" then
bnum[1] = bnum[1] * -1
end
return bnum
end
function xN.div(bnum1, bnum2)
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
local bnum3 = xN.new(0, 0)
bnum3[1] = bnum1[1] / bnum2[1]
bnum3[2] = bnum1[2] - bnum2[2]
bnum3 = xN.errorcorrection(bnum3)
return bnum3
end
function xN.mul(bnum1, bnum2)
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
local bnum3 = xN.new(0, 0)
bnum3[1] = bnum1[1] * bnum2[1]
bnum3[2] = bnum1[2] + bnum2[2]
bnum3 = xN.errorcorrection(bnum3)
return bnum3
end
function xN.log10(bnum)
local LogTen = bnum[2] + math.log10(bnum[1])
return xN.errorcorrection(xN.new(LogTen, 0))
end
function xN.eq(bnum1, bnum2)
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
if bnum1[1] == bnum2[1] then
if bnum1[2] == bnum2[2] then
return true
end
end
return false
end
function xN.le(bnum1, bnum2)
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
local signal = "+"
local signal2 = "+"
if bnum1[1] < 0 then
signal = "-"
end
if bnum2[1] < 0 then
signal2 = "-"
end
if signal == "+" and signal2 == "-" then
return false
elseif signal == "-" and signal2 == "+" then
return true
elseif signal == "-" and signal2 == "-" then
if bnum1[2] > bnum2[2] then
-- passed test 1.
return true
end
if bnum1[2] < bnum2[2] then
-- passed test 1.
return false
end
if bnum1[1] < bnum2[1] then
-- passed test 2.
return true
end
elseif signal == "+" and signal2 == "+" then
if bnum1[2] < bnum2[2] then
-- passed test 1.
return true
end
if bnum1[2] > bnum2[2] then
-- passed test 1.
return false
end
if bnum1[1] < bnum2[1] then
-- passed test 2.
return true
end
end
return false
end
function xN.me(bnum1, bnum2)
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
local signal = "+"
local signal2 = "+"
if bnum1[1] < 0 then
signal = "-"
end
if bnum2[1] < 0 then
signal2 = "-"
end
if signal == "+" and signal2 == "-" then
return true
elseif signal == "-" and signal2 == "+" then
return false
elseif signal == "-" and signal2 == "-" then
if bnum1[2] < bnum2[2] then
-- passed test 1.
return true
end
if bnum1[2] < bnum2[2] then
-- passed test 1.
return false
end
if bnum1[1] > bnum2[1] then
-- passed test 2.
return true
end
elseif signal == "+" and signal2 == "+" then
if bnum1[2] > bnum2[2] then
-- passed test 1.
return true
end
if bnum1[2] < bnum2[2] then
-- passed test 1.
return false
end
if bnum1[1] > bnum2[1] then
-- passed test 2.
return true
end
end
return false
end
function xN.leeq(bnum1, bnum2)
local Se1 = xN.eq(bnum1,bnum2)
local Se2 = xN.le(bnum1,bnum2)
if Se1 or Se2 then
return true
end
return false
end
function xN.meeq(bnum1, bnum2)
local Se1 = xN.eq(bnum1,bnum2)
local Se2 = xN.me(bnum1,bnum2)
if Se1 or Se2 then
return true
end
return false
end
function xN.add(bnum1, bnum2)
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
local bnum3 = xN.new(0,0)
local Diff = bnum2[2] - bnum1[2]
if Diff > 20 then
return bnum2
elseif Diff < - 20 then
return bnum1
else
bnum3[2] = bnum1[2]
bnum3[1] = bnum1[1] + (bnum2[1] * 10^Diff)
end
bnum3 = xN.errorcorrection(bnum3)
return bnum3
end
function xN.sub(bnum1, bnum2)
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
local bnum3 = xN.new(0,0)
local Diff = bnum2[2] - bnum1[2]
if Diff > 20 then
bnum3 = xN.new(bnum1[1] * -1, bnum2[2])
elseif Diff < - 20 then
return bnum1
else
bnum3[2] = bnum1[2]
bnum3[1] = bnum1[1] - (bnum2[1] * 10^Diff)
end
bnum3 = xN.errorcorrection(bnum3)
return bnum3
end
function xN.pow(bnum1, bnum2)
if bnum1[1] < 0 then
return {1, "Unsupported"}
end
if bnum1[1] == 0 and bnum2[2] == 0 then
warn("I agree that 0 ^ 0 is 0.5")
return {0.5, 0}
elseif bnum2[1] == 0 then
return {1, 0}
elseif bnum1[1] == 0 then
return {0, 0}
end
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
local bnum3 = {0, 0}
local N = xN.log10(bnum1)
N = xN.bnumtofloat(N)
N = N * xN.bnumtofloat(bnum2)
bnum3[2] = N
bnum3[1] = 1
return xN.errorcorrection(bnum3)
end
function xN.doublepow(bnum1, bnum2)
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
return xN.pow(bnum1, xN.pow(bnum2, bnum2))
end
function xN.sqrt(bnum1)
bnum1 = xN.errorcorrection(bnum1)
return xN.pow(bnum1, {5, -1})
end
function xN.pi()
return {3.141592653589793238462643383279502884197169399375105820974, 0}
end
function xN.e()
return {2.718281828459045235360287471352662497757247093699959574966, 0}
end
function xN.gr()
return {1.618033988749894848204586834365638117720309179805762862135, 0}
end
function xN.two()
return {2, 0}
end
function xN.ten()
return {1, 1}
end
function xN.logx(bnum1, bnum2)
local b = xN.bnumtofloat(bnum2)
local LogTen = bnum1[2] + math.log10(bnum1[1])
LogTen = LogTen / math.log10(b)
return xN.errorcorrection(xN.new(LogTen, 0))
end
function xN.log(bnum)
local b = xN.bnumtofloat(xN.e())
local LogTen = bnum[2] + math.log10(bnum[1])
LogTen = LogTen / math.log10(b)
return xN.errorcorrection(xN.new(LogTen, 0))
end
function xN.fact(bnum)
-- Estimated Error: (n+1) ^ 5
-- Computing LogTwo...
-- Currently In Beta
local TwoPin = xN.mul(xN.pi(), xN.two())
local res2 = xN.div({1/12, 0}, bnum)
local res3 = xN.div({1/360, 0}, xN.pow(bnum, {3, 0}))
-- Computing Res...
TwoPin = xN.mul(TwoPin, bnum)
TwoPin = xN.sqrt(TwoPin)
res2 = xN.sub(res2, res3)
res2 = xN.pow(xN.e(), res2)
res3 = xN.div(bnum, xN.e())
res3 = xN.pow(res3, bnum)
res3 = xN.mul(res3, TwoPin)
local Final = xN.mul(res2, res3)
if Final[2] <= -1 and Final[1] > 9.99 then
Final[2] = -1
elseif Final[2] <= -1 then
Final[2] = 0
end
return Final
end
function xN.gamma(bnum)
-- Estimated Error: (n+1) ^ 5
-- Computing LogTwo...
-- Currently In Beta
return xN.fact(xN.sub(bnum, {1, 0}))
end
function xN.doublefactOdd(bnum)
-- Estimated Error: (n+1) ^ 5
-- Computing LogTwo...
-- Currently In Beta
-- If Even then
if xN.eq(bnum, {1, 0}) then
return {1, 0}
end
return xN.mul(xN.sqrt(xN.div(xN.pow({2, 0}, xN.add(bnum, {1, 0})), xN.pi())), xN.fact(xN.div(bnum, xN.two())))
end
function xN.doublefactEven(bnum)
-- Estimated Error: (n+1) ^ 5
-- Computing LogTwo...
-- Currently In Beta
-- If Even then
local Num = xN.fact(xN.div(bnum, {2, 0}))
return xN.mul(xN.pow{2, xN.div(bnum, {2, 0})}, Num)
end
function xN.rand(bnum1, bnum2)
local Ye = xN.convert(math.random())
local bnum3 = xN.mul(Ye, xN.sub(bnum1, bnum2))
bnum3 = xN.add(bnum3, bnum2)
return bnum3
end
function xN.fmod(bnum1, bnum2)
-- To precisely do mod, you must get 64 things:
-- 1.
bnum1 = xN.errorcorrection(bnum1)
bnum2 = xN.errorcorrection(bnum2)
local MultiplyBy = bnum2
local origexp = bnum2[1]
local origtet = bnum2[2]
bnum2[2] = bnum1[2]
if bnum1[2] > bnum2[2] then
bnum2[2] = bnum1[2] - 1
end
local M = 0
repeat
local VT = xN.div(bnum1, bnum2)
VT = xN.floor(VT)
VT = xN.mul(VT, bnum2)
bnum1 = xN.sub(bnum1, VT)
bnum2[2] = bnum2[2] - 1
until xN.le(bnum1, {origexp, origtet})
if xN.eq(bnum1, xN.abs(bnum1)) then
else
return xN.fmod(xN.abs(bnum1), {origexp, origtet})
end
return bnum1
end
function xN.expoRand(bnum1, bnum2)
local Ye = xN.convert(xN.rand(xN.log10(bnum1),xN.log10(bnum2)))
local bnum3 = xN.pow(xN.ten(), Ye)
return bnum3
end
function xN.abs(bnum1)
return {math.abs(bnum1[1]), bnum1[2]}
end
function xN.between(bnum1, bnum2, bnum3)
return xN.leeq(bnum1, bnum3) and xN.meeq(bnum1, bnum2)
end
function xN.floor(bnum1)
if xN.meeq(bnum1, {1, 16}) or xN.leeq(bnum1, {-1, 16}) then
return bnum1
end
return xN.convert(math.floor(xN.bnumtofloat(bnum1)))
end
function xN.ceil(bnum2)
if xN.meeq(bnum2, {1, 16}) or xN.leeq(bnum2, {-1, 16}) then
return bnum2
end
return xN.convert(math.ceil(xN.bnumtofloat(bnum2)))
end
function xN.round(bnum2)
return xN.floor(xN.add(bnum2, {5, -1}))
end
function xN.shift(bnum2, digits)
--- digits must be float ---
return {math.floor(bnum2[1] * 10^digits) / 10^digits, bnum2[2]}
end
function xN.engineer(bnum)
if math.fmod(bnum[2], 3) ~= 0 then
local ree = bnum[2]
bnum[2] = bnum[2] - math.fmod(bnum[2], 3)
bnum[1] = bnum[1] * 10 ^ math.fmod(ree, 3)
return xN.bnumtostr(xN.shift(bnum,4))
end
return xN.bnumtostr(xN.shift(bnum,4))
end
-- Play Around Here --
To embed this project on your website, copy the following code and paste it into your website's HTML: