Mail Archives: djgpp/1997/04/29/12:34:59
On Mon, 28 Apr 1997, John M. Aldrich wrote:
> Your problem is the cumulative error introduced by the lack of precision
> of floating point variables.
That is correct.
> There's no easy way around the problem, because it even persists when
> you change the precision of current to double or long double. It's the
> repetitive additions and subtractions that cause the problem
That is also correct, and the usual way to work around the accumulation
of round-off errors is to multiply instead of adding. That is, instead
of adding current += SPEED, say something like "current = SPEED * count"
where `count' is an integer variable that counts the number of iterations
through the loop.
- Raw text -