Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site ism780c.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!pyramid!hplabs!sdcrdcf!ism780c!tim From: tim@ism780c.UUCP (Tim Smith) Newsgroups: net.math Subject: Integer division Message-ID: <332@ism780c.UUCP> Date: Mon, 27-Jan-86 22:48:14 EST Article-I.D.: ism780c.332 Posted: Mon Jan 27 22:48:14 1986 Date-Received: Thu, 30-Jan-86 04:44:29 EST Distribution: net Organization: Interactive Systems Corp., Santa Monica, CA Lines: 31 A recent discussion on net.arch raised the problem of defining integer division for negative numbers. Most computers seem to say that -3/2 is -1, and -3%2 is -1. Many people thought this was fine, but some of us think that -3/2 should be -2, and -3%2 should be 1. Both sides agree that integer division on computers must be defined to satisfy (1) (a/b)*b + a%b = a. Everyone agreed that for positive a and b, a/b should round toward zero. The people who want -3/2 to be -1 argue that the following should hold: (2) (-a)/b = -(a/b). Those of us who want -3/2 to be -2 want the following to hold: (3) a%b for positve b has a range of [0,b-1], not [-b+1,b-1], and (4) (a+b)/b = a/b + 1. Are there any good mathematical grounds for choosing one alternative over the other here? Note that I am not asking from a hardware point of view which is better. I want to know mathematically if one is better than the other. My opinion is that (3) and (4) are more important properties than (2), but when I was a math major my major interest was number theory, where (3) and (4) are more useful than (2). [ I have been havig trouble with my mailer, so please respond to net.math ] -- Tim Smith sdcrdcf!ism780c!tim || ima!ism780!tim || ihnp4!cithep!tim