LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

comparison of 2 double values

Solved!
Go to solution

dear community,

please have a look at the simple code attached.

can anyone tell me why the boolean output is false?

the first contant is copied out of a larger code segment.

the value of the second constant is entered directly.

 

thanks in advance

 

 

0 Kudos
Message 1 of 8
(6,317 Views)

The comparisson pallete doesn't like dbl's.

If you want to compare some doubles who are 0,2 you have to multiply them with 10 infront.

And convert them to an integer.

comparisson.PNG

 

Integers do work!

 

---

UnCertified LabVIEW Student
Mistakes are for learning, that's why suggestions are always welcome!
0 Kudos
Message 2 of 8
(6,314 Views)
Solution
Accepted by labviewette

Maybe you need to display more significant digits to see that they are not equal.

 

 

There are many solutions, but you need to decide what is "close enough". 😄

 

(and, no, the solution given earlier is probably not sufficient unless you only care about one decimal digit)

0 Kudos
Message 3 of 8
(6,307 Views)
It's a very basic understanding of computers that equal comparisons of floating point numbers is a big no-no. It is due to the imprecise conversion to binary. This has been discussed numerous times.
0 Kudos
Message 4 of 8
(6,305 Views)

@KoenR94 wrote:

The comparisson pallete doesn't like dbl's.

If you want to compare some doubles who are 0,2 you have to multiply them with 10 infront.

And convert them to an integer.

comparisson.PNG

 

Integers do work!

 


DBLs "work" too, and perfectly at that. This has nothing to do with "does not like". There are no coercion dots, so the comparison operations "likes" DBLs just fine. 😄 (They just might not give you the answer you expect and you need to be aware of pitfalls as mentioned. :D)

 

What is the point of the while loop? just burn the CPU??? 

0 Kudos
Message 5 of 8
(6,294 Views)

does that mean, that if i enter a constant value of 0,20 that that value is in fact not 0,20 but a value somewhere in the tolerance range of the binary conversion ?

0 Kudos
Message 6 of 8
(6,290 Views)

Many simple decimal values (0.1, etc.) cannot be exactly represented in binary, others (e.g. 0.5) can.

 

You'll always get the closest possible binary value when entered manually, so if you enter 0.2 twice and compare, they are equal (but both not exactly 0.2). Of course if the value is a result of some computation, it might be slightly different.

Message 7 of 8
(6,288 Views)

DBLs "work" too, and perfectly at that. This has nothing to do with "does not like". There are no coercion dots, so the comparison operations "likes" DBLs just fine. :smileyvery-happy: (They just might not give you the answer you expect and you need to be aware of pitfalls as mentioned. :smileyvery-happy:)


 


Nice to know that! Wasn't aware of this.

 

 


What is the point of the while loop? just burn the CPU??? 


No just to show it was actually running Smiley Very Happy

Though burning CPU is fun too haha

---

UnCertified LabVIEW Student
Mistakes are for learning, that's why suggestions are always welcome!
0 Kudos
Message 8 of 8
(6,279 Views)