Floating Point v.s. Integers

Hi.

I have to represent large numbers in my game. In order to maintain precision; is it convenient to use, by example, 1e33 or 1e-33?

I read this as contradictory and am unable to figure out the correct approach for Luau.

Thanks for reading; any help is appreciated.

If you need very large numbers, I recommend a BigInt module.

1 Like

The TLDR is that what kind of number you require depends on what kinds of operations you need and to what extent their result must be correct. If you require that all addition and subtraction gives a comparatively correct number (A + 1 == A where A is a very big number must ALWAYS be false), then you have to use a big integer like one from BigInt. If you try to use a float for this, then A + 1 will “flush” if A is too large, and the result will be unchanged. However, if the numbers you’re adding to A grow at about the same rate as A itself, you can continue to use floats up to almost their maximum value of about 10^33

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.