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
Mr.Mike
NI Employee (retired)

As a note:

The floating point primitive may not be safe to use.  It may cause crash on save.  It has not been thoroughly tested.  Read that whole thread.

 

(To whomever implements this at NI, make sure you read the thread linked on LAVA because the node already exists, it just needs to be finished up.)

-- Mike
JÞB
Knight of NI

WOW!

 

I wish to revive this thread!

 

There are many "Almost Equals" ideas out there.  and none can fully satisfy the LabVIEW EXT.

 

EXT is platform dependant in bitness of the exponent.  Mantissa and sign are defined.

 

I created an "Equality.vi" with polymorphs for SGL DBL and EXT today "related" Pvis foainerr <= and >= were no-brainers!

 

My question is.  

 how to detimine the EXT bitness of the OS?  is it 80, 96 or 128?  If I knew that I could write better code.


"Should be" isn't "Is" -Jay
Porter
Member

I've posted some almost equal examples for DBL precision floating point values based on the implementations described in this blog post by Bruce Dawson: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

 

Examples: http://lavag.org/topic/18636-floating-point-almost-equal/

 

They can be easilly converted to single precision if needed.

 

It seems that there is no single function to cover all use cases of almost equal for floating point values. Perhaps that is why such a function doesn't exist in the comparison pallet.

Manzolli
Active Participant

I like the original concept, simple and having the tolerance associated with an error, like in metrology. Percentage could be a nice option too. I would like also to have an option to compare with "Less?" or "Less or Equal?",

 

It would be nice to have this function built in LabVIEW, but it's easy to code and have in a personal library. I kudoed anyway since this is an important issue when float point numbers are compared.

André Manzolli

Mechanical Engineer
Certified LabVIEW Developer - CLD
LabVIEW Champion
Curitiba - PR - Brazil
X.
Trusted Enthusiast
Trusted Enthusiast

Resurrected from the dead: this is similar to this suggestion and never stops coming back it seems, in one variant or another.

Which is why I haven't kudoed it (or them). Like many, I have my own that does what I want but wouldn't do everything people have suggested in other threads.