So I have been wanting to create a system where I can create arbitrarily large numbers exceeding the number limit (about 1.6e+308) with two variables: a base and an exponent.
The base would act as a number from (0, 10), or in other words, a number that is anywhere between 0 to 10. The exponent would act as the exponent, of course. This system could theoretically produce numbers as large as 1 + 1e+308 which is stupendously large and more than anyone would ever need.
Example:
local base = 3.25
-- base is a number that is between 0 and 10
local exponent = 36
-- 3.25e+36
base = 9.6
exponent = 3e+16
-- 9.6e+32000000000000000
-- HUGE NUMBER, most likely won't go this high
Now, this is easy enough: just adjust exponent accordingly dependent on base.
The problem occurs when I attempt to make a function for adding these numbers:
local function Add(n1, n2)
-- string inputs
-- string.split function goes here to separate base and exponent
-- code that does stuff, this is the part I don't know
end
Add(2.5e+47, 3e+48) -- identical to 2.5e+47 + 3e+48
-- returns 3.25e+48
Is this a practical method of making a number system, or should I just use a library that handles it for me? I tried using BigNum, but the most it can handle for my tastes is somewhere around 1e+1200, which is large, but not large enough
If this is practical, how would I go about creating the necessary functions such as multiplication, division, and exponentiation? It is confusing me a lot, haha. Any pointers would be appreciated, I don’t expect my code to be written for me.
EDIT: Additionally, would it be a smart idea to use string functions to separate the +e from the numbers, i.e., 6e+56 = 6 and 56. This isn’t necessary, but it would make things simpler.