From 7791119418550552135
X-Google-Thread: f78e5,c063db358aabf0d8
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: "Maarten Kronenburg" <M.Kronenburg@inter.nl.net>
Newsgroups: comp.std.c++
Subject: Re: Integer division specification
Date: Tue, 20 Feb 2007 17:17:01 CST
Organization: InterNLnet Usenet News service
Lines: 37
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <45db7bed$0$7365$19deed1b@news.inter.NL.net>
References: <n5u5t219ouhheqn399kchuhhrd3jm7er69@4ax.com> <k9odt25148b6olt421jip03kqqbcq4meo1@4ax.com> <45d8adcb$0$7365$19deed1b@news.inter.NL.net> <e16jt2db2qgajj6vdp2ss1g3dcpt7jkj68@4ax.com> <45db3f12$0$428$19deed1b@news.inter.NL.net> <87y7msh56h.fsf@news.bourguet.org>
X-Trace: 1172012013 news.inter.NL.net 7365 217.149.216.145:3025
X-Complaints-To: abuse@inter.NL.net
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
X-Virus-Check: ClamAV 0.86.2/2614 on emr1.eu.uu.net; Tue, 20 Feb 2007 22:53:34 +0000
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Xref: g2news2.google.com comp.std.c++:5661


"Jean-Marc Bourguet"  wrote
> > After all, when -4 / 3 == -2 (instead of -1), while 4 / 3 == 1, then
> > obviously something strange is going on.
>
> You can wonder why Knuth defined MMIX so that its division operates this
> way.  See also http://mathworld.wolfram.com/IntegerDivision.html which
> define integer division in exactly that way.
>
> Practically, I remember few use of integer division or remainder with
> negative operands.  All divisions needed the version C99 mandates.  Things
> change when you consider the remainder: the two versions seems to me about
> as usefull.
>
> For what it worth, Ada defines / as Fortran, but has two remainder
> operators: mod (which is periodic) and rem (which is odd).
>
When / truncates toward zero, then rem (calling it %) is truly the
remainder:
a = ( a / b ) * b + a % b
When / truncates toward -inf, then mod is the remainder.
Now when in Fortran and C99 / truncates toward zero, as most hardware does,
then it seems to me that in C++ / should also truncate toward zero, simply
following Fortran and C99. Then it follows that rem is the remainder,
calling it % as above.
Luckily rem is more like the word remainder than mod is, because mod is an
abbreviation of modulo. Most mathematical texts however mix remainder and
modulo together, which causes all the confusion.
Regards, Maarten.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



