Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!sun-barr!newstop!sun!adapt!linden From: linden@adapt.Sun.COM (Peter van der Linden) Newsgroups: comp.lang.pascal Subject: Re: Problem in Turbo Pascal 4.0 Keywords: Nonterminating Repeat loop Message-ID: <129757@sun.Eng.Sun.COM> Date: 30 Dec 89 19:05:44 GMT References: <4658@ur-cc.UUCP> Sender: news@sun.Eng.Sun.COM Reply-To: linden@sun.UUCP (Peter van der Linden) Organization: Sun Microsystems, Mountain View Lines: 29 > Reply-To: lowj_ltd@uhura.cc.rochester.edu (John Alan Low, aka "Travis" Low) > The repeat loop in the following loop never terminates. > Program Foo; > var x : real; > Begin > x := 0.10; > Repeat > x := x + 0.01; > Until x = 0.30; > End. Another programmer discovers inexact representation of decimals as binary reals! What is happening is that your literals are not *exactly* representable as binary floating point numbers. Hence the loop termination test is never satisfied. The routines that print, also round, so you never saw this. You can change the test to "until x >= 0.30" instead of multiplying. If you have access to a Sun system, read the "Floating Point Programmers Guide" (purple tab in the docu-box). ---------------- Disclaimer: I'm no Jack Kennedy, but I'm no Dan Quayle either. Peter van der Linden linden@SuN.cOm (415) 336-6206