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 number problems

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



Joined: 23 Oct 2012
Posts: 4

View user's profile Send private message

Float number problems
PostPosted: Sat Nov 03, 2012 3:20 am     Reply with quote

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: 19368

View user's profile Send private message

PostPosted: Sat Nov 03, 2012 3:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Nov 03, 2012 3:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Nov 03, 2012 4:12 am     Reply with quote

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: 19368

View user's profile Send private message

PostPosted: Sat Nov 03, 2012 5:23 am     Reply with quote

Yes, to Mike, I too had spotted the error in the number involved, but the result should still be false. Smile
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
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