【发布时间】:2017-09-11 19:24:34
【问题描述】:
我是 lua 新手,我正在使用它来自动化模拟程序 femm 中的一些任务。在我的脚本中,我有这种类型的 for 循环:
for i=0.1,0.3,0.1
do
print(i)
end
问题是它只从 0.1 迭代到 0.2(它没有输入 i=0.3)。我尝试了其他值(例如从 0.1 到 0.4)并且它工作正常。为什么会发生这种奇怪的行为?这是浮点数问题吗?
【问题讨论】:
-
0.3 可能不等于 0.3
-
这是不是因为它没有声明为整数(我之前没有使用过lua)?我应该只对循环变量使用整数值吗?
-
试试
i=0.1, 0.3+1e-9, 0.1 -
听起来你may need a primer在浮点运算中
标签: loops for-loop lua iteration