Overview
GammaNum is a number library that functions similar to EternityNum, but much faster. Both can handle numbers up to 10↑↑2^1024 or 10^10^...^10 with 1.79e308 10s. This module ranges from 30->100x faster than EternityNum, while keeping the exact same precision.Use Case
This module is made for incremental/simulator games that need to calculate numbers higher than doubles efficiently. GammaNum is much faster than alternatives like EternityNum, having performance on par or better than lower limit modules like BigNum, QubitNum, and InfiniteMath.Benchmark
This benchmark compares GammaNum to EternityNum ( left is GammaNum, right is EternityNum ).*operation is run 10,000 times to find approximate time in nanoseconds ( 1 billionth of a second )
GammaNum | EternityNum
- Addition: 40->70ns | 1600->1800ns
- Subtraction: 40->70ns | 3000->3400ns
- Multiplication: 40->75ns | 1600->3800ns
- Division: 40->75ns | 3200->5800ns
- Integer Division: 50->75ns | NF
- Power: 45->80ns | 4700->6900ns
- Root: 45->80ns | 6500->8500ns
- Logarithm: 45->55ns | 6200->6500ns
- Tetration: 40->1300ns | NF
- Gamma: 80->125ns | 2200->8600ns
NF = No Function, meaning there is no support for that operation
There are many more functions that this and a full function list is given at the top of the module.
Advantages
If speed alone doesn't convince you, there's a variety of QOL to make the process of using it as easy as possible. Metatables are off the table (and off the buffer), but I do have a pretty good solution, with functions like addeq() you can essentially perform += without any speed downsides, even making it about 20ns faster. This even exists for other functions like sub, mul, div, log, abs, etc.Example:
local gn = require(game.ReplicatedStorage.GammaNum)
local number1 = gn.fromNumber(5)
gn.addeq(number1, 1) -- takes approx. 20ns
print(gn.tostring(number1)) -- returns 6.000
--As opposed to:
local number2 = gn.fromNumber(5)
number2 = gn.add(number2, 1) -- takes approx. 40ns
print(gn.tostring(number2)) -- returns 6.000
Custom Functions
If you have a function you want to add for yourself I have a designated area for them and some examples to help you get started. Though if you have any additional questions feel free to ask.How it Works
Gammanum is a buffer of size 17, first byte is the sign, bytes 1->9 are the layer and the last 8 bytes are the exponent, so the value would be sign * (10↑↑layer)^exponent.Ranges
- sign = -1, 0, or 1 for negative, zero, and postive respectively
- layer >= 0, when layer = 0, exponent must be non-negative
- exponent is in range 10 <= |exponent| < 1e10 for layer > 0 or 1e-10 < exponent < 1e10 when layer = 0.
- when exponent is negative, it’s the reciprocal of the value with |exponent| as their exponent.
- layer equaling -1 represents NaN
- layer or exponent equaling math.huge represents inf
please report any bugs you find/suggest anything you want to see added.
Get it here: GammaNum
I also want to give a thanks to gui_ducks for the name of the module.