Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!ncar!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: % operator with negatives Message-ID: <2882:Dec1618:47:3190@kramden.acf.nyu.edu> Date: 16 Dec 90 18:47:31 GMT References: <1990Dec12.205416.26622@zoo.toronto.edu> <7461:Dec1310:04:0990@kramden.acf.nyu.edu> <1529@bbxsda.UUCP> Organization: IR Lines: 18 In article <1529@bbxsda.UUCP> scott@bbxsda.UUCP (Scott Amspoker) writes: > In article <7461:Dec1310:04:0990@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: > >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. > Well I can really stir up the muck by pointing out that, by definition, > a mod 0 == a We are (unfortunately) not talking about the mathematical mod function. We are talking about the C % function. I have never seen a sane use of remainders outside [0,b), b positive. I have never seen a program use remainders for b negative. It's a shame that no popular programming language has a mod function defined only for b positive and guaranteed to be between 0 and b - 1 inclusive, as this would strike the right balance between portability and efficiency. ---Dan