Confirmed the problem is that floats are not “precise”. Used your original isInteger() function, which didn’t see any integers. Then tested with the following:
local timeCount = 30
local function isInteger(x)
return ( x - math.floor(x) \< 0.001 ) or ( math.ceil(x) - x \< 0.001 )
-- return math.floor(x) == x
end
while timeCount \>= 0 do
timeCount = timeCount - 0.1
if(isInteger(timeCount)) then
print(timeCount.." is an integer")
else
-- print(timeCount)
end
end
All expected values were close enough to be considered integers. Interestingly, the last few lines showed the gradual accumulation of errors in the floats:
13 is an integer
12 is an integer
11 is an integer
9.9999999999998 is an integer
8.9999999999998 is an integer
7.9999999999998 is an integer
6.9999999999998 is an integer
So, moral is not to assume that math is “precise”. [import]uid: 37155 topic_id: 13552 reply_id: 50026[/import]