LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Quotient & Remainder VI

Using LabVIEW Community Edition 2020, I've found that the Quotient & Remainder VI is not functioning as expected. I don't get an accurate 'Remainder'.

I'm using a loop iteration as a loop counter and plugging the count into the Quotient & Remainder VI. When dividing the count by two, I get a the correct quotient, but if the count is odd the remainder is always rounded up to 1. It should be always be 0.5 for every odd number being divided by two. I checked the property of the remainder indicator and regardless of whether it's set to 'automatic' or 'floating point', the result is the same.

I set up a quick example as shown:

PaulyG123_4-1616179173788.png  PaulyG123_3-1616178267977.png

 

Am I doing something wrong?

 

0 Kudos
Message 1 of 9
(4,578 Views)

@PaulyG123 wrote:

 

 

Am I doing something wrong?

 


High school Algebra.  This is what it's supposed to do.  If you take 9 and divide it into 2 parts, you get a 4, 4, and then one left over.  That's the remainder.

 

What you're expecting it to do is the equivalent of the "floor" function, which this isn't, then give you the difference.  If that's what you want, you can do it... just do normal division, then use the "Round to negative infinity" operator, then take the difference.

0 Kudos
Message 2 of 9
(4,567 Views)

@Kyle97330 wrote:


High school Algebra. 


LOL.  This is not high school algebra.  This is elementary school long division. 

aputman_0-1616182115585.png

 

aputman
Message 3 of 9
(4,540 Views)

On a side note, be aware that Quotient&Remainder is typically uses for all blue inputs and outputs (i.e. integers). While there are some use cases for floating point number (orange), be aware that you might run into unexpected results due to inherent limitations of the datatype.

 

(I agree that the help is a bit sparse. You do get a fractional part directly if Y=1.)

Message 4 of 9
(4,536 Views)

Hmmm, I see... grade school was so long ago...

I was expecting the remainder to be returned as the digits to the right of the decimal place. Especially since the remainder node is a float output. I wasn't looking at it as an integer. 

It's not what I wanted. Searching through the VIs it seems there isn't one for what I want, so I'll have to use my own vi.

Thanks

0 Kudos
Message 5 of 9
(4,438 Views)

As Altenbach mentions, if you divide with 1, you'll get the fractional part. So it sounds like you want to do a normal division and a Q&R with 1 on the result.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 9
(4,429 Views)

@PaulyG123 wrote:

It's not what I wanted. Searching through the VIs it seems there isn't one for what I want, so I'll have to use my own vi.


Yes, just do your own and wrap it into a malleable VI so it works for SGL, DBL, and EXT as well as for arrays of those.

 

Here's one possible idea (again, be aware of certain floating point limitations):

altenbach_0-1616604389444.png

My guess is that this is less expensive than Q&R with a 1 as lower input.

 

And if you want both parts, here's what you could do (modify as needed if you want to deal differently with negative inputs):

 

altenbach_1-1616605220188.png

 

 

Message 7 of 9
(4,427 Views)

@Yamaeda wrote:

As Altenbach mentions, if you divide with 1, you'll get the fractional part. So it sounds like you want to do a normal division and a Q&R with 1 on the result.


Be careful, because you might not get what you expect if the input is negative:

 

altenbach_0-1616605807118.png

 

Message 8 of 9
(4,415 Views)

Why not just divide the remainder by the divisor again?  Very simple.  

aputman_0-1616605901923.png

aputman
0 Kudos
Message 9 of 9
(4,414 Views)