I have created a simple module that does the math for you!
Most of its use is for mass incrementation to create big numbers through tables. I made this for a math heavy game that I am currently making if you are curious.
Example:
local ArithmeticModule = require(script.Arithmetic)
local Arithmetic = ArithmeticModule(1) -- Starting number or 0
Arithmetic:Add(1) -- Adds 1 (2)
Arithmetic:Multiplication({3, 2}) -- Multiplies by 3 then 2 (6, 12)
Arithmetic:Division({3, 2}) -- Divides by 3 then 2 (4, 2)
Arithmetic:ToPowers({3, 2}):andThen(function() -- To the power of 3 then 2 (8, 64)
print("Finished arithmetics.")
end)
print(Arithmetic.Number) -- Prints "64"
local arithmetic = {}
arithmetic.__index = arithmetic
local contin = {}
function contin:andThen(callback: functionOrThread, ...: any?)
coroutine.wrap(callback, ...)()
return contin
end
function arithmetic.new(number: number?)
return setmetatable(
{
Number = number or 0;
}, arithmetic)
end
function arithmetic:ToPowers(powers: table)
assert(powers)
for _, number in pairs(powers) do
self.Number ^= number
end
return contin
end
function arithmetic:ToPower(number)
assert(number)
self.Number ^= number
return contin
end
function arithmetic:Multiplication(multipliers: table)
assert(multipliers)
for _, number in pairs(multipliers) do
self.Number *= number
end
return contin
end
function arithmetic:Multiply(number)
assert(number)
self.Number *= number
return contin
end
function arithmetic:Division(dividers: table)
assert(dividers)
for _, number in pairs(dividers) do
self.Number /= number
end
return contin
end
function arithmetic:Divide(number)
assert(number)
self.Number /= number
return contin
end
function arithmetic:Subtraction(subtractors: table)
assert(subtractors)
for _, number in pairs(subtractors) do
self.Number -= number
end
return contin
end
function arithmetic:Subtract(number)
assert(number)
self.Number -= number
return contin
end
function arithmetic:Addition(adding: table)
assert(adding)
for _, number in pairs(adding) do
self.Number += number
end
return contin
end
function arithmetic:Add(number)
assert(number)
self.Number += number
return contin
end
return function(...)
return arithmetic.new(...)
end
As stated by @R0bl0x10501050 , this module is unnecessary and can be achieved without using this module. I did some benchmarking using this module and a function that returns the sum of two numbers. The custom function that returned the sum of two numbers was about 112% more faster than this module.
(Function 1 is the custom function and Function2 is the module function)
Firstly, thank you for being courteous, unlike others here.
To answer your question, I intended for it to make the math look clean, since simply putting a large amount of numbers in a function looks unorganized to me.
It was made for personal use but I released it simply if anybody felt like using it.
Though, what everybody said here is true, and it is useless, I don’t want to be rude. It’s true that using math looks a little unclean, but it’s that you’re making a module on math with less functions but with clean names.
Though, I still appreciate you putting your time onto developing.
If I read the rules for a post in #resources category correctly, it never said the resource has to be useful or some world changing resource. However, I agree that that this is the equivalent of the math library ( And the mathematical operators) that Lua provides for us.