LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stumped on basic problem with floating point math

Solved!
Go to solution

I can't figure this out!  It should be sooooo simple. 

 

Here is the challenge: 

 

I have an incoming time array.  For example:     0, 1, 2, 3, 4, 5, 6, 7, 8, 9

 

I want to scale this array by a constant (e.g. multiply by 0.1).  So the resulting array should be:     0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9

 

Then I want to calculate the difference between each and every subsequent element in the array.  In this example, the difference should 0.1 between every element.  But my comparison fails. 

 

See the example below.  As far as I can see, the resulting boolean should always be TRUE.  But its not.

 

But if I remove the scaling operation, then it works ok!

 

Please help!Stumped.png

 

 

http://www.medicollector.com
0 Kudos
Message 1 of 4
(2,162 Views)
Solution
Accepted by topic author josborne

It has been awhile since smercurio has had a contribution to his retirement fund, but once again you have "discovered" that there is no exact binary representation for 0.1.

 

I'd use one of the current "almost equals" comparisons described here:

http://forums.ni.com/t5/LabVIEW/Darin-s-Weakly-Nugget-2-8-11/m-p/1444262

 

And vote for this if you haven't already:

http://forums.ni.com/t5/LabVIEW-Idea-Exchange/quot-Almost-Equal-quot-functions-for-Float-comparisons...

Message 2 of 4
(2,149 Views)

@Darin.K wrote:

It has been awhile since smercurio has had a contribution to his retirement fund, but once again you have "discovered" that there is no exact binary representation for 0.1.


Yeah, the little piggy was getting a little light.

 

josborne, you owe me a nickel. Smiley Very Happy

0 Kudos
Message 3 of 4
(2,127 Views)

@smercurio_fc wrote:

josborne, you owe me a nickel. Smiley Very Happy


Don't you mean two bits??? Smiley Very Happy

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
Message 4 of 4
(2,116 Views)