Beware: Hackers - (nf) - integer division

usenet usenet at abnjh.UUCP
Fri Jan 13 03:56:45 AEST 1984


>> The four most obvious possibilities can be summed
>> up in terms of their effects on a non-zero remainder:
>> 
>> 	1. Remainder has same sign as dividend.
>> 	2. Remainder has same sign as divisor.
>> 	3. Remainder is always positive.
>> 	4. Magnitude of remainder is minimized, with some decision rule
>> 		for resolving ties (e.g. 5 div 2 == <2, 1> or <3, -1>).
>> 
>> 3 is a bit odd.  

Not at all, 3 is what most mathematicians would say is *the* correct
way to divide two integers.  It is most convenient for doing modulo
arithmetic.  The result of doing n mod m is always less than m and
greater or equal to zero.

Rick Thomas



More information about the Comp.lang.c mailing list