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 support@ccsinfo.com

Float Precision

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



Joined: 30 Jan 2005
Posts: 23
Location: Argentina

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

Float Precision
PostPosted: Fri Feb 04, 2005 11:54 am     Reply with quote

Hello

First of all, thanks very much to everybody... this forum is great...

Now let's go to the problem... I'not getting enough precision in floating points maths...

x1 = -34.61084;
f1 = 12.44 * x1;
after this we expected f1 = -430.5588496, but we watch f1 = -430.558830

this is just the begining...as we continue doing maths with this floats, errors become biggers...

f1 = f1 + 110574; //just adding a number

Expected f1 = 110143.4411504 -- calculated by Pic f1 = 110143.438726

Is there any way to double the Floating point precision? or at least increase it... Is this a compiler limitation, or a MCU limitation?

Thanks very very much
Kimi
Kimi



Joined: 30 Jan 2005
Posts: 23
Location: Argentina

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Fri Feb 04, 2005 12:31 pm     Reply with quote

I found that the printf is wrong...

dist1 = 110143.4411504;
fprintf (PC," %f ",dist1);

this should return 110143.4411504 but I see 110143.432021 in the PC.
anybody could solve this problem?

Thanks
Kimi
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri Feb 04, 2005 1:14 pm     Reply with quote

The floating point format used by CCS has 6.5 significant digits. It's a 32 bit float not as much percision as used in most PC software.
Kimi



Joined: 30 Jan 2005
Posts: 23
Location: Argentina

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Fri Feb 04, 2005 1:44 pm     Reply with quote

Thanks

Is there any usefull way to display the 4 bytes that compose the float into screen... first to check the operation, second to be able to send a float though the serial or spi port.

Thanks

Kimi
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Feb 04, 2005 3:57 pm     Reply with quote

If you make a pointer to the float you can print the bytes in hex.
My advice is not to use floats unless you really REALLY have to. I measure temperature all the time in integer millidegrees. A while back I was measuring warping in ship hulls in 24bit integer 1/10 millimeters. I could measure everything from the thickness of the paint to the length of a supertanker. I used string functions to convert the results to meters for printing.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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