Re: Floating Point Approximations.



Marshall wrote:

On Mar 29, 12:42 am, "David Cressey" <cresse...@xxxxxxxxxxx> wrote:

Two points on BCD math:

I find BCD rather interesting.

Some years ago, a colleague and I spent some time thinking about
BCD formats. In general, I think the term BCD connotes putting
one decimal digit into four bits, but I think that usage is not
universal.

I think the term "binary coded decimal" is rather self-describing as base 10 encoded in binary.


1 base 10 digit into 4 base 2 digits is wasteful. We can consider
putting different numbers of digits into a different number of bytes
to minimize the waste. In particular, 3 decimal digits fits nicely
into 10 binary digits, and three sets of 10 binary digits fits nicely
into a 32 bit word. Thus we can fit 9 digits into 32 bits whereas
we could only do 8 digits with standard BCD.

2^10 = 1024
10^3 = 1000

Pretty close.

I am not sure what the name for base 1000 is. Millimal, maybe? Wouldn't the above be BCM?


Another big advantage to BCD is the ease of converting to and
from string formats. With 10 bit BCD, the lookup table is
1000 bytes instead of 10 bytes. Although the factor is larger,
the total number of bytes is trivial so it doesn't matter. (Total
cost of 1000 bytes of RAM = approximately epsilon cents.)
(Quick back-of-the-envelope shows it cost more than I thought:
approx .00013 dollars.)

Using a larger number of decimal digits at once means that
operations are more efficient because they can do more at
once. For example, you can convert 3 digits to/from ascii
at once instead of 1. You can multiply three digits instead of
one. Etc.

An amusing diversion.

I frequently encode things using weird bases--especially if I think a human will ever have to type in a large meaningless number. I try to use a set of familiar characters that users will not mistake. For example, I would not use both 5 and S or 0 and O--a trick I learned on a project at a company that deals with a lot of money.
.



Relevant Pages

  • Re: Floating Point Approximations.
    ... I find BCD rather interesting. ... BCD formats. ... 3 decimal digits fits nicely ...
    (comp.databases.theory)
  • Re: how do I get more numbers past the decimal?
    ... Other common formats are 64 ... So for the multi precision arithmetic, ... This page makes it seem like there are several variations on BCD: ... Intel chips also support bcd natively, but only up to 7 or 8 digits. ...
    (comp.lang.php)
  • Re: Fast Binary to BCD method on ARM9 with huge numbers?
    ... The legacy codebase works in BCD, ... I also need all the digits, ... For a simple improvement, instead of dividing my ten, divide by ... If you've got an ARM with long multiplies, ...
    (comp.arch.embedded)
  • Re: HPGCC 2: sat_decode_real
    ... > double with unknown contents in the last digits. ... > BCD to binary conversion. ... What I'm getting at is that this BCD to ... if and when comparing with numbers obtained from stack. ...
    (comp.sys.hp48)
  • Re: Price Data Formatting
    ... data will be of the correct format. ... note that MOST have 4 digits following the decimal point. ... digits MOST of the data items used. ... MAXIMUM number of decimal digits in the data list. ...
    (microsoft.public.vb.general.discussion)