From: "Richard P. Groenewegen" Date: 2000-06-07T11:51:34+02:00 Subject: [ruby-talk:03145] Re: Is divmod dangerous? On Tue, Jun 06, 2000 at 11:12:28PM -0500, Conrad Schneiker wrote: > You could also cross-post a query on comp.lang.python about this, asking: > (1) why it was done the way it was done, (2) what the less-obvious I happen to have an opinion about this issue. For a fixed modulus m the test a%m == b%m should be true if a and b are the same modulo m. In other words, we want a fixed set of representative modulo m (if m is positive, we usually take 0,1,...,m-1) and let a%m be the unique representative that differs a multiple of m with a. So we would want -13%4 to equal 3. Note also that this doesn't break the periodicity: Let m=4: a : 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 a%m: 3 2 1 0 3 2 1 0 3 2 1 0 3 2 I think there are both mathematical and computer scientific advantages to this approach. Now we definitely want a = (a/b)*b + a%b, so now we are almost where python is. For those that think it is unnatural to have (-a)/b unequal to -(a/b) in some cases, the python choice does give us: (a+b)/b == a/b + 1. There is something to be said for that. I have less of an opinion about taking something modulo a negative m, but it seams appropriate to take negative representatives there (as python does). Moreover, we get the relation (-a)/b==a/(-b). So I vote for the python way and let .remainder be the same as %. Richard (number theorist and to be Ruby enthusiast) -- You don't suppose [Microsoft] could "embrace and extend" the law do you? -- lbrlove on slashdot