Daniel Fischer wrote:
Arjen,

There is no precise conversion from base 2/4/8/16 representation to base 5/10 representation when you have digits after the (decimal, binary) point.

That's why base 2 representation just can't be used.


Can you give an example of this?

Generally, in a base-n numeral system, any fraction can be represented either as a real number with a finite number of digits after the radix point, or a real number with an infinitely recurring pattern at the end. Fractions whose denominator can be expressed in terms of the prime factors of the base belong to the first set and all other fractions belong to the second set.

Since 10 has more prime factors than 2, some of the fractions that can be expressed with a finite number of digits after the point in base-10 fall in the other set in base-2, such as 0.1 ^= 1/10 = 1/2*5 =~ 0.0_0011 in binary (the underscore is meant to mark the beginning of the recurring portion of the digits after the binary point).

This means that you can't use a binary floating point format such as an IEEE float to store decimal numbers. I think that's not really what was suggested, though, as you would usually store a numerator and a denominator instead of a binary real number. Typically, the denominator would be a power of ten and chosen so that all the significant digits of the number are contained in the numerator. In other words, you store a string of digits and the position of the decimal point. When you do this, the whole problem goes away.

When I was in high school, I programmed summers for a TV rating company. One day, I noticed a piece of code (360 assembler) that converted each of two numbers in registers to packed decimal, added the packed decimal numbers, then converted the packed decimal back into a register. I asked the guy who originally wrote the code what that as all about. "Oh," he said, "the numbers were actually decimal numbers so they had to be added in decimal."

Oh, well.

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to