LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why doesn't this vi work?

Hi All,

I have a vi that is supposed to determine whether a particular number multiplied by 0.2 is larger than or equal to a minimum number (indicating a pass condition).  Now, to test this vi I want to know what happens when the particular number multiplied by 0.2 is EQUAL to the minimum number.

In other words...

if number=4 and minimum=4*0.2=0.8 then PASS, else FAIL

This vis works for all numbers except when number=3!!!

WHAT THE????

0 Kudos
Message 1 of 14
(4,097 Views)
Hi
 
I just made a vi, which works the same way as visible in your pdf, but it works without any problem. It behaves as expected.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 14
(4,073 Views)

Hi Melanie,

I don't quite understand your explanation of what you're trying to accomplish, so I'll just explain to you what your VI is doing and you can see if that's what you're trying to do.  "PASS" will be true if 'minimum' is greater than or equal to 'number' multiplied by 0.2.  "FAIL" will be true if 'minimum' is less than 'number' multiplied by 0.2.  Trying this VI with a number of different values, the functions always seem to do what they're supposed to.

For your particular case, why don't you create an indicator off the different wires and change its precision to show a bunch of digits, and see if a floating point roundoff error is the cause of your problem.  Otherwise, attach a VI to your post with the *specific* values saved as default in the controls that you are having a problem with.

Good luck,

-D

0 Kudos
Message 3 of 14
(4,073 Views)
Hmmm, just left work so I'll have to post the vi tomorrow. I swear, when I run the vi I get the following:

number=4, minimum=0.8, PASS
number=3, minimum=0.6, FAIL
number=2, minimum=0.4, PASS

after further investigation...

number=3.003, minimum=0.6006, PASS
number=3.002, minimum=0.6004, FAIL
number=3.001, minimum=0.6002, FAIL
number=3.000, minimun=0.6000, FAIL
number=2.999, minimum=0.5998, FAIL
number=2.998, minimum=0.5996, FAIL
number=2.997, minimum=0.5994, PASS

I'm running Labview 7.1.1 on Windows XP. I checked the properties of the double precision variables and they are supposedly keeping 6 significant figures (not that this should matter in the case of number=3 because 0.2*3=0.6 exactly). This is just math, it doesn't make sense!

Please let me know if you get something different on your machine.

Thanks for your help!
0 Kudos
Message 4 of 14
(4,065 Views)

Hi

Unfortunately this is not just math - it's representation of floating point numbers on a binary base.
You say, you checked the properties and the controls should carry 6 significant digits, but this is just for the graphical representation on the front panel. So although you may see a number of 6.400000 for instance, it's value may be 6.40000000000001. This is a topic, which was and still is discussed in the forum.

What you could do to improve your vi, is to insert some rounding (e.g. round to nearest).

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 5 of 14
(4,064 Views)
Or i would also suggest to convert the number to string of a selected precision and compare for that string.
0 Kudos
Message 6 of 14
(4,046 Views)
Or subtract the numbers, and see if the result is within a range. Testing floats for equality is never a good idea (except perhaps 0,NaN, -Inf and +Inf).


You said you wanted to know "whether a particular number multiplied by 0.2 is larger than or equal to a minimum number". So why do you test for equality? Test if it's equal or larger! You don't seem to have a problem at all, you're code is working, but your testing is wrong.


Regards,


Wiebe.




"devchander" <x@no.email> wrote in message news:1139226038680-320702@exchange.ni.com...
Or i would also suggest to convert the number to string of&nbsp;a selected&nbsp;precision&nbsp;and compare for that string.
0 Kudos
Message 7 of 14
(4,033 Views)

Wiebe:

Testing floats for equality is never a good idea, really never.

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 8 of 14
(4,029 Views)

Message Edited by MelanieM on 02-06-2006 08:06 PM

0 Kudos
Message 9 of 14
(4,002 Views)
Thanks everyone for their help.  The fact remains that I still don't have a solution - what is the proper way of comparing two numbers to see if one is greater than or equal to another?
 
I don't really understand how I am testing my vi "wrong".  I am collecting data from an instrument, after a few calculations I arrive at a value (T).  For the particular example I am working with if 3<=T<=8 then the object I am measuring is considered to be "category 4".  My program scans the original data looking for the minimum value (Tmin) and for a category 4 object, Tmin>=0.2T in order for Tmin to "pass" this test.  So, T=3 is a boundary condition.  If my instrument measures T=3, then it needs to ensure that Tmin>=0.6 to pass, otherwise it fails this test.  How else can I test this?
 
Thanks again,
Melanie
 
 
 
 
0 Kudos
Message 10 of 14
(3,988 Views)