LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with the Greater? function

I've run into an issue with Labview 8.5's Greater? function.  (>)    If I run the following code I get a True when the input values are equal.   
 
 
This is a problem I've found in the field, and need to resolve ASAP.   
 
Can anyone tell me why 5.1 is greater than 5.1?     The function seems to work with integer values.
 
 
This was also confirmed to exist in LV 8.2
 
Thanks
 
0 Kudos
Message 1 of 9
(3,683 Views)

Hi lclutchl,

that´s no bug. This both numbers are not equal, because this are floating point numbers. Look at the entire number with all decimal places.

Here is a link for additional informations: http://en.wikipedia.org/wiki/Floating_point_number

Mike



Message Edited by MikeS81 on 04-01-2008 07:25 PM
Message 2 of 9
(3,675 Views)

look again. I've increased the precision...



Message Edited by Jorge Amaral on 04-01-2008 12:25 PM
Software developer
www.mcm-electronics.com





PORTUGAL
Message 3 of 9
(3,671 Views)

fractional decimal values can not always be fully represented in floating point representation, because they cannot be represented exactly by a finite amount of bits.

If you display all digits, you'll see that you are actually calculalting:

5.20000000000000018 - 0.100000000000000006 = 5.10000000000000053 while 5.1 is actually 5.09999999999999964 and thus smaller than the sum.

Message 4 of 9
(3,667 Views)
This is the result of a well known issue regarding the finite representation of numbers in binary in the computer. Numbers which are exactly expressed as decimal fractions may be infinitely repeating "fractions" in binary. Expand the display to show all the digits and your will see.

Lynn

Message Edited by johnsold on 04-01-2008 01:31 PM
Message 5 of 9
(3,662 Views)
Interesting.. Mike is absolutely right!  Why is it that when I manually enter "5.1" it rounds it to "5.0999xxxxxx"?

Message 6 of 9
(3,657 Views)

Got it!    Now that I know this issue exists I can account for it!    

 

 

Thanks everyone.

 

 

 

Message 7 of 9
(3,651 Views)

Vikas K:


Interesting.. Mike is absolutely right!  Why is it that when I manually enter "5.1" it rounds it to "5.0999xxxxxx"?


because it is impossible to represent 0.1 with the number of binary decimals places available to the number.



Message Edited by JeffOverton on 04-01-2008 01:56 PM
Message 8 of 9
(3,644 Views)

It makes sense. Thanks Jeff.

Vikas

Message 9 of 9
(3,589 Views)