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

PCD float seems to be not working right

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



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PCD float seems to be not working right
PostPosted: Tue Aug 21, 2012 7:40 am     Reply with quote

I´m using PIC30F5013 and PCD compiler Version 4.124

floats seems not to be working right.

Code:
float ttt=0,ttt1=1,ttt2=2;
while(true) {     
   delay_ms(1);
   if (ttt>ttt1) {
      liga(O_M3);   //The uC enters here. It is wrong!
      delay_ms(1);  //  :(
   }
   else {
      desl(O_M3);
      delay_ms(1);
   }
}

Sad Sad

Some suggestions?
Very thanks
_________________
Eduardo Guilherme Brandt
Ttelmah



Joined: 11 Mar 2010
Posts: 19347

View user's profile Send private message

PostPosted: Tue Aug 21, 2012 8:00 am     Reply with quote

If the numbers are going to be integers, use integers instead....
Float comparisons have had 'intermittent' problems with PCD for quite a while.
<http://www.ccsinfo.com/forum/viewtopic.php?t=43918&highlight=pcd+float>
Several other examples as well.
Much safer to use scaled integers for example, and quicker as well.

Best Wishes
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PostPosted: Tue Aug 21, 2012 8:17 am     Reply with quote

Thanks Ttelmah.

But floats are essential for my program. I do intensive fractional math calcs.
It have had already worked in the past, as it is.
Could it be a compiler version problem?

Thanks
_________________
Eduardo Guilherme Brandt
Ttelmah



Joined: 11 Mar 2010
Posts: 19347

View user's profile Send private message

PostPosted: Tue Aug 21, 2012 8:46 am     Reply with quote

It appeared to work quite some time ago, but has been 'wrong' for various compilers for quite a while.
Seriously though I can't really envisage that you 'need' float comparisons. If you know the likely range of the numbers, much better to use scaled integers. If you just want to do a comparison, then convert the floats to integer for the comparison. So:
Code:

float ttt=0,ttt1=1,ttt2=2;
while(true) {     
   delay_ms(1);
   if ((int32)(ttt*100)>(int32)(ttt1*100)) {
      liga(O_M3);   //The uC enters here. It is wrong!
      delay_ms(1);  //  :(
   }
   else {
      desl(O_M3);
      delay_ms(1);
   } 

Gives a 2 decimal place integer comparison, which does work.

Moan at CCS, but this has been happening off and on for several versions. You might want to see if the behaviour is the same with another type (float48 for example). I'd write 'round it' as being safer than relying on any CCS fix at present.

Best Wishes
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PostPosted: Tue Aug 21, 2012 9:02 am     Reply with quote

yes, its the only solution.

thanks
Eduardo
_________________
Eduardo Guilherme Brandt
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PostPosted: Tue Aug 21, 2012 10:08 am     Reply with quote

float48 is working fine also.

thanks
_________________
Eduardo Guilherme Brandt
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Aug 21, 2012 1:37 pm     Reply with quote

I don't see the float compare error in present PCD V1.35.
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