Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!decvax!necntc!culdev1!drw From: drw@culdev1.UUCP (Dale Worley) Newsgroups: comp.lang.misc,comp.software-eng Subject: Software Technology is NOT Primitive Message-ID: <1720@culdev1.UUCP> Date: Thu, 29-Oct-87 10:56:06 EST Article-I.D.: culdev1.1720 Posted: Thu Oct 29 10:56:06 1987 Date-Received: Tue, 3-Nov-87 04:23:01 EST Organization: Cullinet Software, Westwood, MA, USA Lines: 33 Xref: mnetor comp.lang.misc:816 comp.software-eng:25 crowl@cs.rochester.edu (Lawrence Crowl) writes: | For instance, the arithmetic right shift | provided by many machines provides division by two except when the number is | negative and odd. Should languages be designed around this quirk? I do not | think so. This is not so simple... What do you mean by "division by 2"? There are actually at least two ways of doing integer division: one way is to always round the mathematical quotient towards 0. This is the common, or "Fortran", way to do it, but to a certain extent it is historical accident that most programming languages do it this way. Of course, this is *not* what arithmetic right shift does. But this method is not necessarily the most natural way to do division. In many cases, this is more natural: round the mathematical quotient *down*, that is, more negative. This is equivalent to the common way for positive quotients, but is different for negative quotients: (-1)/2 = -1. (If you think this method is silly, consider the problem: I give you a time expressed in minutes before-or-after midnight, 1 Jan 1980. Find the hour it occurs in, expressed in hours before-or-after midnight, 1 Jan 1980. The advantage of the second division here is that the quotient is computed so the remainder is always positive.) I have had to write functions in several programming languages to perform this second form of division. Dale -- Dale Worley Cullinet Software ARPA: culdev1!drw@eddie.mit.edu UUCP: ...!seismo!harvard!mit-eddie!culdev1!drw If you get fed twice a day, how bad can life be?