What is the maximum value of a number in Lua?

as compiled by default, the Number is a double, on most compilers that’s an IEEE 64-bit floating point. that means 10bit exponent, so the maximum number is roughly 2^1024, or 5.6e300 years. that’s a long time.

now, if you’re incrementing it, you might be more interested in the integer range. the 52-bit mantissa means that the highest number that can be used with integer precision is 2^52, around 4.5e15. At 31’557,600 seconds/year, that’s 1.427e8, almost 150 million years. still a very long uptime for any process

update 2014-12-30: Lua 5.3 (to be released any moment now) adds support for integer values, either 32 or 64 bits chosen via compile flags.

Leave a Comment