LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

floating point math zero

Solved!
Go to solution

Attached my code.  If you run the code with the default input, you will see a few NaN.  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 11 of 19
(1,555 Views)

The calculation of IaLN_RMS results in 4.999999999999996, not 5. Set the dispaly format to show 16 significant digits.  Thus the calculation of Ia_THD is the result of taking the square root of -35.527E-15 = NaN.

 

As others have pointed out this type of calculation can result in errors.

 

Lynn

0 Kudos
Message 12 of 19
(1,545 Views)

Is there a way to limit all the numbers through out my program to 3 decimal points in my calculation?

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 13 of 19
(1,530 Views)
Solution
Accepted by jyang72211

You will still potentially run into problems because decimal fractions don't necessarily have exact binary fractions. One way would be to make a small subVI that multiplies by 1000, rounds to the nearest integer, then divides by 1000 again.

 

Overall, you have way too much duplicate code. Why not operate on arrays?

Message 14 of 19
(1,527 Views)

Hi Alten,

 

How would using array cut down on duplicate code?  I am using cluster, because I am using it to make my code more documented, but it maybe backfiring on me.  I do have to go back to the code and clean it up though.  Can you give me an example of what you mean?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 15 of 19
(1,509 Views)

Here's the THD code case, for example.

 

Your code:

 

Same using arrays:

Download All
Message 16 of 19
(1,495 Views)

Some modifications which highlights the reduced code duplication.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 17 of 19
(1,477 Views)

Hi Yama,

 

I am using 2009.  Can you re-sent code in 2009?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 18 of 19
(1,451 Views)

Hi Alten,

 

That's nice!!!!  I wish I can give you 10 Kudos.  

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 19 of 19
(1,450 Views)