Arithmetic Module

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"

Arithmetic.lua (1.6 KB)

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
3 Likes

I’m sorry, but this is useless. You can achieve the same end results using variables and arithmetic operations.

10 Likes

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.

image
(Function 1 is the custom function and Function2 is the module function)

Here is the code that I used:
Benchmarking.rbxm (6.0 KB)

What is the purpose of OOP in this module?

4 Likes

what even is the purpose of this I can do this with roblox variables lol

1 Like

Some guy beat you to it, on basically the same idea

How is this different

*= += -= /= ^= %=

Need I say more?

1 Like

I am confused, what is the problem here?

1 Like

Is that this already exists, except itd not a third party module

3 Likes

You did not answer the question, what was the problem with the symbols?

I dont have any problem with the symbols. Im just saying that something already exists and you do not need a third party module for this.

Well you made the point really hidden, you could’ve said so instead of encrypting it.

I dont want to be rude,

First, it’s a nice module , but useless [I still appreciate the time you put into it].

Now,
As others have asked above -

Why should someone use this over simply doing these:

local function AddNumbers(num1:number,num2:number)
    return num1 / num2 , num1 * num2, num1 + num2, num1 - num2
end

or even just doing

local num1,num2 = 1,2
print(num1 + num2)
1 Like

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.

1 Like

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.

2 Likes

Thank you, but I know what they’re saying is pretty honest, I just don’t like the tone they use.

No offense but this really has no use because everyone can do it with basic variables. But I guess it could be good for making your code look better.

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.

1 Like

No, but it says this:

image

This is in no way significant and is low quality. As even you stated, the built-in math library can do exactly what this module can and more.

1 Like