Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mcgill-vision.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: net.arch Subject: Re: Right shift vs. divide (change divide!) Message-ID: <345@mcgill-vision.UUCP> Date: Mon, 13-Jan-86 03:29:58 EST Article-I.D.: mcgill-v.345 Posted: Mon Jan 13 03:29:58 1986 Date-Received: Wed, 15-Jan-86 08:13:55 EST References: <124000005@ima.UUCP> <4772@alice.UUCP> <1016@turtlevax.UUCP>, <32@calgary.UUCP> Organization: McGill University, Montreal Lines: 57 Radford Neal (radford@calgary), U of Calgary, writes (in <32@calgary.UUCP>): > Rather than get rid of the arithmetic right shift, one could instead > change the divide instruction so it does what mathematicians have > always thought division meant. > [ ie, truncate towards negative infinity rather than zero ] > [ example: -3/2 versus 3/2 ] > With this definition, a right shift divides by two and masking off > the lower bit gives you the remainder. > Does anyone know any reason, other than inertia, why divides shouldn't > be changed to work this way. Gee....and I always thought mathematicians thought -3/2 was -1.5 (;-). [ Note: By x%y I mean x mod y (remainder when x is divided by y) x>>y x right-shifted y bits x^y x raised to the power y No flames please, some people out there probably don't know C (I can hear it now: "Doesn't >> mean `much greater than'?"). ] Only reason I can see for a mathematician -- for anyone -- to want it to work this way is that then x-(y*(x/y)) is always >=0. Unfortunately, doing this breaks other nice properties, in particular that x/y equals -((-x)/y). It therefore means that hardware can't handle negative numbers by simply negating before and after the operation. I don't see why you aren't satisfied with -3/2=-1 and -3%2=-1. You still have that x=(x%y)+(y*(x/y)), which is really all mathematicians demand, as far as I know (flame retardant: my knowledge of number theory is limited to undergrad level). What do you want done with -3/-2 or 3/-2? There are some algorithms which are easier to implement with your sort of division, but I would be surprised if it were not the case that in most of them, the divisor *is* a power of two and hence right shifts are appropriate. You seem to want x%(2^y)=(x>>y). Inertia is a powerful reason. There has been much discussion on groups like net.lang.c and net.unix about portability; the general idea is that a programmer should assume as little as possible. Unfortunately, programmers tend to assume that things like the laws of arithmetic will not change and hence assumptions about them can safely be wired into the code. I feel certain there is a lot of code out there which would break on any such machine. I know I would consider such a machine broken (out of incompatibility with the rest of the world and with existing code -- yes, I know that's what you mean by inertia). -- der Mouse USA: {ihnp4,decvax,akgua,etc}!utcsri!mcgill-vision!mouse philabs!micomvax!musocs!mcgill-vision!mouse Europe: mcvax!decvax!utcsri!mcgill-vision!mouse mcvax!seismo!cmcl2!philabs!micomvax!musocs!mcgill-vision!mouse Hacker: One who accidentally destroys / Wizard: One who recovers it afterward