# LabWindows/CVI

cancel
Showing results 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

Message 1 of 7
(4,097 Views)

## Re: Less than symbol problems

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

Message 2 of 7
(4,094 Views)

## Re: Less than symbol problems

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

Message 3 of 7
(4,015 Views)

## Re: Less than symbol problems

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)

Message 4 of 7
(4,004 Views)

## Re: Less than symbol problems

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

Message 5 of 7
(3,999 Views)

## Re: Less than symbol problems

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)

Message 6 of 7
(3,985 Views)

## Re: Less than symbol problems

Hello,

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

Best regards

Message 7 of 7
(3,976 Views)