LabVIEW Idea Exchange

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

Even/Odd? comparison primitive

Status: New

I tend to use the Quotient and Remainder for determining whether a number is even or odd. It clutters up the block diagram with the primitive, a constant, and a comparison.  How about one (or two) of those nifty little triangles with a number in and a boolean out to indicate if the number is even (or odd)?  It seems I need this function more frequently than one would expect, and it would be a simple 'new feature'.

16 Comments
G-Money
NI Employee (retired)

I'm changing the title of this idea to be more of a statement instead of a question. Some people might see this as a support question instead of an idea because of it.

G-Money
NI Employee (retired)

Would you expect this to work with all numeric data types or would I32 be the best use case for this you think?

crossrulz
Knight of NI

If this is going to be done, it should be polymorphic to work with all of the integer types (U8, I8, etc.).  I personally don't see a use for the floating point types.

 

On a personal note, I think NI has more important things to worry about than this.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
dthor
Active Participant

It would be nice to have one that supports arrays of numerics as well: array in returns array of boolean out.

 

I have my own little subVI for this, but it only accepts I32. Luckily I don't care about that particular coercion dot... Maybe eventually I'll get around to making it polymorphic, but I doubt it! Smiley Very Happy

altenbach
Knight of NI

Instead of Quotiend&Remainder, I simply do a bitwise AND with a diagram constant of 1. The result is either 0 (=even) or 1 (=odd). You can wire this directly to a case (and make the cases 0 and 1) or add a "=0" or "!=0" of you want a boolean.

 

Wrap it into a subVI if needed.

 

wired
Active Participant

I've used the AND approach as well. I just really have an affinity for the triangles, I guess 😉

 

Since NI has stated that its near term focus is stability, not enhancements, I figured this would be a good fit for their stated intent - not much time or risk to develop, but an added feature nonetheless.

stbe
Active Participant

... or just use the "rotate right with carry" which returns the LSB

_________________________
CLA
wired
Active Participant

Picture time...

 

Primitive example...

JasonD_at_UML
Member

 

If I had a nickel for every Loop i with a Quot/Rem =0 I've coded over the years...

 

I agree on something small for testing INT evens and odds.

 

 

Broken_Arrow
Active Participant

This is another one of those ideas where - yes, it is easy to do using a few dodgy bits making a fine bit of kit, etc... but why not have a primative? Kudo.

Richard