C needs BCD -- why BCD? Accountants!
Geoff Kuenning
geoff at desint.UUCP
Sun Nov 18 10:11:39 AEST 1984
> I have always been surprised that business people didn't just use 64
> bit integers, and keep the amounts in CENTS. No BCD required, can
> take advantage of nice fast machine instructions, etc.
Primarily because there are *still* relatively few machines that have good
support for 64-bit integers. The average 32-bitter has 32x32 multiply that
produces 64 bits, and a corresponding 64/32 divide, but other 64-bit math
has to be implemented with "add with carry" instructions. If I recall
correctly, the 360 didn't even have such an instruction, so you really had
to hack it. The 2-3 instruction sequences needed to perform 64-bit
arithmetic are not really more efficient than single BCD instructions.
Furthermore, many business programs (e.g., general ledger or accounts
receivable update) have a general model of "read in two fields, add them,
write it out". You can do a BCD add *much* faster than you can do two
conversions and a 64-bit binary add. Remember that decimal conversion
inherently involves multiplication and division.
--
Geoff Kuenning
First Systems Corporation
...!ihnp4!trwrb!desint!geoff
More information about the Comp.lang.c
mailing list