LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Result getting displayed as Nan or 0 or 9.49353E-5 ?

Hello all,

 

In this app i am calculating total distance for the data base .  so i have find  the distance between two points . In this process..............If the distance to be  calculated between the two points are same means i.e x1 = x2 and y1 = y2 ..i am facing the below problem

 

In the below attached file the distance calculater vi is some time showing the result as zero and some times as Nan and some times as 9.49353E-5

 

But when i open the distace cal vi and run it individually but entering the same inputs which are passed to it , it is showing zero . but if i call it as a sub vi and read its value this is showing some times as nan or 9.49353E-5

Download All
0 Kudos
Message 1 of 11
(3,338 Views)

Please attach your VI converted for an older LabVIEW version...

Best regards,
GerdW


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

It is because floating point is not truely exact.  There are rounding errors from your calculations that could cause the results to be off by a bit or more.  This is true for any programming language.


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 3 of 11
(3,315 Views)

0 Kudos
Message 4 of 11
(3,307 Views)

Hello 

 

What should i do to solve this problem

0 Kudos
Message 5 of 11
(3,305 Views)

Hi Nagaa,

 

you should do some error checking before calculating that ACOS: you receive NaN when x is not between -1 and +1 for ACOS...

 

Hint:

There's a joint SIN/COS function, no need for two separate function calls...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 11
(3,302 Views)

hello 

 

Please put your matter in a vi , i am not able to get you

0 Kudos
Message 7 of 11
(3,284 Views)

Hi Nagaa,

 

maybe you get the point now:

check.png

 

Maybe reading some articles on that topic might help too 🙂

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 11
(3,274 Views)

Right click on the indicator & select display format, then select floating point. Then make the precision type as digit of precision & in the digit section enter the digit for precision. If you want 2 digit precision then enter 2.

 

This NaN is actually not a number. Reason for this can be,

  • division of zero by zero
  • square root of a negative number
  • division of an infinity by an infinity
  • logarithm (any base) of a non-positive number
  • any calculation which includes NaN as one of its operands

Make sure this condition.

 

Hope this will help. for better help conver the vi to 2011 compatible. Will deal with it

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 9 of 11
(3,265 Views)

Hi Ranjeet,

 

one more reason for NaN is given in the context help for ACOS - and (I think) that would be the most reasonable here...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 11
(3,259 Views)