问题描述
文档中似乎没有明确的答案.
There doesn't seem to be a clear answer to this in the documentation.
我对递增自程序启动以来的秒数的变量time
感兴趣.如果最大值可以算作未来的很远的数字(例如100年),那么我就不在乎让变量永远递增.否则,我将不得不考虑将time
重置为0的好方法.
I'm interested in incrementing a variable time
that counts the seconds since the program started. If the maximum value can count far into the future, like 100 years, then I don't care about letting the variable increment forever. Otherwise I'm going to have to think of a good point to reset time
back to 0.
推荐答案
在默认情况下,在大多数编译器中,Number是一个double
,它是IEEE 64位浮点.这意味着10bit的指数,因此最大数目大约为2 ^ 1024,即5.6e300年.很久了.
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.
现在,如果要增加它,您可能会对整数范围更感兴趣. 52位尾数表示可以以整数精度使用的最高数字为2 ^ 52,大约为4.5e15.每年31'557,600秒,即1.427e8,接近1.5亿年.任何过程的正常运行时间仍然很长
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
更新2014-12-30 :Lua 5.3(现在随时发布)增加了对通过编译标志选择的32位或64位整数值的支持.
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.
这篇关于Lua中数字的最大值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!