Doing math with arbitrarily large numbers (EternityNum2)

If you have ever felt that 1.79e308 just isn’t a large enough upper limit for numbers in your game, then this tutorial is for you!

EternityNum2 is a module created by FoundForces that can calculate values up to image with the power of strings, and I am going to teach you how to start using it.

Setting it up :
  1. Download the model here, and place it in ReplicatedStorage.
    image

  2. Now, create a script anywhere. I will be placing a LocalScript under StarterPlayerScripts. Require the module, and you can now start working!

How to work with it :

If you have ever used BigInteger in Java, or even written excel formulas, the logic is very similar in EternityNum. While we usually write 10 + 3 * 2, in EternityNum we will write add(10, mul(3, 2)) The innermost operations are calculated first.

A list of all EternityNum operations can be found at the top of the module.

So let’s try solving 10 * ((9 / 2) ^ 100)

  1. Start with the innermost operation and work outwards, 9 / 2: div(9, 2)
  2. The next innermost operation is x ^ 100: pow(div(9, 2), 100)
  3. The only operation left is 10 * x: mul(10, pow(div(9, 2), 100))

In EternityNum, this looks like:

I added the original equation so that we can compare answers. Let’s try running this and see if our code is right!

image
Woah, whats with this table :thinking:? Explanation: This is just how EternityNum stores numbers! Here is what it means: Sign: Indicates whether the number is positive (1), negative (-1), or zero (0). Layer: Determines the logarithmic layer. If it is 1, we use log10(x); if 2, we use log10(log10(x)), and so on. Exp: The result of the logarithmic operation. For example, given the table [66.3, 1, 1]: The sign value (1) means the number is positive. The layer value (1) indicates we are using log10(x) The exp value (66.3) represents log10(x) = 66.3. To find the real value, solve 1066.3

Lets convert this table into a nicer format for our eyes. Wrap the equation in etNum.toScientific(), this converts the table into scientific notation.

image

Perfect!

Application of it :

Now, I want you to script a use case for this. We have not nearly hit the numerical limits yet!
Create a ScreenGui with a TextButton under it, and under this TextButton, make a new StringValue, and set it’s value to 1. This will hold the value of the button.

When the button is clicked, I want you to multiply its value by 1000, and display the new value in the button. Tip: to store an EternityNum value in a string value, you will need to use the function toString() I would also recommend using the function short() to turn the value into a nice suffixed format.

Solution:

local etNum = require(game.ReplicatedStorage.Modules.EternityNum)
local playerGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local textButton = playerGui:WaitForChild("TextButton")

local function multiplyNumberBy1000(number)
	return etNum.mul(number, 1000)
end

textButton.MouseButton1Click:Connect(function()
	textButton.Value.Value = etNum.toString(multiplyNumberBy1000(textButton.Value.Value))
	textButton.Text = etNum.short(textButton.Value.Value)
end)

Image from Gyazo

If you have made it here, great job, and thank you for reading! You now know enough to figure out every other facet of EternityNum on your own. But continue reading the next section if you would like!

Additional stuff :
  1. To store an EternityNum value in datastore, I recommend using toString()
  2. You can display your numbers in several different formats, I prefer toScientific() and short()
  3. To compare EternityNum values, use
    me(x, y) (x > y)
    meeq(x, y) (x >= y)
    le(x, y) (x < y)
    leeq(x, y) (x <= y)
    eq(x, y) (x == y)
    between(val, x, y) (x < val < y)
  4. Most functions are versatile in their accepted inputs. They will accept EternityNum tables, regular numbers, and numbers as strings ("10", "1e3", "1e-4", "1;54.3").

If you have any questions, feel free to reply. This is my first tutorial, and I hope it will help some of you who were as confused as I was when I first tried using this module.

What could this be practically used for? I can’t think of anything.

Seems like this is a reuploaded version of EternityNum 1, I don’t know much about it since I personally use EternityNum 2 and I think the new one should be used instead.

1 Like

Sorry I did not know EternityNum 2 existed, I can update my tutorial to use that instead.

1 Like

I use it in button simulators, but it can be used in incremental games where numbers quickly get large, and even some tycoon games may need it. But a large number library has many other uses outside of game development as well.

1 Like

In these contexts you don’t need to deal with these big numbers. You can have more efficient solutions that are suited to the problem.

1 Like

Bigger numbers = More fun, that is the major selling point of a lot of incremental games, to make big numbers.

2 Likes

Some people want undecillions of dollars