LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

error in calculation

Hello every one,

I am calling this subVI from the main.

I am geting this weird error calculation. Can anyone tell me what is wrong please?

Why am I getting A false while it should be a true?

 

Thanks,

Regards,

F

Download All
0 Kudos
Message 1 of 22
(5,064 Views)

Hi F,

 

the wonders of floating point numbers!

In the screenshot you just see rounded float values. And believe me: 10.9999 is smaller than 11.0001!

 

There are a lot of threads on the topic of floating point precision. And all of them say: be careful when adding 0.8 and 0.2, the result might be different than 1.0!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 22
(5,051 Views)

Yup, GerdW is right.

Please have a look here: http://www.ni.com/white-paper/7612/en/

Message 3 of 22
(5,041 Views)

@feriel0209 wrote:

Hello every one,

I am calling this subVI from the main.

I am geting this weird error calculation. Can anyone tell me what is wrong please?

Why am I getting A false while it should be a true?

 

Thanks,

Regards,

F


From looking at your png of the code it is easy to see the confusion you might have.

11.0 is not equal to 11.0!  BUT yet I believe there is no error in the calculation!  Trust me for a just a "bit" and I will try to explain.  This might be a "Wrap-your-head-in-duct_tape-moment" the FULL explaination is not easy.

 

It is simple to understand if, you remember that computers cannot understand the infinate amount of "Whole numbers" you understand and can only deal with "Floating point" numbers.  Yes, "Whole numbers" like those you learned in grade school and "IEEE-754Floating point numbers" are not the same set of numbers 

 

First; look at this link

 

What this means to YOU:  Unless you have the library I attached to the linked message (or a simillar library) NEVER drive a case structure from a boolean output of a floating point number comparsion!

 

 


"Should be" isn't "Is" -Jay
Message 4 of 22
(5,039 Views)

Hi, thanks for your quick answers!

Yeah, but I am not using measuring values. I am just adding 0.2 to the floating voltage values.

I will check what you told me and be back to you.

 

Regards,

Feriel

0 Kudos
Message 5 of 22
(5,026 Views)

@feriel0209 wrote:

Hi, thanks for your quick answers!

Yeah, but I am not using measuring values. I am just adding 0.2 to the floating voltage values.

I will check what you told me and be back to you.

 

Regards,

Feriel


Just adding 0.2?  0.2 (in "Real") cannot be exactly represented as an IEEE 754 compliant "Float."   The fact that. the set of "Foating point numbers" is a very limited sub-set of the set of "Real numbers"  causes a lot of confussion.  So much confussion that a big bunch of engineers needed to step in and write IEEE 754!  

 

Spoiler
Some day I'll write the "Punchline" to this post

Meaning no offence- you just need to remember your computer just cannot think like a human!  On the "Plus-side" that why some humans get paid to write computer softwareSmiley Very Happy


"Should be" isn't "Is" -Jay
Message 6 of 22
(5,013 Views)

feriel0209 wrote:  I am just adding 0.2 to the floating voltage values.

Yeah, and here (Floating Zero) we are just subtracting 0.1 and causing an infinate loop.

 

And this issue is for every computer language, not just LabVIEW.  This is a lesson I learned hard with QBasic.

Spoiler
I might be dating myself there.  But at least it was not punch cards like some of the guys around here.

GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 22
(4,998 Views)

@crossrulz wrote:

And this issue is for every computer language, not just LabVIEW.  This is a lesson I learned hard with QBasic.

Spoiler
I might be dating myself there.  But at least it was not punch cards like some of the guys around here.

And now we are going very OT, (that is "Off Topic" a rare idiosyncrasy of these forums that do not usually use "txt spk")

 

crossrulz was joking with some of his elders (me.) I dress better than he does! I really have used a BIC Flair as a source code control tool.  Draw a diagonal line across the card-deck edge and, if you drop the stack, you have a clue to the order they belong in without needing to read the code back into your programming notes.

 

Yet, it does make a nice point when juxtaposed with the stacked sequence structure issue the OP (Original Poster another rare idiosyncrasy of these forums) presented.  Show the code and its output!  Just mentioning that some third party software (MS Excel) displays your data "wrong" is really the wrong question to ask.Smiley Wink


"Should be" isn't "Is" -Jay
Message 8 of 22
(4,985 Views)
Spoiler
😄

Haha I see.

Besides, I understand what you mean. I changed the precision of both numbers and I saw that they are different. (Pic.png)

Thank you for the link.

Regards,

Feriel

0 Kudos
Message 9 of 22
(4,968 Views)

@JÞB wrote:

crossrulz was joking with some of his elders (me.) I dress better than he does!


How do you figure?  I have 2 CLA, 1 CLED, and 2 LabVIEW Champion shirts I wear every week.  That takes care of my work week!  All of those are way better than your stupid CLD shirt.Smiley Tongue


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 22
(4,952 Views)