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 CCS Technical Support

if doesn´t work

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



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

if doesn´t work
PostPosted: Thu May 10, 2012 5:00 am     Reply with quote

Hello,

It´s frustrating: is there any reason why the "if" command jumps in when the value GY_SUMME[0] in the watch is 0?

Code:


float            GY_SUMME[5];


         if (GY_SUMME[0] == 100)
            {
            strcpy (TEXT, "I");
            TEXT_7x8_schreiben (72,11);
            }


Version is 4.132 Pic 24FJ128GA106
SherpaDoug



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

View user's profile Send private message

PostPosted: Thu May 10, 2012 5:53 am     Reply with quote

I might try either of these:

if (GY_SUMME[0] == 100.0)

if ((int)GY_SUMME[0] == 100)
_________________
The search for better is endless. Instead simply find very good and get the job done.
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Thu May 10, 2012 6:41 am     Reply with quote

Hello,

the second one
Code:
if ((int)GY_SUMME[0] == 100)


works, but not the first one? Why? I never had to do that before in older compiler versions...
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu May 10, 2012 7:44 am     Reply with quote

Two comments.

- Float compare for equality can easily fouled by rounding errors. You should better avoid it.

- If you want others to reproduce and possibly solve the problem, post a small compilable test program that shows it.
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Thu May 10, 2012 9:31 am     Reply with quote

Hello,

rounding errors are no problem as I want to compare with a >
The code above was just for example.

It works now with

Code:
if ((int)GY_SUMME[0] > 100)


So it´s o.k. for me- I was just again wondering...
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu May 10, 2012 12:16 pm     Reply with quote

In some cases CCS made changes like this to be more ANSI compliant.
_________________
Google and Forum Search are some of your best tools!!!!
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