Newsgroups: rec.arts.int-fiction
Path: nntp.gmd.de!news.ruhr-uni-bochum.de!news.rwth-aachen.de!newsserver.rrzn.uni-hannover.de!hrz-ws11.hrz.uni-kassel.de!news.th-darmstadt.de!nntp.zit.th-darmstadt.de!fu-berlin.de!informatik.tu-muenchen.de!Germany.EU.net!main.Germany.EU.net!EU.net!howland.erols.net!www.nntp.primenet.com!nntp.primenet.com!netcom.com!erkyrath
From: erkyrath@netcom.com (Andrew Plotkin)
Subject: Re: [Z-machine] Divison and modulo
Message-ID: <erkyrathDyEBJB.3pE@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
X-Newsreader: TIN [version 1.2 PL1]
References: <Pine.LNX.3.95.960920173018.5222G-100000@adamant.res.wpi.edu> <erkyrathDy81rB.CsE@netcom.com> <erkyrathDy9vG3.BFG@netcom.com> <52e818$is2@wanda.vf.pond.com> <52e876$j1h@wanda.vf.pond.com> <erkyrathDyCqCD.HAr@netcom.com> <324AEF90.20AF@thuridion.com>
Date: Fri, 27 Sep 1996 14:42:47 GMT
Lines: 31
Sender: erkyrath@netcom.netcom.com

John Francis (johnf@thuridion.com) wrote:
> > > }}(I should add that if a compiler uses this rule -- that (A % B) always
> > > }}has the same sign as A -- it will also follow the rule that (A / B) is
> > > }}rounded towards zero, not towards negative infinity.)
> > > }
> > > (A / B) * B + (A % B) = A

> Erm ... This seems to be very, very wrong.
> The sign of (A % B) should not depend on the sign of A. It could
> depend on the sign of B, or it could be required to be positive.
>
> (-2 % 5) should be 3, not -2.

Your position is consistent, but in fact all C and C++ compilers that 
I've tested don't do it that way. It seems best to have the @MOD opcode 
(which is generated by Inform's % operator) work like the more common C % 
operator.

I believe the C++ ARM remarks that "remainder" would be a better name for 
the % operator than "modulo." Consider it a misnomer rather than a bug.

(In fact, I find arithmetic modulo more useful in IF programming, and 
even in general programming. Thus the safe_div and safe_mod functions, 
which I posted at the beginning of this thread.)

--Z

-- 

"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
borogoves..."
