✓ Accepted answer
Lua uses doubles for all numerals.
These are 64 bit numbers. One bit is used for sign, eleven for the exponent, and fifty-three for the fraction.
This means you have approximately 16 decimal-digits of accuracy. This should be enough for most simulations.
Note that certain operations will cause more loss-of-precision that others. There are algorithms or choices that you can make in the order of computations which minimize these. For example, Kahan summation.
If you need higher precision numbers, it would most likely be best to use floating point still as opposed to fixed point. A floating point number is stored in a scientific-number type form. This allows numbers to have a constant number of significant figures despite how big / small they are.
For efficiency purposes, rather than storing a list of digits (base 10), it would be better to use a much larger base (e.g., base 1000, or bigger), and so 10^6 * pi would be stored as something like:
{2, 3, 141, 592, 653, 590} to represent 3 * b ^ 2 + 141 * b ^ 1 + 592 * b ^ 0 + 653 * b ^ (-1), etc. (where b is 1000).
You, of course, remain to implement addition, multiplication, and division efficiently on these numbers.
2 comments
Could you explain why you need these usually rather insignificant digits?
I'm trying to make a relativistic physics simulator. Once objects get very close to the speed of light, certain properties become very sensitive to incredibly small changes in velocity. For this reason, due to the inaccuracy of the values being stored and manipulated, I get bad results that can occasionally ruin the simulation. (Singularities form, objects break the speed of light, etc.)