Re: Negative Modulus
From: Mok-Kong Shen (mok-kong.shen_at_t-online.de)
Date: 03/15/04
- Next message: Phil Carmody: "Re: factoring massive numbers and geometry"
- Previous message: Mok-Kong Shen: "Re: Countering chosen-plaintext attacks"
- In reply to: Douglas A. Gwyn: "Re: Negative Modulus"
- Next in thread: Dennis Ritchie: "Re: Negative Modulus"
- Reply: Dennis Ritchie: "Re: Negative Modulus"
- Reply: Douglas A. Gwyn: "Re: Negative Modulus"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Mon, 15 Mar 2004 22:27:51 +0100
Douglas A. Gwyn wrote:
> Mok-Kong Shen wrote:
>
>>Both answers are correct. ...
>
>
> Actually the real issue is which of the infinite possibilities should be
> chosen for "the" answer. For positive modulus m the convention is to
> choose the answer in the range [0,m-1]. Since negative moduli are much
> less commonly used, any such convention for them is not as well
> established. There are probably some technical advantages in one choice
> rather than the other; I'm pretty sure Knuth discusses this in Vol. 1 of
> TAOCP, but my copy isn't at hand at the moment.
I have a question about C: For integers a and b, how is
a%b defined by the standard? (I unfortunately don't have
the document to check that myself.)
In Fortran one has, for example,
mod(8,5)=3, mod(-8,5)=-3, mod(8,-5)=3, mod(-8,-5)=-3.
It's interesting that Fortran has also a related function
'modulo' with
modulo(8,5)=3, modulo(-8,5)=2, modulo(8,-5)=-2, modulo(-8,-5)=-3.
I 'vaguely' remember that Pascal's convention is not identical
to at least one of the other PLs. If indeed it's true that
several major PLs differ in the conventions for mod, then it
would mean a certain potential pitfall for those people who
need to frequently switch PLs in their programming work.
M. K. Shen
- Next message: Phil Carmody: "Re: factoring massive numbers and geometry"
- Previous message: Mok-Kong Shen: "Re: Countering chosen-plaintext attacks"
- In reply to: Douglas A. Gwyn: "Re: Negative Modulus"
- Next in thread: Dennis Ritchie: "Re: Negative Modulus"
- Reply: Dennis Ritchie: "Re: Negative Modulus"
- Reply: Douglas A. Gwyn: "Re: Negative Modulus"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|