Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site abic.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!cwruecmp!abic!jst From: jst@abic.UUCP (Shack Toms) Newsgroups: net.lang.c,net.arch Subject: Re: Integer division Message-ID: <736@abic.UUCP> Date: Thu, 13-Feb-86 11:02:54 EST Article-I.D.: abic.736 Posted: Thu Feb 13 11:02:54 1986 Date-Received: Sat, 15-Feb-86 02:09:20 EST References: <11603@ucbvax.BERKELEY.EDU> <4917@alice.UUCP> <11671@ucbvax.BERKELEY.EDU> <731@abic.UUCP> <11774@ucbvax.BERKELEY.EDU> Organization: Allen-Bradley Co., Highland Heights, OH 44143 Lines: 23 Xref: watmath net.lang.c:7859 net.arch:2514 > In article <731@abic.UUCP> jst@abic.UUCP (Shack Toms) writes: > >However: One might use a%b<0 iff a<0 in an algorithm which printed > >the value of an integer in a given radix. The least significant > >digit of a in radix b would then be |a%b|. :-) > > So would |a|%b, and it works under either convention. :-) Except that |a| is not available for the full range of a. In particular, on a 16 bit computer |-32768| is not expressible. The real point [of the :-)] is that it is just as easy to correct the result of a%b in the range [0..b) as it is to perform the absolute value function. That is: result = a%b; if (result < 0) result = -result; is no easier than result = a%b; if (a < 0) result = b - result; Shack Toms