06-17-2009 06:48 AM
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.
06-17-2009 06:55 AM
Try this function. Or check if Y=0
06-17-2009 07:19 AM
Coq rouge wrote:
Try this function.
Can't!
06-17-2009 07:22 AM
06-17-2009 07:32 AM
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.
06-17-2009 07:54 AM
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.
06-17-2009 08:04 AM
06-17-2009 10:49 AM
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.
06-17-2009 10:55 AM
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.
06-17-2009 10:59 AM
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.)