Sign conventions for remainder

From: Michael Stemper (mstemper_at_siemens-emis.com)
Date: 06/17/04


Date: Thu, 17 Jun 2004 12:32:27 -0500

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.

-- 
Michael F. Stemper
#include <Standard_Disclaimer>
Reunite Gondwanaland!


Relevant Pages

  • Re: Sign conventions for remainder
    ... Addition, subtraction, and multiplication ... What about if both the divisor and the dividend are negative? ... The remainder is a piece of the dividend; ...
    (sci.math)
  • Re: Sign conventions for remainder
    ... Addition, subtraction, and multiplication ... > the conventions for remainders. ... What about if both the divisor and the dividend are negative? ... the remainder should still be in the range ...
    (sci.math)
  • Re: Sign conventions for remainder
    ... Addition, subtraction, and multiplication ... > the conventions for remainders. ... What about if both the divisor and the dividend are negative? ... The convention in number theory is non-negative remainders; ...
    (sci.math)
  • Re: Dividing 512 bit number by 128 bit number in C program
    ... calculating the quotient and the remainder before returning. ... In one of the inner loops, the divisor is positioned so that its most ... A bit-wise subtraction of divisor from dividend is performed ... bool borrow = false; ...
    (sci.crypt)