LabVIEW Idea Exchange

About LabVIEW Idea Exchange

Have a LabVIEW Idea?

  1. Browse by label or search in the LabVIEW Idea Exchange to see if your idea has previously been submitted. If your idea exists be sure to vote for the idea by giving it kudos to indicate your approval!
  2. If your idea has not been submitted click Post New Idea to submit a product idea to the LabVIEW Idea Exchange. Be sure to submit a separate post for each idea.
  3. Watch as the community gives your idea kudos and adds their input.
  4. As NI R&D considers the idea, they will change the idea status.
  5. Give kudos to other ideas that you would like to see in a future version of LabVIEW!
cancel
Showing results for 
Search instead for 
Did you mean: 

"Almost Equal" functions for Float comparisons

It is time to put a dent in the floating point "problems" encountered by many in LV.  Due to the (not so?) well-known limitations of floating point representations, comparisons can often lead to surprising results.  I propose a new configuration for the comparison functions when floats are involved, call it "Compare Floats" or otherwise.  When selected, I suggest that Equals? becomes "Almost Equal?" and the icon changes to the approximately equal sign.  EqualToZero could be AlmostEqualToZero, again with appropriate icon changes.  GreaterThanorAlmostEqual, etc.

 

AlmostEqual.png

 

 

I do not think these need to be new functions on the palette, just a configuration option (Comparison Mode).  They should expose a couple of terminals for options so we can control what close means (# of sig figs, # digits, absolute difference, etc.) with reasonable defaults so most cases we do not have to worry about it.  We get all of the ease and polymorphism that comes with the built-in functions.

 

There are many ways to do this, I won't be so bold as to specify which way to go.  I am confident that any reasonable method would be a vast improvement over the current method which is hope that you are never bitten by Equals?.

15 Comments
Trusted Enthusiast

Kudos! But you know that Dr. Spock would give you the three finger grip for that. I once asked someone what Fuzzy Logic was and he said that "It is Dr. Spock's worse nightmare" I would go further and make it the default for equals. Sure it might break some peoples code but it would probably fix even more.

=====================
LabVIEW 2012


Proven Zealot

No, no changing of default behaviour.  That's just not good. 

 

Think of all the example VIs made to show why "equals" for floats is a bad idea.  Suddenly they all work fine!!  Smiley Very Happy

 

No seriously, please don't change the default behaviour.

Active Participant LuI
Active Participant

This is not so hard to do by yourself. I have a 'Are values alike.vi' in my user.lib:

The VI compares both values, if they are alike each other within the acceptance criterium (def 15%).

One has to handle values of 0 (zero) differently, but the rest is quite easy.

C:\temp\Neuer Ordner\alike.png

Active Participant

Regarding the above comment. A lot of us have made a VI to do this kind of thing, but if everybody is rolling thier own, it's time to make it part of LabVIEW. My opinion.

Richard






Member

This may not be a Green solution (for simple comparison), but worth a look.

 

original2.png

Member

I agree with Broken Arrow.  I also have my own version, but would like a new function "Almost Equal To" with reasonable terminal(s) to determine the criteria.  Please keep the "Equal To" as it's own entity.

Member

Hi,

 

Another solution could be what I suggested at:

 

http://forums.ni.com/t5/LabVIEW-Idea-Exchange/New-quot-in-range-quot/idi-p/1487658

 

Cheers,

CHCastro
Member

I think this is a great idea. It should be the default behavior whenever a float is wired to the equal function, but only when you're writing code. Old code would obviously be upgraded to keep the previous glif and previous behavior. New code would default to the new glif and new behavior.

 

When you drop down the equals function and all the sudden you get this weird approximately equal thing, you start asking questions and reading the help, then you figure out that what you were trying to do wasn't the best way to do it.

Knight of NI

The algorithm should probably be based on something along these lines.

 

Equal_DBL.vi


LabVIEW Champion Do more with less code and in less time
Trusted Enthusiast

Looks like someone at NI thought of this a long time ago but never quite finished the job:

 

http://lavag.org/topic/16733-floating-point-equal-primitive/