Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!exodus!ringworld.Eng.Sun.COM!eager From: eager@ringworld.Eng.Sun.COM (Michael J. Eager) Newsgroups: comp.lang.c Subject: Re: % operator with negatives Message-ID: <4818@exodus.Eng.Sun.COM> Date: 19 Dec 90 03:25:39 GMT References: <1990Dec12.185714.7169@mp.cs.niu.edu> Sender: news@exodus.Eng.Sun.COM Distribution: na Organization: Sun Microsystems, Mt. View, Ca. Lines: 18 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. There are two well accepted definitions of the remainder of a division when one of the arguments is zero. One of the definitions has the remainder be negative, the other positive. The ANSI Standard does not specify which definition applies. The only guarantee is that when you have q = d / n; r = d % n; that d == (q * n + r) Best advice is to not use the % operator with negative values. -- Mike Eager