LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Possible LabVIEW math bug?

Multiply 8.2 by 60 (ex. converting minutes to seconds). That equals 492. Take 492 and subtract 492. Should be 0 right? Labview comes up with -5.68434. If you then take that value and subtract 1, you get -1, not -6.68434. Separately, if you subtract a constant of 492 by 492 you get the correct answer, 0. This seems like a bug, but maybe I'm crazy! This is a 2013 file, but this also happens in 2014.

0 Kudos
Message 1 of 10
(4,901 Views)

If you extend your numeric indicator you actually see it's "-5.68434E-14". So what you're actually seeing is rounding error. This means also, that when you subtract 1 you get -1.

If you look at all of the indicators with more sig figs, you get this:

la_FP.png

 

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 10
(4,890 Views)

NOT A BUG. This is expected behavior due to the way floating point numbers are defined (in nearly all languages, not just LabVIEW). Nonetheless, it has been reported over and over again, in various forms. Search this forum (or a Google search for "site:forums.ni.com math bug") for many, many explanations.

0 Kudos
Message 3 of 10
(4,885 Views)

Not a bug.

 

The answer is not -5.68434 but -5.68434E-14.   (Make your indicator wider to see.)

 

This is not surprising when doing math on floating point numbers and is a very well know issue.

 

Please pay  S-mercurio another nickel for his retirement fund.

 

 

0 Kudos
Message 4 of 10
(4,880 Views)

It's not -5.6843, it's -568434E-14 which equals 0.0000000000000568434.  Pretty close to zero.  You're dealing with machine epsilon and all digital computers have this "bug".   https://en.wikipedia.org/wiki/Machine_epsilon

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 5 of 10
(4,871 Views)

Hehehe, the number of quick responses calling out OP cracks me up Smiley LOL

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 6 of 10
(4,866 Views)

That's not -5.6834, it's -5.68434E-14, essentially zero. What you've demonstrated is the fact that decimal numbers don't always convert into binary floating point numbers without a small rounding error. Here's an article that explains it in depth.

 

Aaron T..

0 Kudos
Message 7 of 10
(4,862 Views)

If this thread has taught me anything, it's that this forum could use a feature that tells you if a new reply has been added to the thread while you were typing out a reply of your own.

 

Also to watch your indicator size.

Message 8 of 10
(4,851 Views)

@Verywiseguy wrote:

If this thread has taught me anything, it's that this forum could use a feature that tells you if a new reply has been added to the thread while you were typing out a reply of your own.

 

Also to watch your indicator size.


Jesus Christ, yes.

I bet you that has been suggested already, but I can't find it in the Feedback forum.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 9 of 10
(4,847 Views)

I couldn't find a suggestion like this either.  It's probably been mentioned somewhere but I guess it doesn't have a post of it's own?  Anyway, I posted something about it in that feedback forum.  Link is here.

0 Kudos
Message 10 of 10
(4,754 Views)