delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/29/12:34:59

Date: Tue, 29 Apr 1997 19:14:21 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: fighteer AT cs DOT com
cc: djgpp AT delorie DOT com, David Jenkins <me AT jenkinsdavid DOT demon DOT co DOT uk>
Subject: Re: Floating point bug???
In-Reply-To: <336480C1.37C2@SPAMcs.com>
Message-ID: <Pine.SUN.3.91.970429191100.24554A-100000@is>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019