Join the Discord server! OmegaNum is a port of Naryuoko's OmegaNum for Lua. This library is highly inaccurate for huge numbers, which is perfect for incremental games that intend to reach very big numbers quickly.
local om = require("omeganum")
print(tostring(om.add("1", 1))) --> 2
print(tostring(om.new(1) + om.new(1))) --> 2
The original code is written in Fennel, a Lisp that compiles for Lua. For convenience I provide a Lua file aswell, but in reality you should edit the Fennel file.
This library also has tests. The tests depend on the Faith library which must be put in the same directory. To run the tests, type in the terminal fennel faith.fnl --tests tests
. If you're on Emacs, open the tests.fnl
file and do M-x inferior-lisp
. If you press on the original buffer for tests.fnl
it will run the tests and show the results in the new buffer
To compile the file, run fennel --plugin omeganum.fnl
and in the repl type ,make
. It should write the documentation to README.md
, compile to omeganum.lua
and run the tests
Returns omeganum as a positive number always
- Aliases:
a + b
omegaNum.add(a, b)
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a + b
. Otherwise Luau gives an error.
Adds a and b
Clones omeganum. This is needed because in Lua tables aren't copied everytime you do operations on them. As an example, the following code returns 3
local x = {}
local y = x
y.x = 3
print(x.x)
OmegaNum clones the number everytime you do an operation on it such as addition or basically any other operation, so most likely you won't need to use this function
Returns 0 if they're equal, 1 if a is greater or -1 if b is greater
- Aliases:
a / b
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a / b
. Otherwise Luau gives an error.
Divides a by b
- Aliases:
a == b
Returns true if a is equal to b. Ensure both numbers are OmegaNums when using thea == b
syntax as doingomegaNum.new(n) == notAnOmegaNum
returns nil
Turns n into an integer
Creates an OmegaNum from an array. This function requires you to know OmegaNum's internal format, which is described in OmegaNum's github site
Creates an OmegaNum from a number
It parses the string and creates an OmegaNum from it. The format is quite elegant and I would recommend you to check OmegaNum's documentation for that as I don't think I'm fully qualified to explain it. Note that the format isn't 1:1 because I got kinda lazy tbh
- Aliases:
a > b
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a > b
. Otherwise Luau gives an error.
Returns true if a is greater than b
Returns true if omeganum is not an infinite number
Returns true if omeganum is infinite. One way to reach infinity is by doing omegaNum.div(0, 0)
Checks if n is an integer
Returns true if omeganum is NaN. NaN is the result of an undefined math operation, for example, 0 / 0 returns NaN
Returns true if any is not an OmegaNum object
Returns true if any is an OmegaNum object
Returns the logarithm of 10 by n, or in other words: what is x in 10^x = n
- Aliases:
a < b
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a < b
. Otherwise Luau gives an error.
Returns true if a is smaller than b
- Aliases:
a <= b
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a <= b
. Otherwise Luau gives an error.
Returns true if a is less or equal than b
- Aliases:
math.max(a, b) --[[only works in normal Lua]]
Returns the biggest number, a or b
- Aliases:
math.min(a, b) --[[only works in normal Lua]]
Returns the smallest number, a or b
- Aliases:
a % b
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a % b
. Otherwise Luau gives an error.
Returns the modulo of x over y
- Aliases:
a * b
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a * b
. Otherwise Luau gives an error.
Multiplies a by b. Note, if a number is too huge you should try powering it by a big number. When doing multiplication by two very big numbers, OmegaNum doesn't botter and just returns the biggest number.
- Aliases:
-a
omegaNum.__unm(a)
Returns the omeganum with the opposite sign, e.g: 1 -> -1 and -1 -> 1
Creates an OmegaNum from a number, a string, or an array. If an OmegaNum is passed then it is cloned. The sign paramether is for when this function receives an array.
Internally, it calls the functions omegaNum.fromString
, omegaNum.fromNumber
, omegaNum.fromArray
and omegaNumber.clone
respectively
- Aliases:
a ^ b
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a ^ b
. Otherwise Luau gives an error.
Exponentiates a by *b+
- Aliases:
1/n
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
1/n
. Otherwise Luau gives an error.
Returns the reciprocate, or in other words: 1 / n
Returns the y-th root of x
- Aliases:
a - b
- Note when using Luau: Ensure both numbers are OmegaNums when using the following syntactic sugar:
a - b
. Otherwise Luau gives an error.
Substracts b from a
Converts an OmegaNum number into a Lua number. Mostly used interanally as there's not much point on using this.