Any fast way to do math with more then 32 bits?

Hello, I was wondering if there was any way to quickly do math with more then 32 bits?

If this helps, I don’t need decimals, and the only operations I really need are + - * / ^ %

Any suggestions are appreciated.

Won’t the regular Number (roblox.com) suffice? I haven’t run into a situation where it would be too slow. It can handle numbers as large as 10^308.

It wouldn’t suffice as those are floating point numbers and I need the calculations and numbers to be exact.

If you only need integers and all of your operations are using integers, wouldn’t the calculations still be exact? There is no good way to do math in a way completely different than the language has intended for it to be done.

Are you able to provide an example where there would be an issue from using the regular methods?

2 Likes
print(2^64)

Result: 18446744073709552000
Expected Result: 18446744073709551616

Hmm, well yes, that would of course be an issue if you cannot allow a margin of error of 0.00000000000000002082%. While I understand there are applications you may need to be this precise, I think this just have to work.

The following is from the documentation of the Number class:

My interpretation of this is that there is no way to represent numbers differently than this, which would me you either somehow had to create your own way of doing math, which I think would tank the performance, or you would have to take the inaccuracy into account in some way.

1 Like

I might be able to work with int64 for my code, do you know if there is a way to make sure a number is a int64 number?

When I initially saw that int64 I thought it would be a good solution for you as well, but as the excerpt I sent earlier states they are meant to as more of a hint than a type.

There are libraries which can represent arbitrarily large integers, at the cost of slightly slower calculations.

For example there’s BigNum which has many ports and copies. Here’s one of them: https://github.com/RoStrap/Math/blob/master/BigNum.lua

1 Like