Path: utzoo!attcan!uunet!mcsun!cernvax!chx400!bernina!neptune!inf.ethz.ch!brandis From: brandis@inf.ethz.ch (Marc Brandis) Newsgroups: comp.lang.c Subject: Re: % operator with negatives Message-ID: <18140@neptune.inf.ethz.ch> Date: 13 Dec 90 16:22:52 GMT References: <1990Dec12.185714.7169@mp.cs.niu.edu> <1990Dec12.205416.26622@zoo.toronto.edu> <7461:Dec1310:04:0990@kramden.acf.nyu.edu> Sender: news@neptune.inf.ethz.ch Reply-To: brandis@inf.ethz.ch (Marc Brandis) Organization: Departement Informatik, ETH, Zurich Lines: 23 In article <7461:Dec1310:04:0990@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >In article <1990Dec12.205416.26622@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >> In article <1990Dec12.185714.7169@mp.cs.niu.edu> t901908@mp.cs.niu.edu (Joe Adamo) writes: >> >I know this may sound silly, but what is the effect of using the >> >% (mod) operator with negatives? I can't seem to find any info on it. >> If you're asking the obvious question -- "what's the sign of the remainder?", >> i.e. "which way does the rounding of the quotient go?" -- there is no >> portable answer. It's implementation-specific. > >And if you're asking ``Where is the information on it?'', the answer is >that a % b is defined so that (a / b) * b + (a % b) equals a. It's the >ambiguous definition of / that makes % so useless with negatives. > Did somebody ever try it on the VAX? A guy told me once that integer division rounds toward zero on the VAX while the MOD instruction delivers always a positive result, which does not fulfill the above equation. Or does the VAX have a separate REM instruction? At least for Pascal it is completely wrong. Marc-Michael Brandis Computer Systems Laboratory, ETH-Zentrum (Swiss Federal Institute of Technology) CH-8092 Zurich, Switzerland email: brandis@inf.ethz.ch