Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!bu.edu!husc6!m2c!umvlsi!dime!leban From: leban@par3.cs.umass.edu (Bruce Leban) Newsgroups: comp.sys.mac.programmer Subject: Re: Why can't the Mac add? Message-ID: <20360@dime.cs.umass.edu> Date: 24 Sep 90 23:41:14 GMT References: <45060@apple.Apple.COM> Sender: news@dime.cs.umass.edu Reply-To: leban@par3.cs.umass.edu (Bruce Leban) Organization: University of Massachusetts, Amherst Lines: 14 Several people have suggested replacing: for (x=0.0;x!=10.0;x+=0.2) with variations of: for (x = 0.0; x < 10.0+epsilon; x += 0.2) but that is not the best suggestion since the floating point error compounds on each addition. Presumably, what you want is the nearest approximation to the sequence 0.0, 0.2, 0.4, etc. In that case, do: int y; float x; for (y = 0; x = y/10, y <= 100; y += 2) An excellent reference is the /Elements of Programming Style/ which points out that "0.1 * 10.0 is hardly ever 1.0". --- Bruce Leban@cs.umass.edu @amherst.mass.usa.earth