modulus fn with negatives

JonesBD qwerty at drutx.UUCP
Thu Aug 30 00:38:40 AEST 1984

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

>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 :-).

More information about the Comp.lang.c mailing list