Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.16 $; site ISM780.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!houxm!whuxl!whuxlm!akgua!gatech!seismo!harvard!bbnccv!ISM780!marv From: marv@ISM780.UUCP Newsgroups: net.arch Subject: Re: (Orphan) Re: Right shift vs. divide Message-ID: <27700010@ISM780.UUCP> Date: Fri, 10-Jan-86 18:34:00 EST Article-I.D.: ISM780.27700010 Posted: Fri Jan 10 18:34:00 1986 Date-Received: Tue, 14-Jan-86 06:01:11 EST References: <4772@alice.UUCP.UUCP> Lines: 42 Nf-ID: #R:alice.UUCP:4772:ISM780:27700010:000:1340 Nf-From: ISM780!marv Jan 10 18:34:00 1986 >> 1)if the operand is positive right shift. >> >> 2)if the operand is negative, negate the operand before shifting, then >> right shift, and then negate the result. > ^^^^^^^^^^^ >> >> if you want, try the infamous right shift all 1's (-1). >> >> the division is round toward zero (ala fortran). >> >> the MV series from data general perform arithmetic right shifting >> correctly >Still more evidence that the problem is harder than it looks: >the above algorithm fails if the dividend is the most negative number. >Consider, for example, a 32-bit machine. Let's divide >-2147483648 by 2. The answer should be -1073741824. > -2147483648 is 80000000 hex. Negate it and you > get integer overflow. If this is masked, most machines > will give you 80000000 hex back. > > Shift 80000000 right 1 bit, giving C0000000. > > Negate this again, giving 40000000. > >Thus, the sign gets lost. >/* End of text from ISM780:net.arch */ > Boy this shure is harder than it looks. Note that the algorithm said "shift right" *not* "arithmetic shift right" 800000000>>1 is 40000000 (not C0000000) 40000000 negated is C0000000 which is -1073741824 However I agree with Tim. It would be better if -1/2 produced -1. If you are interested in my reasons, send mail. Marv Rubinstein -- Interactive Systems