% operator with negatives

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Thu Dec 13 21:04:09 AEST 1990


In article <1990Dec12.205416.26622 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
> In article <1990Dec12.185714.7169 at mp.cs.niu.edu> t901908 at 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.

---Dan



More information about the Comp.lang.c mailing list