04-18-2016 08:17 AM
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
04-18-2016 08:54 AM
yes, you have forgotten something called numeric precision, see, e.g., here
04-24-2016 11:36 PM - edited 04-24-2016 11:38 PM
Ok thank you. But how can I solve the problem? I tried the solution in the othee topic but it didn't work.
04-25-2016 12:56 AM
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)
04-25-2016 01:42 AM - edited 04-25-2016 02:01 AM
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
04-25-2016 02:49 AM
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)
04-25-2016 04:26 AM
Hello,
thank you anyway. I thought so that there is a basic failure and I think it is really the calculation.
Best regards