Thursday, September 29, 2005, 10:12:44 PM, Dennis Cote wrote: > On 9/29/05, Darren Duncan <[EMAIL PROTECTED]> wrote: >[...] >>> 2. DECIMAL(p,s) - An exactly remembered fractional number that is >> typically stored in a form akin to text, such as one byte per base-10 >> digit. These can effectively store arbitrarily large numbers of any >> length and precision without loss of detail, although doing math with >> them may be slower. For example, if you store '2.5' in one, then >> '2.5' is actually stored.
> This can also be done with fixed point fractions. This type of scaled > integer with a fractional component are often used by integer DSPs. They > store a value in an integer with a fixed binary point (rather than a > floating binary point as implied by the name floating point). [...] For those still following this thread, and looking for more examples of the infinite representations of numbers ;-), here is another... Instead of a binary fixed point, you can use a binary number with an implicit decimal fixed point. For example, if your implicit decimal point were 10^2, the number 345 (stored as a binary integer) would represent the number 3.45. Concretely in C syntax, you'd print numbers as printf("%d.%02u", x/100, x%100). Addition and subtraction can be done with the integer operators. Multiplication and division take some care to avoid loss of range or precision, but abstractly, multiply is (x * y) / 100 and divide is (x * 100) / y. This is a neat hack to maintain fixed decimal accuracy with binary integers. > These values can also be stored as arbitrary precision integers, > which store multiple integers words to represent the value which can > again be interpreted as a fixed point fraction, or as BCD (binary > coded decimal) values which store 2 digits per byte. Storing numbers as *two* arbitrary precision integers, a numerator and a denominator, gives you all the exact rationals (at least as big as your memory allows -- reducing the numbers helps). Common Lisp and Scheme have rationals as well as real, complex, and arbitrary precision integer numbers. http://mathworld.wolfram.com/RationalNumber.html -- Doug Currie Londonderry, NH