Re: Bug in expr ?
- From: Eric Hassold <hassold@xxxxxxxxxxx>
- Date: Mon, 03 Jul 2006 01:38:01 +0200
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/
.
- References:
- Bug in expr ?
- From: tunity5
- Re: Bug in expr ?
- From: Michael Schlenker
- Re: Bug in expr ?
- From: tunity5
- Re: Bug in expr ?
- From: Eric Hassold
- Re: Bug in expr ?
- From: tunity5
- Re: Bug in expr ?
- From: stephanearnold
- Re: Bug in expr ?
- From: tunity5
- Re: Bug in expr ?
- From: Eric Hassold
- Re: Bug in expr ?
- From: Darren New
- Bug in expr ?
- Prev by Date: Re: Better approach to extension-specific objects...
- Next by Date: Re: Help in Using a file to record status
- Previous by thread: Re: Bug in expr ?
- Next by thread: Re: Bug in expr ?
- Index(es):
Relevant Pages
|
Loading