Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
809 views
in Technique[技术] by (71.8m points)

time - What is the maximum value of a number in Lua?

There doesn't seem to be a clear answer to this in the documentation.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...