LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bug? Two Doubles not detected as equal v8.6

Hi Bais,

 

LabVIEW can calc that one too:

check.png

0.5 can be stored with no rounding error as it's a power of 2.

 

But: the problem is limited accuracy of floats!

As soon as rounding errors come into play you shouldn't compare floats for equality, no matter of the used programming language...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 21 of 33
(1,821 Views)

And if you compare two constants set equal to 0.5 in LabVIEW, you'll find that LabVIEW also finds they are equal.

 

The problem is when you do calculations that you mathematically expect to be the same number wind up coming from different paths when the miniscule errors that are present in representing numbers in a binary language start to accumulate.

 

If you have meaningful examples to post to this thread, then comment please.

Message 22 of 33
(1,819 Views)

@RavensFan wrote:

And if you compare two constants set equal to 0.5 in LabVIEW, you'll find that LabVIEW also finds they are equal.[...]


If display format does NOT mask any differences that is.......

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 23 of 33
(1,807 Views)

The attached VI shows the problem. As mentioned, 0.1 x 10 doesn't yield 1, just like 0.111 x 9 times doesn't equal 1. It's close, but not close enough for Equal (as you can see in the VI, the bit pattern differs).

It's a well known limitation of limited precision, whether it be 1, 7 or 15 digits of precision. Just like you cannot write PI or 1/9 as a decimal number ...

 

For floats, you'll need account for the total insecurity, like X+/-Epsilon or round to 10 significant figures or something.

 

As mentioned, it has nothing to do with LV, but with floats and binary representation.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 24 of 33
(1,783 Views)

this is what matlab does

type 

a = 0.5;

b = 0.5;

a == b

it prints out 1 ( which is true) 

 

-- so yea i found out 0.5 = 0.5 in labview as well ( so i was wrong) its because there one data line had a very small error apparently which i didn't epect.

 

btw i wasn't running my code on matlab, it was actually on a mathscript node.  my mathscript node produced a different result to the same code re-written in labview g-code with the same unit test. Mathscript syntax is the same as matlab syntax and you can actually run matlab code in mathscript.

 




 

0 Kudos
Message 25 of 33
(1,766 Views)

If there is a difference between MatLab and LabVIEW at all regarding this topic, then the explanation is:

LabVIEW is a programming language, as C/C++ or C#.

MatLab isn't.

 

So, MatLab isn't bound to rules of programming languages and therefore can insert *some* stuff as feature. Programming languages often support *libraries* which do also provide API functions with such features.

EDIT: And if there is no such library available, one can implement this on him-/herself. I *think* that MatLab supports interfaces for feature additions like this as well to the customer, but still it is no programming language....

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 26 of 33
(1,759 Views)

And as already noted, the exact same thing happens in LabVIEW. The moment you start doing some calculations, both LabVIEW and matlab perform the same. A high level language such as C, C++, LabVIEW are not designed to be idiot proof. The programmer must be familiar with limitations of digital computers and make those sort of adjustments for the idiot user.

0 Kudos
Message 27 of 33
(1,757 Views)

Floating Point Comparisons in Matlab.

 

Funny how the Matlab experts say the same thing as the LabVIEW experts.

0 Kudos
Message 28 of 33
(1,733 Views)

yea matlab and labview handling of floats is exactly the same. 

 

I guess there was problem with my translation of mathscirpt to labview g code or something else...

0 Kudos
Message 29 of 33
(1,726 Views)

@Sentinal_Bais wrote:

btw i wasn't running my code on matlab, it was actually on a mathscript node.  my mathscript node produced a different result to the same code re-written in labview g-code with the same unit test. Mathscript syntax is the same as matlab syntax and you can actually run matlab code in mathscript. 


It is very likely that the two appraches (LabVIEW vs MathScript) don't result in binary identical code. Slight changes in the order of operations can propagate floating point limitations differently and thus lead to non-identical results. Nothing new here.

 

You can even get slight result variations with the same code. See here for an interesting case study.

0 Kudos
Message 30 of 33
(1,698 Views)