From: Chris Gehlker Date: 2006-08-11T21:36:34+09:00 Subject: Re: Confused by Bignum#remainder On Aug 11, 2006, at 2:16 AM, Michael Ulm wrote: > Chris Gehlker wrote: > > --snip-- >> A couple of years ago I took a discrete math course and was very >> surprised to find division defined as: >> "Let a be an integer and d a *positive* integer. Then there are >> unique integers q and r, with 0 .le. r .le d, such that a = dq + >> r. Apparently my elementary school teacher had lied to me by >> saying that division was even defined for a non-positive divisor. >> Furthermore, an examination of the above definition will show >> that my calculator has always lied to me for negative dividends >> since the remainder must by definition be non-negative. > --snip-- > > You do not understand the difference between a theorem and a > definition. Actually, i do. I was just trying to state the so called "division algorithm". > The statement you quote is a theorem. It does not define division but > states a property of the integers. This property as stated holds if > the > assumptions of the theorem (d is a positive integer) hold. This > theorem > then can be used to define the modulo function. I think you may be missing the point. The theorem can be used to define *a* modulo function but not one which will serve to answer the original question which was about the case where the assumption that d is positive does not hold. My, rather trivial, point was that language implementors do what feels right to them in this case and who can blame them? The more interesting case is when the dividend is negative. Here Ruby does the 'right thing' but many languages do not. -- A young idea is a beautiful and a fragile thing. Attack people, not ideas.