Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!pasteur!helios.ee.lbl.gov!nosc!spectra!bseeg From: bseeg@spectra.COM (Bob Seegmiller) Newsgroups: comp.lang.pascal Subject: Re: Problem in Turbo Pascal 4.0 Keywords: Nonterminating Repeat loop, real, representation, binary coded decimal Message-ID: <300@spectra.COM> Date: 4 Jan 90 21:58:04 GMT References: <4658@ur-cc.UUCP> <4660@ur-cc.UUCP> <803@tuewsd.lso.win.tue.nl> <4679@ur-cc.UUCP> Reply-To: bseeg@spectra (Bob Seegmiller) Organization: Spectragraphics, Corp., San Diego, CA Lines: 58 In article <4679@ur-cc.UUCP> lowj_ltd@uhura.cc.rochester.edu (John Alan Low, aka "Travis" Low) writes: > > >In article <803@tuewsd.lso.win.tue.nl> wsinkees@lso.win.tue.nl (Kees Huizing) writes: >>>In article <4658@ur-cc.UUCP> I wrote: >>>> [deleted floating-point loop program text] >>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? > > [report of discovery that same program works under Turbo Pascal 3.0] > 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? BCD was (probably) used because the 80x86 processor has instructions that support BCD arithmetic, and then it goes in to really ancient history (8080 & business applications and, ... inaccuracies in floating-point arithmetic, plus speed penalties ... & & ). The 360 instruction set still supports BCD arithmetic, though whether it is still used I can't say (I haven't programmed 360's, just Concurrent Interdata processors, and the Interdata instruction set is similar to some version of the 360's -- and I'd never used that particular instruction in my work). I would guess it has big application in business/banking software where round-off would cause a hole in someone's account -- I was doing scientific work where round-off either didn't matter, or was minimized by appropriate algorithm design. > 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? > Umm, the Turbo Pascal 4.0 manual and .DOC files describe Borland's shift from BCD in ver 3.0 to a binary form (which format is described in the manual). Also, I do believe they warn in the manual against using floating-point loop control variables. Guess it pays to read them manual things once in a while. A text on numerical methods using computers would make interesting reading for those curious about just what floating-point numbers are (essentially an incompletely mapped representation of the real [as in set theory] number set). I found a good one when I was at Utah, same publisher and series(?) as Wirth's _Algorithms + Data Structures .._ book, but an author whose name I (sorry) can't remember. A really excellent reference. Now for the name ... anybody? -- /---------------------------------------+-------------------------------------\ | Bob Seegmiller | Spectragraphics Corp. 619-587-6912 | | "Till mermaids wake us..." - Eliot | 9707 Waples Street | | UUCP: ...!nosc!spectra!bseeg | Sandy Eggo, CA 92121 |