CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

newbie in float

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 26, 2005 12:41 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group