Re: Sign conventions for remainder

From: Gerry Myerson (gerry_at_maths.mq.edi.ai.i2u4email)
Date: 06/17/04


Date: Fri, 18 Jun 2004 09:47:29 +1000

In article <200406171732.i5HHWRG37280@mickey.empros.com>,
 mstemper@siemens-emis.com (Michael Stemper) wrote:

> Just for fun, I've been implementing a package to perform arithmetic on
> integers of arbitrary size. Addition, subtraction, and multiplication
> were all pretty straight-forward. (Subtraction was the easiest!) But,
> when I prepared to implement division, I realized that I'm not aware of
> the conventions for remainders.
>
> If the divisor and the dividend are both positive, I know that my result
> should be d = n*q+r, with 0<=r<n. What if one of them is negative? Should
> the remainder still be in that range? Should it be in the negative of that
> range? What about if both the divisor and the dividend are negative?
>
> Yes, I am aware that there is no "right" answer to this, there are only
> conventions. But, that's exactly what I'm looking for. Conventions are
> usually established because they're useful.

The convention in number theory is non-negative remainders;
0 less than or equal to r less than absolute value of n.

-- 
Gerry Myerson (gerry@maths.mq.edi.ai) (i -> u for email)