为什么lua 5.1错误地解释某些整数?

时间:2018-02-07 17:57:31

标签: lua integer

Lua 5.1似乎将许多完全有效的64b整数解释为

#custom-owl-slider .owl-item  {
    display: flex !important;
    justify-content: center !important;
    height: auto; /* or other desired height */
    overflow: hidden !important;
}

#custom-owl-slider .owl-item img {
    flex: none !important; /* keep aspect ratio */
}

而最大的有符号有效64b整数是

1,805,996,217,335,808,768 

以下是不幸输出的示例:

9,223,372,036,854,775,807

人们希望在这里找到Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio > return 1805996217335808768 == 1805996217335808804 true > return 1805996217335808768 == 1805996217335808805 true > return 1805996217335808768 == 1805996217335808806 true > return 1805996217335808768 == 1805996217335808769 true > return 1805996217335808768 == 1805996217335808767 true false

编辑(标记为重复):

这不是this question的重复,因为你无法编译Lua 5.1来处理64b整数。

1 个答案:

答案 0 :(得分:0)

Lua 5.1使用精度为53位的double类型。

只有前53位数字将被存储在双小数部分中。 最大有效整数为9007199254740991。如果数字大于9007199254740991,则最后一位直到53位将被清零。

54位数字:

18014398509481983 = 111111111111111111111111111111111111111111111111111111b

内部将存储为

18014398509481982 = 111111111111111111111111111111111111111111111111111110b

因为仅使用了前53位,所以两者相等。