Lua5.3与Lua5.1相同的代码

时间:2018-03-22 18:55:25

标签: lua

我在Lua中有这个用于阶乘微积分的脚本:

N, F = 1, 1
while F < 1e200 do
print(N .. "! is " .. F)
N = N + 1
-- Compute the factorial of the new N based on
-- the factorial of the old N:
F = F * N
end

Lua 5.3中此代码有什么问题?在19!之后,一切都很奇怪。 但是相同的代码在Lua 5.1中完美无缺。

1 个答案:

答案 0 :(得分:2)

Lua 5.3支持整数,它具有环绕算术。

使用

尝试使用代码
N, F = 1, 1.0

获得与Lua 5.1相同的行为。