From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,582dff0b3f065a52 X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,582dff0b3f065a52 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,bc1361a952ec75ca X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-28 13:49:47 PST Path: archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.bc.home.com.POSTED!not-for-mail From: kaz@ashi.footprints.net (Kaz Kylheku) Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Subject: Re: Subtle Bugs, kudos Ada (was How Ada ...Red Code ...) Supersedes: References: <3B6555ED.9B0B0420@sneakemail.com> <87n15lxzzv.fsf@deneb.enyo.de> <3B672322.B5EA1B66@home.com> <4a885870.0108112341.7ce02ac0@posting.google.com> <3B834E5D.B0D26AB1@adaworks.com> <9lvsic$bet9s$1@ID-9852.news.dfncis.de> <9m0193$grs$1@bird.wu-wien.ac.at> <3B83F042.4CFB073D@home.com> <3B8462C8.5596C089@yahoo.com> <87n14nmbf8.fsf@deneb.enyo.de> <3B89A809.46083436@yahoo.com> <871ylxpxu6.fsf@deneb.enyo.de> <3B8AA131.3FCC0E9A@yahoo.com> <87g0ad44ab.fsf@deneb.enyo.de> <3B8B1130.97FFDD66@yahoo.com> <3B8BD171.32C155D2@yahoo.com> <_SRi7.115023$B37.2552767@news1.rdc1.bc.home.com> <3B8BED46.3DEE945B@yahoo.com> Organization: Psycho-Neurotic Institute for the Very, Very Nervous Reply-To: kaz@ashi.footprints.net User-Agent: slrn/0.9.6.3 (Linux) Message-ID: Date: Tue, 28 Aug 2001 20:49:46 GMT NNTP-Posting-Host: 24.68.85.82 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.bc.home.com 999031786 24.68.85.82 (Tue, 28 Aug 2001 13:49:46 PDT) NNTP-Posting-Date: Tue, 28 Aug 2001 13:49:46 PDT Xref: archiver1.google.com comp.lang.ada:12533 comp.lang.c:77280 comp.lang.c++:86296 Date: 2001-08-28T20:49:46+00:00 List-Id: In article <3B8BED46.3DEE945B@yahoo.com>, Joe Maun wrote: >Kaz Kylheku wrote: > >> The entire paragraph from C99 says this: >> >> The result of E1 >> E2 is right shifted E2 bit positions. >> If E1 has an unsigned type, or if E1 has a signed type and >> a nonnegative value, the value of the result is the integral >> part of the quotient of E1 divided by the quantity, 2 raised to >> the power of E2. If E1 has a signed type and a negative value, >> the resulting value is implementation-defined. >> >> So you see, when the result is not implementation-defined, it is actually >> defined *arithmetically* as the quotient of an integer division by a power >> of two. > >The *value* is defined arithmetically, while the bit positions are >defined in terms of bit-shifts. Both are properties of the shift Under ones' complement, the bit pattern 1111...111 is non-negative; it represents the value zero. When this is right shifted by 1, it must result in the value 0. That value could be represented as 0000...00 or 1111...11. What about the sign-magnitude zero, 1000...000? When that is shifted right, you can get 1000..000 or 0000..000. Is that a bit shift? >operator. When one is implementation defined, the other may still be >well defined. What do you think the first sentence is there for? I think it's superflous text that helps to clarify what the operator is generally for. The subsequent sentences form an exhaustive partition of all the possibilities: unsigned E1, non-negative signed E1, and negative signed E1. Each partition of the E1 input is assigned a behavior. The first two partitions have an arithmetically defined resulting value. That value is positive, and therefore it has a corresponding portable binary representation. So, effectively, in these first two partitions, bit shifting behavior is specified implicitly as a division by a power of two, except in cases like the alternate zeros in ones' complement and sign-magnitude. The third partition leads to an implementation-defined value, which could be anything. If these sentences did not provide semantics for all the partitions, then the first sentence would apply to the remaining cases that are not covered. So for instance, if nothing were mentioned about the handling of an unsigned E1, then the interpretation would be that E1 is right shifted E2 bit positions. I believe that you have to apply the text which has the most specific semantics for a given case; it overrides any general text. The general text is that E1 >> E2 is E1 right shifted by E2 bits. This is obviously not the case if the sign bit does not shift along with the others. If the value of the sign bit does shift along with the others, then the only question that remains is what replaces its value: is a 1 shifted in or a 0? Under two's complement, these two possibilities are called arithmetic and logical shift. If the only question were what value is shifted in, then the standard could easily have specific text to that effect. As it stands, the general text is at odds with the specific text for negative E1. The specific text dominates.