LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does this program return falls?

Hello,
I have a problem about a simple program.

I added two constant number,value of them 1,2 and 0,15.After that i
compared 1,35 and sum of them(1,35) are they equal or not.The results
of this program must be true.But program returns falls.

(a+b) =? c. Where a=1,2 b=0,15 c=1,35.


Where is the mistake?
I need your help.
Thanks.

0 Kudos
Message 1 of 3
(2,809 Views)
You are doing a comparison of floating point number which is a basic mistake that many beginning programmers make. Floating point numbers do not have an exact binary representation so this comparison is something you want to avoid. There are many ways to work around this limitation of computer math. Do a search of the forum for 'floating point comparison' to get an idea of the many possibilities.
0 Kudos
Message 2 of 3
(2,802 Views)
Hello,

This is a problem known in all languages when using floating point representation.
The following link explain this issues with examples.

Comparing Floating Points Does Not Seem to be Working Properly.

Best regards,
National Instrument Switzerland
Nick_CH
0 Kudos
Message 3 of 3
(2,796 Views)