Path: utzoo!attcan!uunet!cs.utexas.edu!titan!drack From: drack@titan.tsd.arlut.utexas.edu (Dave Rackley) Newsgroups: comp.lang.c Subject: Re: % operator with negatives Message-ID: Date: 13 Dec 90 17:25:49 GMT References: <1990Dec12.185714.7169@mp.cs.niu.edu> <14722@smoke.brl.mil> Sender: news@titan.tsd.arlut.utexas.edu Organization: Applied Research Laboratories, University of Texas at Austin. Lines: 27 In-reply-to: gwyn@smoke.brl.mil's message of 12 Dec 90 20:40:18 GMT 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. In article <14722@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >Two things: % is NOT a modulo operator; it's a remainder operator, which >is not the same thing. Also, for negative operands there are >implementation-dependent aspects to the result obtained; in most >applications you should avoid using negative operands. Hmmm? You answer is correct, except _K & R 2d edition_, page 41, refers to % as the modulus operator. Prentice Hall must have missed it during their review. I agree, one should avoid negative operands with %. -- DISCLAIMER? I don't know anything 'bout any ol' disclaimer! +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+ | David Rackley | | | Applied Research Laboratories | It's OK to be a martyr, as long as | | The University of Texas | you don't bring your own firewood. | | Austin, TX. 78758 | -- Dr. James Rigby | +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+