03-19-2021 01:40 PM
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:
Am I doing something wrong?
03-19-2021 01:46 PM - edited 03-19-2021 01:48 PM
@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.
03-19-2021 02:28 PM
@Kyle97330 wrote:
High school Algebra.
LOL. This is not high school algebra. This is elementary school long division.
03-19-2021
02:42 PM
- last edited on
05-05-2025
03:52 PM
by
Content Cleaner
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.)
03-24-2021 11:24 AM
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
03-24-2021 11:48 AM
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.
03-24-2021
11:49 AM
- last edited on
05-05-2025
03:53 PM
by
Content Cleaner
@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):
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):
03-24-2021 12:11 PM
@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:
03-24-2021 12:13 PM
Why not just divide the remainder by the divisor again? Very simple.