Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!snorkelwacker!bloom-beacon!eru!luth!sunic!tut!ra!uwasa.fi!ts From: ts@uwasa.fi (Timo Salmi LASK) Newsgroups: comp.lang.pascal Subject: Re: Problem in Turbo Pascal 4.0 Keywords: Nonterminating Repeat loop, real, representation Message-ID: <1990Jan4.081234.7882@uwasa.fi> Date: 4 Jan 90 08:12:34 GMT References: <4658@ur-cc.UUCP> <4660@ur-cc.UUCP> <803@tuewsd.lso.win.tue.nl> Organization: University of Vaasa Lines: 31 In article <803@tuewsd.lso.win.tue.nl> wsinkees@lso.win.tue.nl (Kees Huizing) writes: >lowj_ltd@uhura.cc.rochester.edu (John Alan Low) writes: > >>In article <4658@ur-cc.UUCP> I wrote: >>>I am having a problem with Turbo Pascal 4.0. 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. > >> Thanks to everybody who emailed me on this. I forgot that 0.01 is a >> repeating decimal in binary. I never will again. One (similar) solution as has been pointed out by many netters is using function Equal (a, b : real) : boolean; begin if abs(a-b) < 1.0E-5 then equal := true else equal := false; end; . Until Equal (x, 0.30); ................................................................... Prof. Timo Salmi (Site 128.214.12.3) School of Business Studies, University of Vaasa, SF-65101, Finland Internet: ts@chyde.uwasa.fi Funet: vakk::salmi Bitnet: salmi@finfun