LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I check if the result is NaN

If you are afraid that a user input may cause a NaN. You can right click on a control and select "Data Entry" In this menu you can define a valid range 


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 11 of 16
(1,685 Views)
Thank you, Altenbach.
0 Kudos
Message 12 of 16
(1,686 Views)

This is how:

// The equivalent of:
// if( isnan( f ) ) {;} 
// is:
if( !( f == f )) {;}

If the variable is not nan the equality operator will always output true when the same variable is compared with itself. But because the result of any comparison operation done with a nan is always false, if that variable is a nan the result will always be false.

 

0 Kudos
Message 13 of 16
(1,182 Views)

Artst wrote:
// The equivalent of:
// if( isnan( f ) ) {;} 
// is:
if( !( f == f )) {;}

 


Why would you post offtopic text code in a LabVIEW forum? (and in a thread that is 8+ years old!)

 


@Artst wrote:

... because the result of any comparison operation done with a nan is always false, ....


This statement is incorrect too. Some comparisons with NaN result in a TRUE. Here is one of them.

 

NanCom.png

0 Kudos
Message 14 of 16
(1,163 Views)

Hi!

There is a discussion about the same problem for MATLAB. As I understand it, acording to IEEE 754 standard +Inf, -Inf and NaN are valid results for math processors. If the "division-by-zero test" is built into LabView software it would slow the performance. So: there is no general solution to check our floating point operations. If necessary we will have to do it on a case-by-case basis.

0 Kudos
Message 15 of 16
(1,148 Views)

It is not off topic. The the code I posted shows how a NaN can be detected in a LabVIEW Formula Node's script.

 

As for G-Code, the way to do that is the "Not A Number/Path/Refnum?" VI in the Comparison palette. There is not an equivalent function for that in Formula Node scripting. The isnan() function in C, which is what the scripting language is based on, is not in that scripting language. So how to do it in scripts is not obvious.

 

 

 

0 Kudos
Message 16 of 16
(523 Views)