InstanceCalculator - Calculator with 0 internal math operations


Calculator with 0 internal math operations, supporting both negative and positive integers

View the GitHub repositoryVisit the demo placeDownload the module


This module offers four of the most basic math operations: addition, subtraction, multiplication, and division. However, it unironically takes pride in its in its zero tolerance policy for the +, -, *, and / symbols. Because of the methods it uses to make these calculations, you willl notice that calculations often become unreasonably slow when using numbers larger than ~16 bits.


The method is in the name. The main principle is getting the length of the table returned by calling GetChildren on a folder of instances. We can add an instance one by one until we reach a certain amount using a for loop, and we can do that again a different amount of times for a different amount. Finally, we check the amount of instances there are and that is your sum! This same concept is applied to the subtraction, multiplication, and division functions, just in slightly more complicated fashions. The hardest part, though, was adding unrestricted support for negative numbers. I ended up creating a class called Number that stores the sign as either “Positive” or “Negative” in a property. I also ended up using a combination of string manipulation and tostring/tonumber to detect the sign of numbers and convert them between positive and negative with no math. I was going to implement support for non-integers, however after fiddling around for a bit I realized how difficult that would be without math. Lucky for you, the source is all available in this repository, and if you want to give adding decimals a shot––well, I wish you luck.

There is also a demo LocalScript included that creates an interface and buttons for you to play with the module without having to touch anything. I’ve also attached a demo game for those who are nauseated at the sight of code.


Stan asked me to.

All source code and files are uploaded to the project’s GitHub repository.


even though there’s no use in it, i did ask for it as a joke


It works as intended! There is only one slight issue: the script ran out of memory when I tried to add large numbers.


PC died when I added 15678, and 1234567890 together. It still worked perfectly fine when my PC wasn’t half dying. Very cool!

1 Like

This is inevitable, the 0 math operation motto is held true by spam creating instances and then checking how many there are. Adding large amounts will always cause a memory leak regardless of the optimizations I add.

Perhaps I could store the current amount after reaching a certain amount of instances and then clear them, and then add the new count onto the old count. This would create a whole new universe of what-ifs that. I’d have to also account for, though. Maybe I’ll add it in the future, although I’m not intending to constantly update this project since it’s just a showcase.

1 Like

This is a pretty humorous “DI-WHY…?” style project. I applaud the absurdity and the idea as a creative exercise!

You seem to store state using instance. This is fairly inefficient, as you stated. A way you could achieve addition without using Lua mathematical operations with greater performance is by implementing math via boolean logic gates and tables of bits. You could simulate a full-adder ladder for addition, and expand from there for other mathematical operations. It would even be possible to support floating point numbers if you follow the IEEE 754 Spec.

Because you would be evaluating boolean operations against a table, it would both fulfill the requirement and be a lot faster than adding a bunch of instances to a folder.

1 Like