On Mon, 2008-10-20 at 12:37 -0500, Danny Miller wrote: > Many beginners jump right into "floating point- yeah I need decimals". > But you'll find FP on a system with no Floating Point Unit is incredibly > slow. Hundreds of times slower (or worse). In fact there are plenty of > ways to work with decimals as "fixed point" that don't involve Floating > Point calcs. Like if you need a single digit to the right of the > decimal, just store the number as 10x larger than it is. 13.8=>138. > 13.8 + 1 becomes 138+10. One of the FIRST things I do when starting a new MCU project is defining what kind of math I need. Often this means figuring out the min and max values I'll have to deal with, the resolution I'll need, and how fast things need to be done. Then I go through all the formulas I'll be using, and hand optimize them, keeping in mind the min/max values that might be hit in the intermediate steps. I also introduce approximations in this step, if appropriate. For example if the sensor I'm using is non linear, but I'm only using it for a small range, I might approximate things with a linear function. It sounds like a lot of work, but in the end the code is SO much easier to write, plus you can catch ALOT of bugs before even writing a single line of code. FWIW I've never ended up needing to use FP on an MCU, sometimes I can get away with just integers, the rest of the time a "fixed point" type of math has been appropriate. TTYL -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist