Olin Lathrop wrote: > Kerry Wentworth wrote: >> Please pardon my ignorance, I'm here to learn. Is 10.6 arithmetic >> something that everybody but me uses? Is it an assembly language >> thing? >=20 > Fixed point in general is commonly used on small systems like PICs.=20 > 10.6 format is just one example, which has 6 fraction bits in a 16 > bit number. Fixed point is common when you need to represent > fractional values but have a integer arithmetic processor. It's more > tricky than floating point because you have to keep track of where > the imagined binary point is.=20 >=20 > One way to think of floating point is that it stores the binary point > information in the number, and updates everything accordingly at run > time. That takes more hardware, which small processors like PICs > don't have.=20 >=20 >> I use a C compiler almost exclusively. >=20 > There's the problem. Wake up and smell the bits. It is difficult to > understand what is really going on if you keep a compiler between you > and what is really going on.=20 I disagree that using a C compiler is a problem. IMO the difficulty in understanding fixed point math is about the same either way. (IMO it's actually easier in C, because you're less sidetracked by other issues.) IMO it is also not about smelling the bits, it is about understanding the principle, and you don't even need a processor for this, whether programming it in assembly or C; a sheet of paper (and a head) is all you need. I think the (one) key to understanding fixed-point math is to understand units. Most are used to deal with numbers and not consider units, or consider them only at the output, where the units appear like magic. IMO this is generally not a good idea, but the absence of units makes itself most notable when dealing with fixed-point math. Just pin an appropriate unit to each number, and it all will solve itself. The units of course usually contain a scaling factor, and you need to carry units through operations properly. In the simplest case -- and this is enough to understand fixed-point math --, the unit is just a scaling factor. Say you have numbers with 4 (binary) digits to the right of the binary point, then their unit is [1/16]. Adding two such numbers leaves the unit [1/16], using simple math rules: (A * [1/16]) + (B * [1/16]) =3D (A + B) * [1/16]; The operation (A + B) is done by the processor, the rest happens on your sheet of paper. Multiplying two such numbers makes the unit of the result [1/16] * [1/16] =3D [1/256], again using the same simple math rules: (A * [1/16]) * (B * [1/16]) =3D (A * B) * ([1/16] * [1/16])=20 =3D (A * B) * [1/256]; The operation (A * B) is done by the processor, the rest is implicit in the design of the algorithm. Now if for some reason you need the result with a unit of [1/16], you know what to do... you need to divide by 16: C * [1/256] =3D C/16 * [1/16]; Brining the last two calculations together, the complete multiplication of two numbers with the unit [1/16] resulting in a number with a unit of [1/16] becomes: (A * [1/16]) * (B * [1/16]) =3D (A * B / 16) * [1/16]; (A, B and C are integer variables of any suitable size.) This could get you started. Just carry always the unit along, helpfully marked with e.g. brackets "[]", when you design your algorithm, and the actual arithmetic will all be integer and you won't even know that you're doing fixed-point math -- until you see that it's exactly this what it is :) The advantage of this approach is that it all reduces to simple math that can be easily executed on a sheet of paper, no magic with smelling bits and dead chickens necessary. Gerhard --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .