Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 (Denver Mods 4/2/84) 6/24/83; site drutx.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!drutx!qwerty From: qwerty@drutx.UUCP (JonesBD) Newsgroups: net.lang.c Subject: Re: modulus fn with negatives Message-ID: <1011@drutx.UUCP> Date: Wed, 29-Aug-84 10:38:40 EDT Article-I.D.: drutx.1011 Posted: Wed Aug 29 10:38:40 1984 Date-Received: Thu, 30-Aug-84 01:31:24 EDT References: <212@digi-g.UUCP> Organization: AT&T Information Systems Laboratories, Denver Lines: 18 K&R states the following re: % operator: 1) operator yields remainder of division of first exp. by second exp. There are further statements under division about remainders: 2) It is always true for b != 0 that (a/b)*b + a%b = a 3) "On all machines covered by this manual, the remainder has the same sign as the dividend." 4) When positive integers are divided, truncation is toward zero, but the form of truncation is machine-dependent if either operand is negative. From the above, in particular 3), it seems that a%b with 'a' negative should return a negative number. However, the also seems to be considerable phrasing present to indicate that machine dependencies may cause problems with code portability. Its so nice to use a tight, well defined language :-).