LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Rashek

Equal to -1 function

Status: New

When working with arrays, it is convention that search functions output -1 when element is not found. There are several functions using this logic. I find myself quite often using "Equal" function to compare this value to -1. While not being overly complicated, considering I do it very often, it would still be nice to have function "equal to -1" which would work similarily to "equal to 0", having only one output.

Current approach:

Rashek_0-1575453021315.png

Suggestion ("equal to -1" icon is only illustratory):

Rashek_1-1575453212574.png

Purpose: Speeding up programming routine

7 Comments
drjdpowell
Trusted Enthusiast

I just use the "less than zero" primative, as for every case where -1 is used as the equivalent of "not found", other negative numbers are never returned.

Intaris
Proven Zealot

Except for "scan String for tokens" which can return -1or -2.

wiebe@CARYA
Knight of NI

Sounds like a 2 minute job using a malleable VI? 

altenbach
Knight of NI

Most of the time,alternative code needs to follow if something is "not found" and I typically just wire that output to a case structure with "-1" and "default" as the only two cases. And yes, for functions that can also return other negative sentinel values, just add more cases if really needed. 😄

donkdonk
Member

Generally, I also just use the "less than zero" primitive.

Alternatively, a case structure with "-1" is often useful as altenbach pointed out.

 

No need for a -1 primitive. Sorry no kudos.

 

AristosQueue (NI)
NI Employee (retired)

> Sounds like a 2 minute job using a malleable VI? 

 

Actually surprisingly tricky.

 

The easy step: File >> New... >> Malleable VI

 

But then the obvious idea:

Untitled.png

Is going to give you a coercion dot for some data types, which would be a notable performance hit when you wire with an array of numerics or a subelement of a cluster.

 

Similarly, this implementation is going to create a data copy, so same problem for arrays:

Untitled.png

 

The correct implementation:

Untitled.png

This version forces the coercion to be on the constant, never on the variable, so the coercion is done at compile time (constant folding).

wiebe@CARYA
Knight of NI

>The correct implementation:

 

Ok, not trivial, but still a 10 minute job (for you that is)?

 

Too bad we can't post attachments over here...