lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Mar 27, 2012 at 11:40 AM, fra III <ilterzouomo@fastwebnet.it> wrote:
> the first include last value (1.0), while the second not.

It is because of floating-point inaccuracy, so the cumulative sum is
not _quite_ 2.0 at the end

> for x = 1.0,2.0,0.1 do print(x) end
1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9

but check this:

> for x = 1.0,2.0+1e-14,0.1 do print(x) end
1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2

Gotcha!  Note the small little 'epsilon' we have added to 2.0.

steve d.