From: Mark Swayne <mark.swayne@ch...>  20041214 23:14:35

Vikram, I agree with Rod, fixed point is definitely the way to go. Some things you may want to keep an eye on as you write your code: 1. Make sure you handle negative numbers properly. If the stuff to the left of the nominal decimal point is negative, so must the stuff to the right. For an 8 bit implementation, using 4 bits.4 bits 1.25 = 0001 0100 1.25 = 1110 1100 NOT CORRECT 1110 0100 2. Don't overflow/underflow when you multiply and divide. There's some goofing around with the offsets when you write these operations. Be careful. Test for accuracy with numbers that are close to 0, like 0.01. 3. Make sure you handle numbers between 0 and 1 correctly. 4. Remember that fixed point values will not be precise, just like floating point. Instead of looking for a specific value, look for a valid range. Depending on your encoding, 25 * 0.2 may not be exactly 5. Good luck! mark Rod Boyce wrote: > All, > > I have been following this thread for a while and have been temped to > say this before but now is the correct time. Floating point math in > an 8bit micro is wasteful especially and 89C2051 ;) . I was going to > suggest this a while ago but most people don't like hearing it you > should be looking in to fixed point arithmetic but it is going to > require a bit of though on your part to figure out the biggest and > smallest number your program should have to deal with and then over > and under flow checking. I did a quick google for some info and there > is a ton of it this is the first hit and it has a very good > explanation http://www.gameprogrammer.com/4fixed.html. > I have been working with micro's for a number of years and I have yet > to find a reason other than laziness to use a floating point library. > They are usually full of bugs anyway I mean no disrespect to the SDCC > version I have never used it. What you need to decide is how many > digits after the decimal point you can deal with. Then figure out how > many bits you need to represent that. Anyway there is no need for me > to repeat what has been said else where. I will also say that on > micros you usually end up witting the result of your floating point > sums into an integer register so just figure out the largest and > smallest number you need to deal with and then do integer math. It is > very simple and very space efficient. when the time comes to print > out your result just remove the noninteger part and print the integer > and then print the noninteger part very simple. You should not be > using printf either if you are working on a 2051 that will give you > lots more room for your code but that is another story altogether. > > Regards, > Rod Boyce. > 