Jump to content

[CR] Floating Point Almost Equal


Recommended Posts

Floating Point Almost Equal


This package contains VIs for testing equality of floating point numbers within a specified tolerance. Absolute Epsilon comparison, Relative Epsilon comparison and the ULP comparison have been implemented as described in this blog post by Bruce Dawson: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
Note that the ULP comparison has not been implemented for extended precision floating point type.
Installation and instructions:
  • Install VIP package using VI Package Manager 2014.
Examples:
  • "<LabVIEW>\examples\LAVA\AlmostEqual\AlmostEqual_Example 1.vi" Demonstrates the usage of all three AlmostEqual functions.
  • "<LabVIEW>\examples\LAVA\AlmostEqual\AlmostEqual_Example 2.vi" Demonstrates a case where exactly equal fails to produce the expected result.
 
Development version available on GitHubhttps://github.com/rfporter/FP-Equal

  • Submitter
  • Submitted
    12/19/2014
  • Category
  • LabVIEW Version

 

  • Like 1
Link to post
  • 3 weeks later...
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By Porter
      This package contains VIs for testing equality of floating point numbers within a specified tolerance. Absolute Epsilon comparison, Relative Epsilon comparison and the ULP comparison have been implemented as described in this blog post by Bruce Dawson: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ Note that the ULP comparison has not been implemented for extended precision floating point type. Installation and instructions: Install VIP package using VI Package Manager 2014. Examples: "<LabVIEW>\examples\LAVA\AlmostEqual\AlmostEqual_Example 1.vi" Demonstrates the usage of all three AlmostEqual functions. "<LabVIEW>\examples\LAVA\AlmostEqual\AlmostEqual_Example 2.vi" Demonstrates a case where exactly equal fails to produce the expected result.   Development version available on GitHub: https://github.com/rfporter/FP-Equal
    • By Porter
      The other day I encountered a situation where I wanted to test if two floating point values were equal. Of course, one of the first things that you are told about floating point values is that you should never test for exact equality. So I proceed to wire up:
       
      Is X = Y +/- some acceptable tolerance?
       
      And that worked perfectly for my use case. That is, I knew that the max. value was 1000 and the min value was 0 and the resolution (or increment) was 0.01. A tolerance of 0.001 was sufficient.
       
      This got me thinking. Wouldn't it be nice to have some reusable VIs for testing if floating point values are almost equal? Unfortunately this meant taking a broader view of the problem and lead me to this interesting blog post:
       
      http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
       
      I've attached VIs for the Absolute Epsilon comparison, Relative Epsilon comparison and the ULP comparison described in the blog post for double precision floating point values.
       

       
      Perhaps this would be a nice addition to the somewhat barren OpenG Comparison Pallet?
       
      Uploaded package to Code Repository: http://lavag.org/files/file/259-floating-point-almost-equal/
      AlmostEqual_LV2013.zip
      AlmostEqual_LV86.zip
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.