Path: utzoo!attcan!uunet!cs.utexas.edu!usc!apple!agate!shelby!portia!dhinds From: dhinds@portia.Stanford.EDU (David Hinds) Newsgroups: comp.lang.pascal Subject: Re: Problem in Turbo Pascal 4.0 Summary: BCD arithmetic is DOG SLOW Keywords: Nonterminating Repeat loop, real, representation, binary coded decimal Message-ID: <8218@portia.Stanford.EDU> Date: 13 Jan 90 19:35:00 GMT References: <4658@ur-cc.UUCP> <4660@ur-cc.UUCP> <803@tuewsd.lso.win.tue.nl> <4679@ur-cc.UUCP> Sender: David Hinds Organization: Stanford University Lines: 18 In article <4679@ur-cc.UUCP>, lowj_ltd@uhura.cc.rochester.edu (John Alan Low) writes: > Is there some reason [BCD] representation is not common practice? BCD arithmetic is SLOW! It is hard to manipulate BCD-format numbers, because at the assembly language level for almost all computers, there are only instructions for doing binary arithmetic. Doing BCD arithmetic is a real pain - the result of every fundamental binary operation has to be corrected to restore it to BCD format. BCD numbers are typically stored as two 4-bit digits per byte, so they also waste space, because only values of 0 to 9 are allowed for each 4-bit digit. So, a binary number of a given number of bits has a higher precision than a BCD number occupying the same space. I haven't timed Turbo's BCD support vs. normal real's, but I would expect the BCD stuff to run maybe 1/2 as fast for addition and subtraction, maybe 1/10 as fast for multiplication and division, and even worse for transcendental functions. -David Hinds dhinds@portia.stanford.edu