LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

The Quotient & Remainder function gives incorrect results!

I am trying to use the Quotient & Remainder function from the Numeric palette within a timed loop to initiate data logging at an interval that is a multiple of the loop time; however, it doesn't work because the remainder output is not always correct.  The two attached LabVIEW code snippets demonstrate this problem.  The remainder output should be calculated identically in both examples but they are sometimes incorrect in each and don't even agree with each other.
 
I have used this technique before with older version of LabVIEW, even with LabVIEW 8 but not in a timed loop, and all worked fine so am I doing something wrong within the timed loop or is this a bug with LabVIEW 8?
0 Kudos
Message 1 of 4
(2,578 Views)
The answer to your two questions is no.  The problem is not with the Q & R or with the timed loop; it is a problem with the number 1.  Actually, you don't have a number 1.  You have the valude of 0.9999999999999998890 in the Logging Interval control.  This is what is causing your unforseen answers.  This is a fairly common floating point problem.  I am guessing that you did not enter 1 into the control, but rather it is the result of a calculation and then the code was simplified (presumably to highlight the problem).

I hope that this helps,
Bob Young

Message 2 of 4
(2,567 Views)
Actually, there was a very lenghty discussion as to whether this was a bug or not here. I don't think that the Q&R function was meant to be used on floating point numbers. Usually it is used with whole integers. That is the whole idea of quotient and remainder. The current Q&R works as intended, it is just that computers have a problem when working with whole numbers that are represented as floating point numbers. The number 1 might be represented as 0.99999999999998 when defined as a SGL or DBL. When defined as U32 it is exactly 1. I would refrain from using Q&R on floating point numbers.
- tbob

Inventor of the WORM Global
Message 3 of 4
(2,552 Views)
Good point and a better reply than mine.  I forgot about the other thread (I only read a couple pages woth of posts before I lost interest). 

Thanks,
Bob Young

0 Kudos
Message 4 of 4
(2,540 Views)