[comp.lang.c] Reason for using BCD arithmetic

BBUXEIPD@UIAMVS.BITNET (Robert Pearson) (10/21/88)

> Date: Tue, 4 Oct 88 22:59:18 pdt
> Message-Id: <8810050559.AA05017@BOEING.COM>
> From: carroll%m211b@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....

gwyn@smoke.BRL.MIL (Doug Gwyn ) (10/23/88)

In article <8810211335.AA19348@ucbvax.Berkeley.EDU> BBUXEIPD@UIAMVS.BITNET (Robert Pearson) writes:
>     You are quite correct that BCD arithmetic has 'roundoff error', as all
>'floating point' representations will have 'roundoff error' if the 'mantissa'
>is exceeded.

That is incorrect.  Not all so-called "floating point" schemes have fixed
significand size, and some (including those using variable-length BCD
strings) are able to represent results of arithmetic operations exactly.
A BCD-based one will have problems with division, but that is not usually
commercially significant (whereas the errors introduced by use of normal
flotaing-point hardware is).

850347s@aucs.UUCP (Hume Smith) (11/09/88)

In article <8737@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <8810211335.AA19348@ucbvax.Berkeley.EDU> BBUXEIPD@UIAMVS.BITNET (Robert Pearson) writes:
>>You are quite correct that BCD arithmetic has 'roundoff error'.
>>That is incorrect.  Not all so-called "floating point" schemes have fixed
>>significand size, and some (including those using variable-length BCD
>>strings) are able to represent results of arithmetic operations exactly.

I was about to say: Even sqrt(2)? arctan(1)? exp(1)?  but then I realised
these aren't EXACTLY arithmetic operations.  Can someone clarify?

>
>