LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Something strange about the"Search 1D Array" function,if there is some kind of bug of LabVIEW?

The Threshold 1D Array function solves the problem perfectly. You can convert to an I32 integer and it will round to the closest if there's not a match.

Threshold.PNG

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 11 of 25
(1,809 Views)

@billko wrote:


@Munna232 wrote:
Try to use "Threshold 1D Array" If search element is not exists in array, it gives nearest fraction Index.

This isn't going to work if you have instances where the next element is less than the one before it.  I guess you could sort the elements is ascending order, though.

 

I think that comparing integers is the better way to go because it is scalable and you can exactly the same comparison that you wanted to do in the first place.


 

Hi @billko ,

 

Thanks for reply.

 

As per @daed post, data is already in ascending order so I thought we can use Threshold 1D Array approach.

 

Munna
0 Kudos
Message 12 of 25
(1,797 Views)

If you want to make sure the search came up with an approximate exact match, you can do something like this:

 

Threshold Match.PNG

 

I expanded the indicators to show the rounding offsets. That's what you're dealing with when you work with DBLs building off of each other.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 13 of 25
(1,781 Views)

AHA, I found a project I had put togeher a while back based on expansion of code found on the forums

Equal SGL.png

I am showing this example for the documentation referances

the whole project with polymorpic vis for =, <= and >= (SGL, DBL and EXT instances) is attached


"Should be" isn't "Is" -Jay
0 Kudos
Message 14 of 25
(1,753 Views)

@James.M wrote:

The Threshold 1D Array function solves the problem perfectly. You can convert to an I32 integer and it will round to the closest if there's not a match.

Threshold.PNG


While I do agree that this does solve the perceived problem, the actual problem is that the OP did not understand the issues associated with floating point numbers; therefore, I believe the "brute force" method of comparing floating point numbers is more appropriate in this case, as the "brute force" method teaches the OP how to handle floating point comparisons in general.

 

Wow, how's THAT for a run-on sentence???

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 15 of 25
(1,730 Views)

@JÞB wrote:

AHA, I found a project I had put togeher a while back based on expansion of code found on the forums

Equal SGL.png

I am showing this example for the documentation referances

the whole project with polymorpic vis for =, <= and >= (SGL, DBL and EXT instances) is attached


Wow!  That's ummmm... pretty involved.  It's more like a debate on what "equal" really means, not a straight "yes" or "no" answer.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 16 of 25
(1,710 Views)

@JÞB wrote:

AHA, I found a project I had put togeher a while back based on expansion of code found on the forums

Equal SGL.png

I am showing this example for the documentation referances

the whole project with polymorpic vis for =, <= and >= (SGL, DBL and EXT instances) is attached


 

 

Related to this, whats the benefit of this approach? When comparing floating point numbers for equality I've been using the following, is this incorrect?

 

Float Point Compare.png

0 Kudos
Message 17 of 25
(1,696 Views)

OEM_Dev wrote:

 

Float Point Compare.png


Related to this, whats the benefit of this approach? When comparing floating point numbers for equality I've been using the following, is this incorrect?
Yes. For example of you would compare 1e-30 and 1e-40, your code would say they are equal, even if they are 10 orders of magnitude different. 😄

 

Message 18 of 25
(1,682 Views)

I suppose that's what I get for trusting inherited code, not that I frequently check floating point numbers for equality. I did find a rather interesting article that seems to explain why someone before me did it that way and why I should not continue to follow it

 

http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

0 Kudos
Message 19 of 25
(1,667 Views)

Hello OEM_Dev

 

You might want to try something like this. Just enter the precision desired!

 

compare floats.png

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding. Proverbs 4:7
0 Kudos
Message 20 of 25
(1,649 Views)