Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: -1%N = -1
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 9 of 14 Topic 9512 of 10087
Post > Topic >>

Re: -1%N = -1

by OuFeRRaT <ouferrat@[EMAIL PROTECTED] > Apr 18, 2008 at 05:14 PM

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|.

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".

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.

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?

Thanks,


OuFeRRaT


On Apr 18, 3:33 am, "Maarten Kronenburg" <M.Kronenb...@[EMAIL PROTECTED]
>
wrote:
> "Seungbeom Kim" wrote in message
> > Maarten Kronenburg wrote:
> > > The remainder has the sign of the dividend,
> > > the modulo has the sign of the divisor
> > > (if not zero).
>
> > Are these commonly accepted definitions?
>
> > Remainder seems to allow both cases, and modulo is actually the name
> > of the operation, not the result.
>
> There is indeed much confusion in literature about this.
> The word remainder however means remainder of the quotient, so that:
> (a / b ) * b + a % b = a
> where / is the quotient symbol and % is the remainder symbol in C++.
> The quotient / is here truncated towards zero (as in C and Fortran).
> The modulo as in a mod b however comes from the mathematical
> residue class ring of x modulo y.
> When / would be truncated towards minus infinity, the modulo would be
the
> remainder.
> In my opinion remainder and modulo are thus two different things, but in
> many literature they are taken to be the same thing.
> In the book "Modern Computer Algebra" (2nd ed) by Von zur Gathen and
> Gerhard, on pages 696 and 697, the remainder and the modulo are also
thus
> separately defined.
> Sometimes the remainder is indicated with a rem b and the modulo with a
mod
> b.
> In C and C++ a rem b is indicated with a % b.
> Following these definitions of remainder and modulo, then the sign of
the a
> rem b (if not zero) is the sign of a, and the sign of a mod b (if not
zero)
> is the sign of b.
> Regards, Maarten.



-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 14 Posts in Topic:
-1%N = -1
OuFeRRaT <ouferrat@[EM  2008-04-17 03:52:00 
Re: -1%N = -1
Thomas Richter <thor@[  2008-04-17 11:36:17 
Re: -1%N = -1
Marco Manfredini <ok_n  2008-04-17 11:41:52 
Re: -1%N = -1
Francis Glassborow <fr  2008-04-17 11:43:14 
Re: -1%N = -1
guinness.tony@[EMAIL PROT  2008-04-17 11:41:28 
Re: -1%N = -1
"Maarten Kronenburg&  2008-04-17 12:03:20 
Re: -1%N = -1
Seungbeom Kim <musiphi  2008-04-17 16:15:48 
Re: -1%N = -1
"Maarten Kronenburg&  2008-04-17 19:33:50 
Re: -1%N = -1
OuFeRRaT <ouferrat@[EM  2008-04-18 17:14:06 
Re: -1%N = -1
John G Harris <news0@[  2008-04-19 02:01:59 
Re: -1%N = -1
Thomas Richter <thor@[  2008-04-19 18:12:30 
Re: -1%N = -1
peter koch larsen <pet  2008-04-20 15:46:04 
Re: -1%N = -1
"Maarten Kronenburg&  2008-04-20 15:49:33 
Re: -1%N = -1
John G Harris <news0@[  2008-04-20 15:49:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 17:06:38 CDT 2008.