Most fixed-decimal values cannot be represented precisely as binary floating-point numbers, no matter what the precision, because 1/10th is an infinite repeating fraction in binary. Unless the number is an integer divided by a power of two, you'll get some sort of truncation error.
Kinda makes me long for the days of BCD arithmetic on an old Motorola 6502c -- there was a chip that knew how to handle base-10 arithmetic! *g*
Seriously, though, it makes me wonder about constructing a "BCD-based float" object; the significant digits are stored in BCD (binary coded decimal, for those of you too young to remember) format, and the exponent is stored as a signed short -- you'd get 11 digits of precision out of a packed 8-byte structure. The unfortunate part is that you would have to emulate the BCD arithmetic in software, increasing the computation times considerably.
hehehe just to be picky, one more thing: Tilly said there were a "finite number" of exceptions. If you want, I can demonstrate that the number of exceptions (ie. the number of reals without terminating base-2 representations) is not only infinite, it is also uncountable. *g*
Spud Zeppelin * spud@spudzeppelin.com
| [reply] |