View previous topic :: View next topic |
Author |
Message |
Kimi
Joined: 30 Jan 2005 Posts: 23 Location: Argentina
|
Float Precision |
Posted: Fri Feb 04, 2005 11:54 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Kimi
Joined: 30 Jan 2005 Posts: 23 Location: Argentina
|
|
Posted: Fri Feb 04, 2005 12:31 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Fri Feb 04, 2005 1:14 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Kimi
Joined: 30 Jan 2005 Posts: 23 Location: Argentina
|
|
Posted: Fri Feb 04, 2005 1:44 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Feb 04, 2005 3:57 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|