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.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!cmcl2!seismo!mcvax!zuring!dik From: dik@zuring.uucp (Dik T. Winter) Newsgroups: net.lang.ada Subject: Re: AND, OR & XOR on integers Message-ID: <290@zuring.UUCP> Date: Wed, 16-Apr-86 21:09:51 EST Article-I.D.: zuring.290 Posted: Wed Apr 16 21:09:51 1986 Date-Received: Sat, 19-Apr-86 14:16:31 EST References: <1255@enea.UUCP> <4700025@ada-uts> <13158@ucbvax.BERKELEY.EDU> Reply-To: dik@zuring.UUCP (Dik T. Winter) Organization: CWI, Amsterdam Apparently-To: rnews@mcvax List-Id: In article <13158@ucbvax.BERKELEY.EDU> desj@brahms.UUCP (David desJardins) writes: >In article <4700025@ada-uts> stt@ada-uts writes: >> >>function "XOR"(Left, Right : in Integer) return Integer; >> >> would be a better start :-) >> >>Also, if you figure out how to implement this portably >>in Ada, without using unchecked conversion, lemme know! Portable *with* unchecked conversion? How? Conversion to what? > > Easy. Just use repeated division by two to extract the bits, and >multiplication by two to construct the result. > Balderdash. What is "(-1) and (1)"? Yes, 0 on 2's complement machines, 1 on 1's complement machines. So is there a portable way to decide whether a machine is 2's or 1's complement? We might enquire whether INTEGER'FIRST = - INTEGER'LAST but although from falsehood of this statement you might safely conclude that the machine is 2's complement, the reverse is certainly not true (a 2's complement might reserve the most negative number for special purposes). Another thing though, what should the system do if the value returned is out of range (most negative number on a machine that reserves it)? Raise NUMERIC_ERROR? You wouldn't want that. Moral: you do not want logical operators on integers but logical operators on packed array's of booleans. The first part is required by the language, the second part is left to the discretion of the implementors. So: push the implementors to let pack work. (I ignored decimal machines in this article; but implementing Ada on such a machines will be fruitless.) -- dik t. winter, cwi, amsterdam, nederland UUCP: {seismo,decvax,philabs,okstate,garfield}!mcvax!dik or: dik@mcvax.uucp ARPA: dik%mcvax.uucp@seismo.css.gov