Janeice DelVecchio wrote:So the language specification states that the remainder when dividing 0 by 15 is 0?
I mean, if you do long division, you do have a remainder of 15 (unlike Devaka's beautiful picture shows).
I'm confused why this is and who thought it would be a good plan to say they'll make the expression evaluate differently if it is with a 0 divisor.
Is 0 the divisor or the dividend? Up until now, I thought we were talking about 0/15 rather than 15/0. For 0/15, 0 is the dividend, and 15 is the divisor. The quotient is 0, and the result is 0.
As a general rule, the dividend should equal the divisor times quotient, plus the remainder. For example if we divide 14 by 3, we get a quotient of 4 with a remainder of 2. If we multiply divisor 3 by quotient 3, we get 12, and if we add the remainder 2, we get 14, which is the dividend.
How does this apply to 0/15? Can we agree the quotient here is 0? If you say the remainder is 15, then when we calculate (divisor * quotient) + remainder we get (15 * 0) + 15 = 15 - that's supposed to add up to the dividend. Except that the dividend was 0. So how could the remainder have been 15? That doesn't work.
Instead, the remainder is 0. Now (divisor * quotient) + remainder = (15 * 0) + 0 = 0, which was the dividend. As we expect. All is right in the world again.
So, defining 0/n to have a remainder of 0 is not just a Java specification thing. It's the way remainder has always been defined, as far as I know.
Mike Simmons wrote:
So, defining 0/n to have a remainder of 0 is not just a Java specification thing. It's the way remainder has always been defined, as far as I know.
What? I'm not a math major and I'm incredibly confused by your whole post.
If you have no pies and you try to divide them to feed 15 hungry friends, you have no friends fed with a remainder of 15 hungry friends.
A remainder is how much is left over in the dividend after dividing into the divisor, right?
Fifteen goes into zero no times with a remainder of fifteen.
So saying that the modulo is "the remainder" is not correct?
Janeice DelVecchio wrote:If you have no pies and you try to divide them to feed 15 hungry friends, you have no friends fed with a remainder of 15 hungry friends.
You have 15 hungry friends, but they aren't the remainder. When you divide 0 pies among 15 friends, they each get 0 pies (the quotient) and you have 0 pies left over (the remainder). The remainder in this problem should be the number of pies left over, not the number of friends.
Janeice DelVecchio wrote:A remainder is how much is left over in the dividend after dividing into the divisor, right?
Yes - what's left over from the dividend. Which was zero pies. The 15 friends were never part of what was being divided up - they were who it was divided up amongst.
Janeice DelVecchio wrote:Fifteen goes into zero no times with a remainder of fifteen.
Obviously, I still disagree.
Janeice DelVecchio wrote:So saying that the modulo is "the remainder" is not correct?
It is correct, at least for positive numbers. (There may be a subtle definition issue for negative numbers; don't remember and don't care at the moment.)
This is a very interesting concept. I never considered the remainder being what's left of the top number or the bottom number...
I thought it was what "couldn't fit" and is thereby left over... and I never really thought (since third or fourth grade) about how the number was derived.
I suppose I never thought about it critically. It makes sense.
There are several different ways to calculate a remainder; I believe the % operator in Java is "Euclidean", ie remainder + quotient * divisor gives the original dividend back. There is a thing called IEEERemainder, which is used by the BigDecimal class; that is slightly different.