InfiniteMath is a module that allows you to surpass the double-precision floating-point number limit
1 * 10^308 / 1e+308
Here is a showcase video.
Explanation.
InfiniteMath’s limit is 10^^308 / 1e+1e+308
, or 1 with 10^308
zeros.
This is achieved by cleverly storing the coefficient and exponent of the number separated. If we take for example 1500
, the coefficient is 1.5
, and the exponent is 3
.
1500
is 1.5 * 10^3
, so our table will be {1.5, 3}
.
We can do math with these 2 numbers always being separate, meaning we’ll never actually be storing 10^308
even if we mathematically have 10^308
or go beyond it.
InfiniteMath uses metamethods, meaning you can do arithmetic +, -, *, /, ^, %
and comparison
<, >, <=, >=, ==, ~=
without needing to call functions.
All you need to do is use InfiniteMath.new(num)
and you’re done. You can do arithmetic with constructed numbers and normal numbers together, meaning
InfiniteMath.new(1) + 1
Will return 2
.
InfiniteMath.new({1, 1000}) ^ 100
Will return 1e+100000
You can use GetSuffix()
up to 1e+12000
or ScientificNotation()
to format the number.
InfiniteMath.new(1000):GetSuffix()
is "1K"
But why?
You may be wondering why you would ever need to go this high with numbers? Well simulators and tycoons can benefit from this, an example being Miner’s Haven.
Miner’s Haven is a sandbox tycoon about making as much money as possible, however in end-game you can hit the number limit in a matter of minutes. Miner’s Haven would benefit greatly from increasing the number limit to further progression, which they already plan on doing themselves.
Why InfiniteMath?
Other modules exist that are capable of doing this, so why would you use InfiniteMath?
One module is OmegaNum, but the source code is an absolute mess, and doesn’t use metamethods, meaning you need to do OmegaNum.add()
instead of just using +
. OmegaNum does have a larger limit, but the implementation is much worse and I believe 10^^308 is enough.
Another module is EternityNum, but it doesn’t have support for OrderedDataStores, and the creator has recommended to not use it as “this one, while usable, doesn’t feel that great to use.”
Contribute and Documentation
If you want to contribute, I have a GitHub where you can make issues and pull requests. There is also a documentation website for more info.
Get it for yourself!
I have made an uncopylocked game if you would like to see how this would be used in an actual game. It’s a simple idle game with a global cash leaderboard, it’s balanced so that you can break 1e+308
in a few minutes.
You can get the module here!
If you use InfiniteMath in your game, reply with a link to your game and I’ll add it to a section of games using the module.