How do you handle numbers larger than the max?

When using numbers on Roblox, there is a max number, which I believe is 2,147,483,647 (corrected by CloneTrooper1019). However, some people get around this, such as Mining Simulator:

image

What methods can you use to do this?


6 Likes

You’ll need some implementation of BigNum.

I haven’t tried this module, but it’s in pure Lua 5.1 so it should port over to Roblox nicely with relative ease: euler/BigNum.lua at master · ennorehling/euler · GitHub

Not exactly sure how you’d serialize it to data storage with this module, but that’s something you should be able to look into.

17 Likes

Can confirm this is working.

Haven’t taken too much of a look at it so I don’t know how i would save the BigNums to a data store yet. Will try figuring that out soon.

3 Likes

You could also just use number values instead of intvalues

Number values go upto 10^300 and lua can handle them without any outside library

1 Like

As far as I know, this isn’t true and I just tested it.

image

In fact, it doesn’t seem to work at around 10^23.

image

4 Likes

those are called floating point precision errors and occurr because they dont store the full number (kinda)

1 Like

I know, thus it’s not useful for the OP’s use cases.

2 Likes

I managed to JSONEncode and JSONDecode a BigNum. Thanks @Kampfkarren.

2 Likes

didn’t they increase int values to 64-bit?

3 Likes

For reference the largest value you can have now is 9,223,372,036,854,775,807 when using an IntValue.

21 Likes

Also, the maximum integer value that can be stored with precision in a Lua number (or more generally in a double-precision number) is 2^53 or around 15 quadrillion. Depending on your purposes this might not be enough, but it’s good to know.

4 Likes

And if datastore of the number is an issue, you could potentially save the number as a string and convert it back to a number on loading if it were to be that big of a problem.

3 Likes

Can you upload the file for the roblox version of BigNum? My ported version is having an error while loading :\

Edit*: Nvm I found this: https://raw.githubusercontent.com/RoStrap/Math/master/BigNum.lua HOWEVER for some reason having a large number powered by itself makes a negative large number rather than a positive cus their both positive.

1 Like

I would imagine you could create a separate value for each next big number, for example Value: 10 (Billion), Value: 500 (Million), Value: 875,000 So basically just breaking it up. When it comes to the math, just account for this and add/subtract based on all these values.