View previous topic :: View next topic |
Author |
Message |
Simone
Joined: 23 Oct 2012 Posts: 4
|
Float number problems |
Posted: Sat Nov 03, 2012 3:20 am |
|
|
Hi,
I'm using CCS PCD C Compiler for PIC24EP512GU810.
I've a problem with float number operations. Here an example inside a function:
Code: |
float vAOUT1 = -8.3
float p = 10.0F - vAOUT1;
if (p < 0.0F) // p is 1.7, but it return FALSE
return(FALSE);
|
Can someone help me? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sat Nov 03, 2012 3:42 am |
|
|
Critical question is always 'compiler version'....
Do a search on the forum, for 'PCD float', and select to include all terms.
If you must do a float comparison, use float48, which seems to be more reliable than the default.
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Nov 03, 2012 3:45 am |
|
|
p is NOT 1.7
If vAOUT1 is -8.3 then
10 - vAOUT1 becomes
10 - -8.3 = 18.3
Can't help with the rest.
Mike |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Nov 03, 2012 4:12 am |
|
|
The code is working correctly with recent PCD versions (skipping return FALSE), tested with V4.127 and 4.135. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sat Nov 03, 2012 5:23 am |
|
|
Yes, to Mike, I too had spotted the error in the number involved, but the result should still be false.
Yes, on versions. It was a sequence around the early 4.1xx area, where oddities appeared with this type of test, was fixed, then appeared again, over a number of compilers. Hence the critical 'what version' question.
Had some code that had to be 'bodged' to work correctly round then, and it seems to be fine for the last few compiler versions, so agree it does not now apply.
Best Wishes |
|
|
|