LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search 1D Array not working with Double

Solved!
Go to solution
Can anyone tell why Search 1D Array function is not working as expected in the attached VI ?
Message Edited by ssingh1 on 26-04-2010 08:21 PM
0 Kudos
Message 1 of 9
(4,695 Views)

Please do a search on "equality", "LabVIEW", "floating point", "I found a bug in LabVIEW!", "LabVIEW can't do math!"

 

Also,  http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems.

 

The Search 1D Array works by performing equality comparisons.

 

I have another nickel in my retirement fund.

0 Kudos
Message 2 of 9
(4,685 Views)

Search 1D Array uses an "equal" as comparation. It is always a bad idea to compare floating point numbers with equal.

There are plenty of threads on this forum covering this issue. (example here).

This is not a LV issue (see here).

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 9
(4,683 Views)

The problem is the way floating-point numbers are represented in binary.  You can find many discussions on the subject of comparing two floating-point numbers on this forum.  One good explanation is at: http://digital.ni.com/public.nsf/allkb/B01682241DD825948625665100663F61

 

0 Kudos
Message 4 of 9
(4,682 Views)

Welcome to the world of floats and doubles. The precision is good, but not infinite giving these symptoms every so often.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 9
(4,675 Views)

The VI is right, btw. Increasing visible number of decimals you'll notice you compare 0,58723354278 to 0,587234 which will never be true.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 9
(4,666 Views)
Solution
Accepted by topic author ssingh1

Hi Singh,

 

The 2 numbers you have arent equal:

 

Number in array is actually: 0.5872335427799636, you can see this by altering the display format.

 

Its to do with how the double value is stored on the computer.

 

I use an array called 'Approx Equals' that compares numbers to a specified decimal place:

 

Find Double Match Snippet.png

 

I have attached the 'Approx Equals' vi. As said you can specify the accuracy of the comparison.

 

Rgs,

 

Lucither

 

 

 

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
Message 7 of 9
(4,663 Views)
Dear Friends,

Thank-you very much for your prompt replies explaining the reason for Search 1D Array not working accurately with doubles.

With regards
Shourya
Message Edited by ssingh1 on 27-04-2010 10:47 AM
0 Kudos
Message 8 of 9
(4,605 Views)
Dear Friends,

Thank-you very much for your prompt replies explaining the reason for Search 1D Array not working accurately with doubles.

With regards
Shourya
0 Kudos
Message 9 of 9
(4,605 Views)