So this module basically takes a string, acts on it like a number by most of the functions iterating thru each character and carrying numbers like how multiplication, sum and substractions work and give a string result that can go any length.
It works like a oop number constructor with methods to add on other constructors or simply strings / numbers. (Yes, you can initially assign it a number but it will convert itself to a string.)
It has functions that compare numstrings with other numstrings and return booleans such as :isgreaterthan (>), :islessthan (<) and :isequalto (=)
For you to get a grasp, I multipilied a 30K digit stringnum (yes, 30k characters long) 20 times, which was approximately…
9.87698987 * 10^30764
Then, take that number and multiply it 20 times
20(9.87698987 * 10^30764)
The operation took about 0.97 seconds to complete, which is absolute madness. I really dont know how a computer would take to do that with regular numbers.
Advantages
- Let’s you go as long as your hardward doesn’t die
- Mostly optimized
- Why not try how big of a number you can get?
- Multiplication, subtraction, addition and exponentiation available
- I guess it can be saved in a datastore, with string compression of course
- And for the best, it has 6 possible number representations to choose from!
local extra = testInt.extra
print(extra.numvalue, -- 12005000000
extra.scientific_explicit, -- 1.2005 x 10^10
extra.scientific_enotation, -- 1.2005e+10
extra.shortnam, -- 12 billion
extra.shortsym, -- 12B+
extra.vcommas -- 12,005,000,000
)
Disadvantages
- Division, decimals and negative numbers not supported (For now
). It’s meant only for positive integers
- Going crazy with it, such as exponentiating a huge number by a huge number is going to truncate the result up to a higher value, but not the expected one. (Script exhaustion time)… however you can also do a work around and add task.wait()s
- Still working on a way to make it more game friendly. Doing extremely high values (and I mean, extremely as extremely extremely) will cause the framerate of the server/client to drop, still looking for methods with parallel lua to speed it up
Example script, I recommend you to put it thru the command bar and see the output.
local widenum= require(game.ReplicatedStorage.widenum)
-- Initial require
local int = widenum.newint("5")
-- Create a new positive integer
print("Results:\n")
-- Exponenciate
int:exp("5")
print("5^5 =",int:get()) --> 3125
print()
int:set("5")
-- Multiply
int:multiply("10")
print("5*10 =", int:get()) --> 5
print()
int:set("10")
-- And all its benefits come because it remains a string,
-- only being close to a number when each digit is converted to a number
-- In the process.
-- Substract
int:sub("5")
print("10-5 =", int:get()) --> 5
print()
-- Substract again but with a larger number
int:sub("10")
print("5-10 is truncated to =", int:get())
print()
-- As specified before, it's meant to display positive integers.
-- It's very well recommended for simulators to represent cash or repetition
-- Still, useful for any other purpose.
-- A little rough test
local start = os.clock()
int:add("234567891223456789123456789123456789012312432534534567891234567890123124325345")
int:add("1273967512739675782465834568437654368534756834568345738782465834568437654368534756834568345738")
int:multiply("229")
int:update()
print(`Crazy arithmetic result: {int.extra.shortnam}, took about {os.clock()-start} seconds to do allat.`)
print(`A 78 digit number + a 94 digit number multiplied 229 times.`)
Methods:
Most important method to remember
self:update(): ()
- Why is it so important?
- If you ever want to display any value other than the main value (such as with scientific notation or with commas), you need to call this function before doing it.
It is NOT automatically updated because the performance loss of doing that comes down to about -50% less performance. So if you want to display the number in a text, do self:update() and then self.extra.scientific_explicit or anything you want.
- If you ever want to display any value other than the main value (such as with scientific notation or with commas), you need to call this function before doing it.
It does not affect the main value which is doing int.value or int:get(), so you can call those without worrying.
Base methods:
Create a new integer:
widenum.newint(value: string | number): constructor (self)
Get a random string number:
widenum.getrandomwidenum(stringLength: number): string
Number methods:
(Self is the variable you use to store the newint value, for example:
local myNumber = widenum.newint("1000")
myNumber:sum("100000")
Addtion:
self:add(other: widenum | string | number): ()
Subtraction:
self:sub(other: widenum | string | number): ()
Multiplication:
self:multiply(other: widenum | string | number): ()
Exponentiate:
self:exp(other: widenum | string | number): ()
Comparison methods:
(=) Operator:
self:isequalto(other: widenum | string | number): boolean
(>) Operator
self:isgreaterthan(other: widenum | string | number): boolean
(<) Operator:
self:islessthan(other: widenum | string | number): boolean
Other methods:
Set:
self:set(newvalue: widenum | string | number): ()
Get: (same as doing self.value)
self:get(): string
Remove constructor
self:destroy(): ()
And don’t forget (as specified above), update the decorative values
self:update(): ()
Get it here
Keep the extinguisher near your pc, just in case