LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I check if the result is NaN

Hi!

 

I would like to check the result of formula node without checking the inputs one by one. Division by zero gives Inf. What about if I divide zero by zero? The result is NaN. I tried to compare (see picture) the result NaN with constant NaN but LED remained dark = false.

 

Ljubo.

Message 1 of 16
(19,485 Views)

Try this function. Or check if Y=0

 



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Message 2 of 16
(19,473 Views)

Coq rouge wrote:

Try this function.


 

Can't!

The image “http://forums.ni.com/ni/attachments/ni/170/416840/1/sample.PNG” cannot be displayed, because it contains errors.


Never say "Oops." Always say "Ah, interesting!"

Message 3 of 16
(19,444 Views)
You will need to use the Not A Number/Path/Refnum? Function.
Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
Message 4 of 16
(19,440 Views)

Thank you, Coq

 

Function Not A Number/Path/Refnum? works in case "zero divided by zero".

I would like to repeat: I don't want to check inputs one by one. My example is simplified to illustrate the problem. Formula can be much more complex with many inputs. 

In fact I'm interested in catching all the errors which can occur during mathematical operations. C++ or Delphi for example, can report errors always when you try to execute an illegal math operation. And they have a mechanism to catch NaN, Inf ... (see Delphi code below)

 

  b := 0;
  c := 0;
  try
    a := b / c;
  except

    // this part of code is executed only if division a/b is invalid

    a := 0;
  end;

Is this possible in LabVIEW too ?

 

Regards, 

 

Ljubo.

0 Kudos
Message 5 of 16
(19,432 Views)

The Formula Node is somewhat limited in the number of functions and operators.  If you have the Full or Professional Development system, you might want to look at using a MathScript Node instead.

 

Mathscript Functions


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Message 6 of 16
(19,415 Views)
Yes you can. I my picture is not censored. It will show how


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 7 of 16
(19,409 Views)

Hi, Phillip

 

MathScript functions give some hope. Programming class or Support could include a function or programming structure which catch an error. MathScript error output could also report an error or a warning, at least. User should know that input data is wrong. But it seems we will have to wait a newer version.

 

BTW, are this function trustworthy? The result of two structures (MathScript node and Formula node, see picture) are not always the same. SQRT(-1) should be NaN in both cases.

 

Regards,

 

Ljubo.

0 Kudos
Message 8 of 16
(19,364 Views)

Ljubo wrote:

 

Function Not A Number/Path/Refnum? works in case "zero divided by zero".


Technically, that function will operate in any case when the value is NaN.

 


Ljubo wrote:

I would like to repeat: I don't want to check inputs one by one. My example is simplified to illustrate the problem. Formula can be much more complex with many inputs. 

In fact I'm interested in catching all the errors which can occur during mathematical operations. C++ or Delphi for example, can report errors always when you try to execute an illegal math operation. And they have a mechanism to catch NaN, Inf ... (see Delphi code below)

 

  b := 0;
  c := 0;
  try
    a := b / c;
  except

    // this part of code is executed only if division a/b is invalid

    a := 0;
  end;

Is this possible in LabVIEW too ?


When you say one-by-one are you referring to an array? If so, that function is polymorphic so you can wire an array to it.

 

However, it sounds, based on your description, that you are trying to check *all* possible calculations being performed in LabVIEW. I'm not sure I understand the practicality of this, as 99% of calculations are not likely to create NaN/Inf values. It is usually better to identify specific parts of code in which such kinds of results can happen and check for them. As far as LabVIEW is concerned, it has no automatic way of stopping the code and reporting such errors, unless you consider conditional probes, but those only work in the development environment. 

 

0 Kudos
Message 9 of 16
(19,353 Views)

Ljubo wrote:

BTW, are this function trustworthy? The result of two structures (MathScript node and Formula node, see picture) are not always the same. SQRT(-1) should be NaN in both cases.


You are using the wrong datatype. The mathscript output should be set to complex (CDB).

 

(Still, it should be "0+1i" and not "-2.71051E-20 +1i", but that's just an approximation error.)

Message 10 of 16
(19,349 Views)