Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: bcd arithmetic
Posted:
Jun 17, 1996 1:54 PM


In article <4phmie$c0i@news.microsoft.com>, Dann Corbit <acnadc@microsoft.com> wrote: >In article <hpa.31ba9c8e.I.use.Linux@freya.yggdrasil.com>, hpa@freya.yggdrasil.com says... >>FINANCIAL DATA ARE INTEGER DATA, THE UNIT OF WHICH IS THE SMALLEST >>AVAILABLE CURRENCY UNIT. >> >>In other words: for U.S. currency, you keep track of cents. Not >>dollars. Cents. >> >This approach works in simplistic terms, for instance, when you are adding >two amounts. But how do you figure tax using only integers? If you >use only integer types, how do you figure interest, which is an exponential? >You are back to using floating point in either case, which never eliminates >the problem. > >All real world accounting systems have to deal with noninteger amounts at >some point in the calculation stream.
To handle numeric data of this type, you need fixed point arithmetic, not integer arithmetic. Decimal fixed point arithmetic keeps the decimal (not binary) point a fixed number of digits from the right end of the field. It uses decimal arithmetic rules for rounding and truncation. Integer arithmetic is a special case of fixed point arithmetic, with zero digits to the right of the point.
Fixed point numbers can be represented in any numeric format. The "trick" to dealing with them correctly is in doing the correct rounding, truncation, and scaling after *each* operation. Since many of the computers we use do not have decimal fixed point arithmetic built into the hardware, it becomes a software exercise (that is often done incorrectly by those who don't understand all the implications).  Michael D. Shapiro, Ph.D. Internet: mshapiro@nosc.mil Code 4123, NCCOSC RDT&E Division (NRaD) San Diego CA 92152 Voice: (619) 5534080 FAX: (619) 5534808 DSN: 5534080



