Re: Sign conventions for remainder
From: Keith A. Lewis (lewis_at_PROBE.mitre.org)
Date: 06/17/04
- Next message: Rick Decker: "Re: My results, concrete and real"
- Previous message: Craig Feinstein: "A great puzzle"
- In reply to: Michael Stemper: "Sign conventions for remainder"
- Next in thread: G. A. Edgar: "Re: Sign conventions for remainder"
- Reply: G. A. Edgar: "Re: Sign conventions for remainder"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Jun 2004 18:09:26 +0000 (UTC)
mstemper@siemens-emis.com (Michael Stemper) writes in article <200406171732.i5HHWRG37280@mickey.empros.com> dated 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?
My opinion: The remainder is a piece of the dividend; therefore it should
have the same sign, regardless of the sign of the divisor.
This has the result of always rounding your quotient toward 0 rather than
away, which seems intuitive. You wouldn't want -1/100 = -1 rem. 99, would
you?
--Keith Lewis klewis {at} mitre.org
The above may not (yet) represent the opinions of my employer.
- Next message: Rick Decker: "Re: My results, concrete and real"
- Previous message: Craig Feinstein: "A great puzzle"
- In reply to: Michael Stemper: "Sign conventions for remainder"
- Next in thread: G. A. Edgar: "Re: Sign conventions for remainder"
- Reply: G. A. Edgar: "Re: Sign conventions for remainder"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|