Reason for using BCD arithmetic

Robert Pearson BBUXEIPD at UIAMVS.BITNET
Fri Oct 21 23:37:18 AEST 1988


> Date: Tue, 4 Oct 88 22:59:18 pdt
> Message-Id: <8810050559.AA05017 at BOEING.COM>
> From: carroll%m211b at BOEING.COM (Jeff Carroll - BASC EM Staff)
> Subject: non-binary hardware?

> It's the same reason that Borland released a version of Turbo Pascal with
> BCD arithmetic - the fact (assertion?) that BCD arithmetic is impervious
> to roundoff error.
>
> I implore (and defer) to anyone who can explain why to do so.
>
> Nonetheless I assert that BCD arithmetic notwithstanding, the HP15C and
> the IBM PC are essentially binary machines.

     You are quite correct that BCD arithmetic has 'roundoff error', as all
'floating point' representations will have 'roundoff error' if the 'mantissa'
is exceeded.  However, when dealing with 'binary floating point' you have an
additional source of errors, converting between binary and decimal (BCD avoids
these errors by doing calculations in decimal).  It turns out that sometimes
these conversions can NOT be made exactly (the result is 'irrational' in the
other base) even if you have plenty of room in the 'mantissa'.  In these
cases, doing the calculation with BCD arithmetic will give an exact result,
but converting to 'binary floating point' will only give an approximate result
(because of the small amount of error introduced by the number 'base
conversion').  Some earily 'business' programs in BASIC suffered from this
very problem.  For some 'unknown' reason, the programs would occasionally be a
penny or two off ... needless to say, this can be a serious issue sometimes....



More information about the Comp.lang.c mailing list