On Fri, 18 Apr 2008 at 17:14:06, in comp.lang.c++.moderated, OuFeRRaT
wrote:
>The definition of the remainder:
>
>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|.
Dividing a by b to give quotient q and remainder r is expected to give a
result that obeys the equation
a = b*q + r
Now, if the numbers are Natural numbers, {0, 1, 2, ...}, then when
a < b there is only one solution, q = 0, r = a. If a >= b then there is
more than one solution. We want a rule that picks solutions that are
clean and convenient. The rule is
b is non-zero and r < b.
Luckily this rule always picks a single answer for q and r. Application
areas where a different rule is desirable appear to be rare.
But if the numbers are Integers, { ... -2, -1, 0, 1, 2, ... }, then
there is an infinite number of solutions in every case. A rule that
picks clean and convenient solutions will make r close to zero, but
different application areas have different needs for the sign of r and
can have cases where r = 0 is not allowed.
For instance, a distance to the left of 275 cm will translate to -2 m
followed by -75 cm.
For instance, a payment of 275 cents will translate, relative to you, to
-3 dollar bills followed by +25 cents change.
It wouldn't be sensible to decree that one of these calculations is
wrong. Indeed, picking the most appropriate rules is the essence of
applied mathematics.
>This is the correct mathematical definition, as explained in the first
>week of any basic maths course, this is why I used the word
>"incorrect".
It's normal practice to give beginning students a simplified definition.
Only later, when they have more experience, are they told about all the
complications.
>I didn't say it was a bad idea that in C++ (and possibly other
>programming languages) they decided to make another definition for the
>integer division and the remainder , but I would like to know why.
It's very simple : different areas of applied mathematics need different
definitions.
>Thomas, "chip manufacturers aren't certain either which definition to
>pick for the modulo operation." Has it anything to do with the
>efficiency of the operation or it's that they haven't asked a
>mathematician?
<snip>
It may be that the algorithm runs faster, or maybe they've consulted
their Fortran compiler team who want the Fortran benchmarks to run as
fast as possible.
John
--
John Harris
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|