LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bug? Two Doubles not detected as equal v8.6

I have dealt with this in C++, so to me it isn't new, but the strange part is this.

 

If I remove the shift-register value and instead wire in a constant double of 1.1 (lets say), and compare two 1.1 values, I get a TRUE.  It is when I compare the shif-register value that it never registers TRUE.

 

So, the question here is if given the precision problem, does labview treat a shift register differently than a constant?  I can work around this by rounding or using "Greater-or-Equal". 

0 Kudos
Message 11 of 33
(1,367 Views)
Can't deny this. But I have attempted to manipulate with the representation of the constants changing those between doubles and integers in different combinations I have also incremented the value which is checked while using "increment by one" and "add" + user defined constant functions. But still I was unsuccessful to make this comparison to fail.
---

While evaluating my code please have in mind that I am a LV novice. Therefore sometimes my code might violate some coding rules that I have to learn about myself. But how else could I do that... 🙂

Chart zoom with "Mouse Over" effect
0 Kudos
Message 12 of 33
(1,367 Views)

dre99gsx wrote:

Seriously?

 

If you're not going to contribute in a productive manner, why waste your time? 


Why waste our time by not searching the forums to see if a question like what you're asking has already been posted. Which it has. Countless times. 

 

I have very little patience for people who don't even bother to do a little bit of work on their own. Perhaps it's that I'm old enough to remember when there WASN'T an internet and people had to find answers the HARD way. Like research.

0 Kudos
Message 13 of 33
(1,364 Views)

Darin.K wrote:

 

Read the threads, integers are fine, there is an exact binary representation (except for 1 perhaps Smiley Wink ) , try something like 0.1.
Message Edited by Darin.K on 02-04-2010 02:05 PM

My bad. I am not used to such format like ".1". I have read it as "1". Sorry.

---

While evaluating my code please have in mind that I am a LV novice. Therefore sometimes my code might violate some coding rules that I have to learn about myself. But how else could I do that... 🙂

Chart zoom with "Mouse Over" effect
0 Kudos
Message 14 of 33
(1,352 Views)

dre99gsx wrote:

I have dealt with this in C++, so to me it isn't new, but the strange part is this.

 

If I remove the shift-register value and instead wire in a constant double of 1.1 (lets say), and compare two 1.1 values, I get a TRUE.  It is when I compare the shif-register value that it never registers TRUE.

 

So, the question here is if given the precision problem, does labview treat a shift register differently than a constant?  I can work around this by rounding or using "Greater-or-Equal". 


It is irrelevant whether you use a shift register or any other construct. Just because it happens to work without a shift register and it doesn't happen to work with a shift register is completely meaningless. You're still trying to perform an equality on floating point values.

0 Kudos
Message 15 of 33
(1,339 Views)

dre99gsx wrote:

I have dealt with this in C++, so to me it isn't new, but the strange part is this.

 

If I remove the shift-register value and instead wire in a constant double of 1.1 (lets say), and compare two 1.1 values, I get a TRUE.  It is when I compare the shif-register value that it never registers TRUE.

 

So, the question here is if given the precision problem, does labview treat a shift register differently than a constant?  I can work around this by rounding or using "Greater-or-Equal". 


 

Not at all strange and it has nothing to do with the shift register. It has everything to do with the add. You add an imprecise representation to another imprecise representation and .1 + .1 does not equal .2. You will have exactly the same problem in every other programming language.
0 Kudos
Message 16 of 33
(1,340 Views)

I don't think your issue is that you are using a shift register, but more a case where you are accumulating an error until it finally shows up.

 

You can do a comparison where 1 = 1,  but if you add some math and do a 1 /3 x 3, the result is not 1 but .99999.   Comparing constants is like the first case,  comparing the result of a calculation (adding .1 over and over again) is like the second case.  Adding .1 ten times does not yield a precise 1.

Message Edited by Ravens Fan on 02-04-2010 05:20 PM
0 Kudos
Message 17 of 33
(1,333 Views)

-------

It is irrelevant whether you use a shift register or any other construct. Just because it happens to work without a shift register and it doesn't happen to work with a shift register is completely meaningless. You're still trying to perform an equality on floating point values.

------ 

 

Great, I think that answers the question.   I was under the impression LabVIEW was being "smart" about this since it worked well in some odd cases.  When it suddenly didn't work, I began to rethink the operation.  I will probably subtract the two values and look for a few decimal place range of error to determine if the value is equal or not. 

 

Thanks for the input.

0 Kudos
Message 18 of 33
(1,322 Views)

I am supprised at the number of condesending people there are in the NI fourms... 

 

But by the way 

 

in matlab 

a = 0.5

b = 0.5

a==b will give 1 

a and b are both doubles.

 

labview is supposed to be a high level language like matlab and it would be expected this functionality is built in.

So clearly this is a grose oversite by NI I would expect this feature to be built in.

 

0 Kudos
Message 19 of 33
(877 Views)

I'm constantly amazed at how many people who don't unerstand computers try to program one. There is no GROSS oversight at all and I don't believe that matlab does anything differently. Your simplified example works in LabVIEW as well.

Message 20 of 33
(865 Views)