Kevin Bealer wrote: > == Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article > ... >> It may be that you would still end up with situations where two values that >> you >> would think would be the same aren't due to rounding error or whatnot. >> However, >> with a fixed point value, you wouldn't have the problem where a particular >> value >> could not be held in it even if it's within its range of precision. As I >> understand it, there are a number of values which cannot be held in a >> floating >> point and therefore end up being rounded up or down simply because of how >> floating points work and not because there the precision isn't high enough. >> >> It's definitely true however, that using fractions would be much more >> accurate >> for a lot of stuff. That wouldn't be particulary efficient though. Still, if >> you're >> doing a lot of math that needs to be accurate, that may be the way to go. >> >> - Jonathan M Davis > > Floating point numbers are a good compromise for a lot of purposes, but yeah > they > are limited. Here are some ways to open up the limits a bit... > > (First some math for those who haven't gone down this path...) > > The reason that fixed point does better than floating is that fixed point > classes > use base ten and floating point uses base 2. In base two, all fractions that > have > a denominator of a power of 2 can be represented (e.g. 3/16) exactly, and all > others > can't. > > Fixed point solves this for numbers like .1 or .0003 because the denominator > is a > power of ten. Ten is 5*2 and the way it works is that any denominator that > is a power > of two times a power of ten can be represented exactly. > Wrong. There is nothing that says fixed-point uses a power of ten. Actually, I do a lot of work on embedded platforms without a FPU and with slow integer division (and to a lesser extent multiplication). Non-integer numbers are represented in fixed point (to work around the lack of FPU) using base 2 (so that adjustments only require a bitwise shift). Of course, this means that 0.1 cannot be represented exactly...
Jerome -- mailto:jeber...@free.fr http://jeberger.free.fr Jabber: jeber...@jabber.fr
signature.asc
Description: OpenPGP digital signature