View previous topic :: View next topic |
Author |
Message |
richi-d
Joined: 28 Aug 2007 Posts: 106
|
if doesn´t work |
Posted: Thu May 10, 2012 5:00 am |
|
|
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
|
|
Posted: Thu May 10, 2012 5:53 am |
|
|
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
|
|
Posted: Thu May 10, 2012 6:41 am |
|
|
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
|
|
Posted: Thu May 10, 2012 7:44 am |
|
|
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
|
|
Posted: Thu May 10, 2012 9:31 am |
|
|
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: 1933 Location: Norman, OK
|
|
Posted: Thu May 10, 2012 12:16 pm |
|
|
In some cases CCS made changes like this to be more ANSI compliant. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
|