LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with NaN treatment in LabView 2016

I have a camera program in which I use many IMAQ functions. By the error out output of these functions, if Status is set to False, the measurement run without error. In this case, the program displays the measured value. However, in the event of an error, I would like the program to return a NaN value.

I can generate Nan value in two ways: "zero divided by zero" or "square root of -1".
In the former case, the program works well and displays a "NaN" value. In the latter case, the program always returns 0 value. Why doesn't this case work?

0 Kudos
Message 1 of 11
(2,456 Views)

You can just type "nan" (case insensitive) into a DBL constant/control.

 

(It would help to see some simplified code, especially the non-working case. For example sqrt(-1) is NOT NaN if the input is complex)

Message 2 of 11
(2,452 Views)

Hi sziszkont,

 


@sziszkont wrote:

However, in the event of an error, I would like the program to return a NaN value.

I can generate Nan value in two ways: "zero divided by zero" or "square root of -1".
In the former case, the program works well and displays a "NaN" value. In the latter case, the program always returns 0 value. Why doesn't this case work?


Well, there is (atleast) a 3rd way: simply use a "NaN" float numeric constant!

Why do you need a (quite senseless) calculation to create a NaN value?

 

It seems you doing something wrong when calculating sqrt(-1):

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Download All
0 Kudos
Message 3 of 11
(2,447 Views)

sziszkont_0-1643129555040.pngsziszkont_1-1643129573241.png

Could you help me with what could be wrong?

0 Kudos
Message 4 of 11
(2,416 Views)

@sziszkont wrote:

I have a camera program in which I use many IMAQ functions. By the error out output of these functions, if Status is set to False, the measurement run without error. In this case, the program displays the measured value. However, in the event of an error, I would like the program to return a NaN value.

I can generate Nan value in two ways: "zero divided by zero" or "square root of -1".
In the former case, the program works well and displays a "NaN" value. In the latter case, the program always returns 0 value. Why doesn't this case work?


Note that while "zero divided by zero" is always not a number, "square root of -1" may or may not be a number depending on the type of numeric representation.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 5 of 11
(2,415 Views)

We can't debug a picture.

 

 

Also... it looks like your -1 isn't wired to the Sqrt function?

 

Also also, get rid of the sqrt function altogether, and type "nan" into the inside of the orange box. You've got it typed into the label of the orange box.

0 Kudos
Message 6 of 11
(2,410 Views)

Hi sziszkont,

 


@sziszkont wrote:

sziszkont_0-1643129555040.png

Could you help me with what could be wrong?


  • missing wire at "-1" to sqrt function
  • labelling the "-1" constant as "NaN" instead of typing the value of "NaN"
  • lots of coercion dots
  • Do you really need SGL values? Really? Why not stick with DBL values avoiding several additional type conversions?
  • missing comment in the subdiagram label of the case structure
  • Do you really need to output NaN? Would it make sense to output the previous values in case of an error?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 11
(2,391 Views)

@GerdW wrote:
  • missing wire at "-1" to sqrt function

Something has to be wired to the input of the Square Root function since it is required.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 11
(2,380 Views)

It is -1 wired to the Sqrt function, only not shown in the picture.

This has been a well-functioning program for years, but now I ran into this bug that returns 0 instead of NaN. I'm looking for an explanation for this. If I use 0/0, the error is solved, but why?

0 Kudos
Message 9 of 11
(2,321 Views)

You have been told already that pictures can NOT be debugged. So post your actual code if you want us to help you further than this!

 

And no we do not ask you to post your company top secret VI that spans 20 screens across. We would actually appreciate it if you can create a small test VI that shows the effect that you claim you see. In many cases while creating that test VI you will often already see yourself where the real problem is!

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 10 of 11
(2,317 Views)