Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!sunybcs!uhura.cc.rochester.edu!lowj_ltd From: lowj_ltd@uhura.cc.rochester.edu (John Alan Low) Newsgroups: comp.lang.pascal Subject: Re: Problem in Turbo Pascal 4.0 Summary: Loop terminates when binary coded decimal is used. Keywords: Nonterminating Repeat loop, real, representation, binary coded decimal Message-ID: <4679@ur-cc.UUCP> Date: 3 Jan 90 18:58:34 GMT References: <4658@ur-cc.UUCP> <4660@ur-cc.UUCP> <803@tuewsd.lso.win.tue.nl> Reply-To: lowj_ltd@uhura.cc.rochester.edu (John Alan Low, aka "Travis" Low) Followup-To: comp.lang.pascal Organization: University of Rochester Lines: 32 In article <803@tuewsd.lso.win.tue.nl> wsinkees@lso.win.tue.nl (Kees Huizing) writes: >>In article <4658@ur-cc.UUCP> I wrote: >>>Program Foo; >>>var x : real; >>>Begin x := 0.10; >>> Repeat >>> x := x + 0.01; >>> Until x = 0.30; End. >It's not you that is stupid, it's (Turbo?) Pascal. Is it not the purpose of >a high level pogramming language to hide the funny details of implementation >and representation for the user? As it shows, the equality operator >"=" does not on reals what it pretends to do. I accept that it cannot >detect perfect equality of reals, but what it could do is detect equality >upto some representation dependent accuracy. >Why is it not done this way? After I read this, I compiled the program with the Turbo Pascal 3.0 turbobcd.com compiler. Guess what? The loop terminates nicely. Also, expressions such as 1/3 + 2/3 come out equal to 1.0. So the binary- coded representation of decimals works nicely, and the "=" works the way it's supposed to. Is there some reason this representation is not common practice? Can anybody shed some light on this? I think that later versions of Turbo Pascal do not implement this representation, so there must be some good reason, right? ---Travis Ich suche die Leidenschaft, die keine Leiden schafft.