04-02-2012 11:13 AM
In labview, if you divide fractional numbers, you end up with a rounding error.
For example if you use quotient/remainder and divide 0.6/0.2 the quotient should be 3, but it is 2 instead. This acts exactly the same as doing that divide and then using "round toward -infinity".
04-02-2012 11:37 AM
Hi,
That is not a LabVIEW error, is a computational error from representing fractional numbers at binary (IEEE-754)
0.6 = 5.9999996e-1
0.2 = 2.0000000e-1
Best regards,
04-02-2012 11:44 AM
You owe me a nickel for my retirement fund.
04-02-2012 02:03 PM
OK, thanks.
My solution is to add 0.000001 to the dividend, that seems to work, at least for my application.
04-02-2012 05:01 PM
@Kier wrote:
My solution is to add 0.000001 to the dividend, that seems to work, at least for my application.
That does not sound like a general and robust solution. Try it with 0.0000000000000006/0.0000000000000002 😮
04-03-2012 07:42 AM - edited 04-03-2012 07:44 AM
@Kier wrote:
OK, thanks.
My solution is to add 0.000001 to the dividend, that seems to work, at least for my application.
This value only makes sense if you use single precision floating point number and the whole part of your number only has one digit. It is meaninful because single precision floating point values have about 7 significant digits in decimal representation. Double precision have about 16 significant digits and you would have to change your number again.
Your value would be to small if you want to avoid rounding errors for numbers having 2 or more digits in the whole number part and the operator to use on this correction would also depend on the operator you want to use for the calculation.