[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: noobie question about numeric for
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 27 Mar 2012 11:53:50 +0200
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.