I want to point out that Lua stores numbers internally as "double" (in C terminology). Since MUSHclient is compiled under the Microsoft compiler, the definition of the Microsoft double is:
An important point here is that the mantissa is 52 bits, so the largest number you can reliably store and add 1 to (to reach the next number up) is 2^52, or 4,503,599,627,370,496.
Whilst you can store larger numbers some of the low-order precision will be thrown away, since the mantissa only stores 52 bits. As an example:
This example shows that it thinks that 2e100 and 2e100 plus one are the same number. (The number 2e100 is a "2" followed by 100 zeroes). Effectively the processor (this is the maths chip, not Lua specifically) has had to throw away some of the low-order bits in order to store that really large number.
By way of comparison, smaller numbers work correctly:
The break-even point, as I mentioned earlier, is 52 bits, so you can test it like this:
This is really only of academic interest, usually if you are working with really large numbers you don't care if they are absolutely accurate.
However if it really matters, you can use the "bc" library, which works with full precision.
http://www.gammon.com.au/scripts/doc.php?general=lua_bc
The double type contains 64 bits: 1 for sign, 11 for the exponent, and 52 for the mantissa. Its range is +/–1.7E308 with at least 15 digits of precision.
An important point here is that the mantissa is 52 bits, so the largest number you can reliably store and add 1 to (to reach the next number up) is 2^52, or 4,503,599,627,370,496.
Whilst you can store larger numbers some of the low-order precision will be thrown away, since the mantissa only stores 52 bits. As an example:
print (2e100 == 2e100 + 1) --> true
This example shows that it thinks that 2e100 and 2e100 plus one are the same number. (The number 2e100 is a "2" followed by 100 zeroes). Effectively the processor (this is the maths chip, not Lua specifically) has had to throw away some of the low-order bits in order to store that really large number.
By way of comparison, smaller numbers work correctly:
print (2e10 == 2e10 + 1) --> false
The break-even point, as I mentioned earlier, is 52 bits, so you can test it like this:
print (2^52 == 2^52 + 1) --> false (correct)
print (2^53 == 2^53 + 1) --> true (incorrect, they are different)
This is really only of academic interest, usually if you are working with really large numbers you don't care if they are absolutely accurate.
However if it really matters, you can use the "bc" library, which works with full precision.
http://www.gammon.com.au/scripts/doc.php?general=lua_bc