PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 26, 2005 12:41 pm |
|
|
Not all decimal fractions can be represented exactly with the 32-bit
Microchip floating point format. Here is a program which will let you
experiment with this:
Go here:
http://www.piclist.com/techref/microchip/math/fpconvert.htm
Download this file:
floatconv10.zip
Open it with WinZip and drag the Floatconv.exe file onto your desktop.
Run it.
1. On the left side, select the Format: Microchip 32bit
2. In the top box for Float, enter: .01
3. On the right, click the button for Convert To Byte.
Notice that it fills in the values for BYTE1, BYTE2, BYTE3, BYTE4.
4. Press button for Convert To Float.
Notice that the top box now says: 0.00999999977648
This is the closest number to .01 that you can get with the Microchip
32-bit format.
You can test this. Go back, and put .01 in the top box. Press
Convert to Byte. Now go to the BYTE4 box. It has an 'A' in it.
Change it to a 'B' and press Convert to Float. The top box now says:
0.0100000007078
Compare those numbers:
A -- 0.00999999977648
B -- 0.0100000007078
The 'A' value is closer to .01, so it is the best approximation.
When you use this program, make sure that you always select
the proper format, which is: Microchip 32bit |
|