As a Mathematician I would like:

S. S at s.com
Tue Jul 3 15:26:39 PDT 2007


Stephen Montgomery-Smith Wrote:

> S. wrote:
> > Stephen Montgomery-Smith Wrote:
> > 
> >> 2. a%b has a very definite and unambiguous meaning when a is negative, 
> >> and b is positive. The output should be non-negative. This is something 
> >> perl has done right.  For example (-6)%7 is 1.
> > 
> > That's not true.  There is two definitions of the 'mod' operator for negative numbers.  Depends on how you define the operator itself.
> > 
> > -6%7 is equally 1 or -6. 
> > 
> > Long division makes extensive use of remainders for calculations, if you were to say the initial calculation was 7*-1 remainder 1, then you would have a very wrong answer doing division by hand.
> > 
> > See: http://en.wikipedia.org/wiki/Modulo_operation
> > and http://mathforum.org/library/drmath/view/52343.html
> 
> After reading these, I get the sense that they side a lot more with my 
> position, vis (-6)%7=1.
> 
> Long division as I have used it never has negative numbers in the 
> remainder operations.

It also doesn't take your definition of the modulo operation because you're not defining the modulo to be the "remainder."  Long division requires dividing into the absolute value and taking the positive or negative result as needed.

There are purposeful uses of both definitions. So,  they should both be at the disposal of the programmer.  That's all I'm saying.



More information about the Digitalmars-d mailing list