lua-users home
lua-l archive

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

On Mon, Nov 20, 2017 at 4:03 PM, Paige DePol <> wrote:
> I would also like it if 2.5,3.0,0.1 actually iterated on 3.0, but that
> sure seems to be quite the complex problem in general.

Well, I mean, I already explained a couple different ways to do that one. ;)

One of the ways I quoted is numerically ideal: Computing the number of
steps and then multiplying the iteration number by the step size is
the most stable way to do it because it doesn't accumulate error.
Unfortunately, it's also got more overhead because multiplication is
so expensive relative to addition, but I imagine that it's not going
to have a noticeable impact on most use cases.

There are a variety of techniques you can use to minimize or mitigate
the rounding error even without using multiplication. Accumulating
steps starting at 0 instead of at the lower bound is a good start
because it means you're more likely to be adding numbers of similar
magnitudes (you add the accumulator to the lower bound and set the
loop variable to that). You could also compute the actual error in
advance and use that to adjust the upper bound if it would miss.

Obviously none of these techniques come without cost, but it actually
IS a well-researched field and the solutions are understood.

/s/ Adam