08-24-2015 05:13 PM
I can't seem to figure out why this is happening. Code attached. In the actual code I use, the 1/25 and the 62 come from global variables, if that helps. The 25 is input via a control as 25, and then the reciprocal is applied before storing in the global. All data types are standard Double Precision Floats.
08-24-2015 05:20 PM - edited 08-24-2015 05:24 PM
Your result is actually 14.879999999999999000 (show sufficient significant digits!)
Computers operate in binary and amy nice decimal fractions cannt be expressed as a nice fraction in base 2. This is normal and there are many existing discussions about that.
Your comparison with the machine epsilon is also flawed.
08-24-2015 05:26 PM
ALso note that the order of operation matters. If you would wire the 1/25 at the bottom of the compond node, the difference is zero.
08-24-2015 05:27 PM
Here is a picture of what altenbach said.
Lynn
08-24-2015 05:29 PM
08-24-2015 05:33 PM
The result is random and you cannot guarantee that any specific order produces a "better" result than any other order. The computer does not know what result you want. 😉
08-24-2015 05:34 PM
08-24-2015 05:39 PM
1/25 cannot be represented exactly in binary. So any calculation using that value will give a result different from the exact mathematical value. Attempting to rely on specific round off behavior to get what you want is likely to result in frustration.
Look at the precision of the values and the accuracy of the sources (if measured data). Consider noise in any measurements. Then assign an appropriate tolerance to the comparison. That way you control the decison making process to be consistent with your data and what you are doing with it.
Lynn