Newsgroups: rec.arts.int-fiction,rec.games.int-fiction
Path: nntp.gmd.de!Dortmund.Germany.EU.net!main.Germany.EU.net!EU.net!www.nntp.primenet.com!nntp.primenet.com!netcom.com!erkyrath
From: erkyrath@netcom.com (Andrew Plotkin)
Subject: Re: [Z-machine] Divison and modulo (was: JZIP/XZIP Patches)
Message-ID: <erkyrathDy81rB.CsE@netcom.com>
Followup-To: rec.arts.int-fiction,rec.games.int-fiction
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> <erkyrathDy1z30.MMD@netcom.com> <slrn548at1.ivk.mike@skaro.lawlib.wm.edu> <Pine.LNX.3.95.960922165609.1217A-100000@adamant.res.wpi.edu> <526n52$en@europa.frii.com> <erkyrathDy7w36.8t0@netcom.com>
Date: Tue, 24 Sep 1996 05:25:58 GMT
Lines: 28
Sender: erkyrath@netcom9.netcom.com
Xref: nntp.gmd.de rec.arts.int-fiction:16522 rec.games.int-fiction:17448

Andrew Plotkin (erkyrath@netcom.com) wrote:
> The Z-spec (0.2) says that both divison and modulo are *unsigned* 16-bit 
> operations.
> (Has there been any discussion on the Z-machine mailing list about this? 
> I can't get into GMD to check.)

Ok, never mind. I got in, and according to the remarks and corrections on 
GMD, everyone agrees that the opcodes are signed after all.

> Furthermore, the expression (a % b), with a and b signed numbers, does 
> not produce consistent results on all machines. Honest! If either a or b 
> is negative, the remainder may be positive *or* negative. This is stated 
> explicitly in the K&R C manual, and the C++ Annotated Reference Manual. 
> (I don't have the ANSI C manual handy, but I'm sure it's the same.) (This 
> is because the division instruction on different CPUs may be wired either 
> way, and compiler authors are too lazy to worry about it. It's not a good 
> reason, but it's the reason.)
>
> If Lurking Horror assumes signed division, we have a problem.

The more common option seems to be that (a % b) always has the same sign 
as a. This would be a thing to standardize on, I guess? Comments?

--Z
-- 

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