LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DBL comparison errors

While testing a test data cluster I load a random number for a DBL into a USR, save the cluster to disk, read back the data, and read the cluster and compare the two values. Due to the DBL's not being "equal" the test fails. Yet if I check my data visually the numbers are the same. I know this has been discussed before but no one seemed to have a good answer as to how you can eliminate the small errors LV creates when handling DBL's. Any suggestions?
 
Paul
7.1.1
PaulG.
Retired
0 Kudos
Message 1 of 10
(5,417 Views)

Hi Paul

Never compare floating point numbers to 0. In addition to that - if possible, never compare floating point numbers with each other.

Always compoare if one is bigger than the other.

You must know, that for example 3.2 is not just saved as 3.2.

Have a look at this wikipedia article - it gives you a brief overview of this topic.

http://en.wikipedia.org/wiki/Floating_point_numbers

Hope this helps.

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 10
(5,408 Views)

Subtract one from the other and check the magnitude of the difference.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 10
(5,402 Views)
Hi all!
Example of diagram
0 Kudos
Message 4 of 10
(5,389 Views)
Buried in <LabVIEW>\vi.lib\Waveform\WDTOps.llb is a subroutine named Check for Equality.vi.  This VI checks to see if two floating point numbers equal one another to six digits of precision and returns the actual precision.  It has been there and has not changed since LV6.0, so it is probably fairly safe to use.  However, since it is not part of the official LabVIEW API, it can change at any version of LV.
Message 5 of 10
(5,374 Views)
Comparing floating was one of the first problems I encountered when I started programming years ago.  Equal of floats or doubles just means that their difference is insignificant so find the absolute value of the difference and see if it is greater than some epsilon constant.  Remember that floating point numbers have a finite precision (single is 22 bits, double is 51 bits and extended is 63).  Usually there is a limitation of significant digits at the value input (measurement) stage.
 
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 10
(5,365 Views)


@PaulG. wrote:
.., save the cluster to disk, read back the data, and read the cluster and compare the two values. ...

If you would write the cluster to file in binary form, the comparison should always succeed. How are you writing the values?

Of course in the general case, you should always compare DBLs within a certain tolerance by comparing their absolute difference with a threshold (e.g. 0.0001) as in this image:

Message Edited by altenbach on 11-18-2005 09:13 AM

0 Kudos
Message 7 of 10
(5,354 Views)
Wouldn't it be nice to have the "tolerance" independent of the values?Smiley Surprised
OlegUA's solution calculates the "tolerance" as a percentage of the size of [one of] the inputs,
Perfect!  (almost... needs tweaking for values close to zero where Δx may be much larger than X1).
 
Went to the wiki-link becktho, saw "problems with floating-point numbers"  (though, didn't see EQ comparison discussed Smiley Mad )
 
Somebody here probably knows whether it's possible to: measure LSBits-of-difference [in the mantissa] between values.
 
If it is IMPOSSIBLE, I hope "somebody" will say something - before I spend too much time on (another) fools-quest.
 
When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 8 of 10
(5,314 Views)
...felt like I was being rude for posting the last question here, so here's a dedicated thread: http://forums.ni.com/ni/board/message?board.id=170&message.id=152640
 
(i'm so confused...Smiley Surprised)

Message Edited by Dynamik on 11-18-2005 11:00 PM

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 9 of 10
(5,307 Views)
Hi,
 
Did not see this thread before. Try my Equal_SGL.vi for SGL at
 
Cheers,
 
Xu
0 Kudos
Message 10 of 10
(5,292 Views)