#anyone good with math

1 messages · Page 1 of 1 (latest)

atomic spear
#

kinda```lua
-- able to compute down to 2e18 for the math to handle BN to OrderedDataStore
function Bn.lbencode(val: any): number
val = Bn.convert(val)
local man, exp = val.man, val.exp
if man == 0 then return 4e18 end
local sign = (man < 0) and -1 or 1
man = math.abs(man)
if exp < 15 then
return sign * math.floor(man * 10^exp + 0.5)
end
local scale = 1e16 / 308
local encoded = sign * (math.log10(exp+1) * scale + math.log10(man) * 1e6)
return math.abs(encoded)
end

function Bn.lbdecode(val: number): BN
if val == 4e18 then return zero end
local sign = (val < 0) and -1 or 1
val = math.abs(val)
if val < 1e15 then
local exp = math.floor(math.log10(val))
local man = val / 10^exp
return Bn.new(man * sign, exp)
end
local scale = 1e16 / 308
local manLog = val % 1e6
local expLog = (val - manLog) / scale
local exp = 10^expLog-1
local man = 10^(manLog/1e6)
return {man = man * sign, exp = exp}
end

#

so basically
'1e1e200' shows
3.2e1e200 but im trying to show it as 1e1e200
then encode and decode but once after encode it does it like that then in decode doenst match up

#

same with smth like 1e308

#

since 1e308 in .short is 100UCe

#

try the module and do a loop like lua local Bnum = require(script.Bnum) local newBN = Bnum.new(1, 3) while task.wait(0.5) do local mul = Bnum.mul(newBN, 1e3) newBN = Bnum.toStr(mul) local encode = Bnum.lbencode(newBN) local decode = Bnum.lbdecode(encode) print('Encoded to:', Bnum.toStr(Bnum.convert(encode))) print('Decoded to:', Bnum.toHyperE(decode)) end

atomic spear
#

Like if I didn’t math.log10(exp)
It will be way over 1e308 for the encode that’s why I’m doing math.log10(exp+1) to make sure that it won’t get to 9.22e18 in encode

lunar parcel
#

ONE BANANA

#

TWO BANANA

#

THREE BANANAF

#

FOUR BANANAF

#

FIVE BANANAS

#

SIX BANANAS

#

SEVEN BANANA

#

EIGHT BANANA

#

NINE BANANA

#

TEN BANANANyo wtf