LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Darin.K

"Almost Equal" functions for Float comparisons

Status: New

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
SteveChandler
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


Intaris
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.

LuI
Active Participant
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

Broken_Arrow
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






lvABC
Member

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

 

original2.png

CrystalTech
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.

ClaudioH
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
Jason_Harrigan
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.

altenbach
Knight of NI

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

 

Equal_DBL.vi

Darin.K
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/