Re: Bug in expr ?



Darren New wrote:
> Eric Hassold wrote:
>> Note however that remainder (aka modulo) is negative,
>
> The basic flaw here is that "remainder" and "modulo" are *not* the same
> thing. Modulo numbers are never negative. Remainder can be whatever you
> want to call it. :-) Modulo isn't, in algebra, even an operator, any
> more than the "unsigned" keyword in C is an operator.
>
> (Indeed, I beleve Ada actually has both "remainder" and "modulo"
> operators.)
>

"Modulo" has multiple meanings, especially accoring to context, e.g. mathematics vs. computing. I used to be a mathematician working in computer algebra area, so could enjoy how difficult it happens to be for mathematicians and programmers to communicate and share the same language! ;-) Probably something to do with accuracy vs. pragmatism :-)

Since we are talking about computers here, I was refering to the modulo operation. From http://en.wikipedia.org/wiki/Modulo_operation :
"in computing, the modulo operation finds the remainder of division of one number by another".

So saying modulo is an operator, and remainder the result of that operation is acceptable. But I agree I'm often using english acronyms the wrong way, and "aka" was somehow abusive.


However, I don't believe remainder is "whatever I want to call it either".
http://en.wikipedia.org/wiki/Remainder#The_case_of_general_integers

QUOTE:

If a and d are integers, with d non-zero, then a remainder is an integer r such that a = qd + r for some integer q, and with 0 <= |r| < |d|.

When defined this way, there are two possible remainders. For example, the division of -42 by -5 can be expressed as either
-42 = 9x(-5) + 3
or
-42 = 8x(-5) + (-2).
So the remainder is then either 3 or -2.

END OF QUOTE


Applied to problem raised by original poster, we have:
(-9)%10=-9 and (-9)/10=0 because -9 = 0 x 10 - 9 (as in C)
or
(-9)%10=1 and (-9)/10=-1 because -9 = -1 x 10 + 1 (Tcl way to go)

Just hope it shows the original poster there is two valid ways to go, and Tcl goes one while C (and some other languages) goes the other, but none are buggy.

Eric

-----
Eric Hassold
Evolane - http://www.evolane.com/
.



Relevant Pages

  • Re: Representing sets of points
    ... defined in a coordinate system by these ... Given an integer m, we say that "a and b are congruent modulo m", ... This is usually called "division with remainder", ... this is seldom used by mathematicians. ...
    (sci.math)
  • Re: Order modulo p^n (Number Theory)
    ... modulo. ... order via theorems and was getting know where. ... that is the order or the order divides p^n-1. ... powers less than n-1 the expansion dosent give the remainder 1 and the ...
    (sci.math)
  • Re: Integer division, surprising results
    ... > A remainder is always positive, ... Remainders are always positive, but modulo can be ... There are pros and cons for doing it either ...
    (comp.lang.python)
  • Re: do something every 1000 records or so
    ... On May 15, 10:36 am, Richard Senior ... I think you need the modulo operator. ... This gives the remainder of an ... it print only the first time? ...
    (comp.lang.java.programmer)
  • Re: % operator incompatibility...
    ... > Try Pascal and Ada as well. ... Fortran defines two functions: ... MODULO - the modulo function ... I think the confusion arises because people assume that the remainder ...
    (comp.lang.tcl)

Loading