Showing results for 
Search instead for 
Did you mean: 

Less than symbol problems

Hello everybody,


ich have written a code, nothing special.


    if(Phi < 0.25)
        A = 1;


Now I have a problem. When I get a value Phi = 0.25, Lab Windows jumps into the bracket and writes A=1.

But that is not correct. 0.25 is not smaller, it is equal. Is this a failure of the program or have I forgotten something?


Best Regards

0 Kudos
Message 1 of 7

yes, you have forgotten something called numeric precision, see, e.g., here Smiley Wink

0 Kudos
Message 2 of 7

Ok thank you. But how can I solve the problem? I tried the solution in the othee topic but it didn't work.

0 Kudos
Message 3 of 7

Can you provide some more information about your input data such as the resolution of your measurement? How did you check the value of your number / with which CVI version (note that more recent versions have some limitations in debugging due to automatic rounding, see here)

0 Kudos
Message 4 of 7

This is a part of a calucation. I have a signal and that signal has a length from 1. And from 0-0.25 the signal has a positive Amplitude, so therefore I need to give aut a 1 and from 0.5 to 0.75 I have a negative ampltude, so I give out a -1. I get the comparitve value from another calucation as a double value.


When I transformed the double value into a int 

double Phi = 0.25 * 1000.0 ;

int a = Phi;  // 249


I got a int with the value 249. So the value got rounded. So this was not a option.


I used printf to show me the value. The first values are exactly the same 0.25 = 0.25, 0.5 = 0.5,... but after some time the value got this behavior 0.25 = 0.249500998 seen in the following.


I use the CVI Version 2015

0 Kudos
Message 5 of 7

Maybe this is not the answer you wanted to hear but...


- I would conclude that the main problem is not your initial comparison statement but some accumulating inaccuracies in your calculation, probably due to cumulative roundoff errors... but this is a common issue, when reading some books about numerical recipes you will find that for this reason many routines claim only 7 or 8 valid digits, even if done with double precision


- there is no simple answer. The usual approach for comparisons is sketched here (I had a more detailed link but can't find it right now, sorry)

0 Kudos
Message 6 of 7



thank you anyway. I thought so that there is a basic failure and I think it is really the calculation.


Best regards

0 Kudos
Message 7 of 7