sommar@enea.UUCP (Erland Sommarskog) (03/23/86)
In article <4700020@ada-uts> stt@ada-uts.UUCP writes: > >AND, OR, and XOR are defined on boolean arrays (whether packed or not). >If you have a great desire to apply these operators to Integers, >then you will have to implement them via pragma-Interfaced functions (in C >or assembler), or hope that your compiler supports packed boolean arrays >and Unchecked_Conversion between Integers and appropriately-long >packed, constrained, boolean arrays. NO, NO, NO! The author of this doesn't seem very knowledgeable in Ada. What you do if you need logical operators on integers is of course: FUNCTION "XOR"( IN Number : integer) RETURN boolean_value; And to implement this functions is not very hard, unless you don't want go as fast as an assembler instruction. Erland Sommarskog
Bryan@SU-SIERRA.ARPA (Doug Bryan) (03/25/86)
I think Erland ment something like: function "xor" (l, r : integer) return integer; The real question is why would you want to xor two "integers". If you are treating integers as arrays of (16 | 32) booleans, do so... type word is array (0 .. 15) of boolean; pragma pack (word); now the functions xor, not, and, or are predefined for type word. doug -------
stt@ada-uts (03/31/86)
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! -S. Tucker Taft Technical Director of Ada compiler development ;-) Intermetrics, Inc. 733 Concord Ave Cambridge, MA 02138
desj@brahms.BERKELEY.EDU (David desJardins) (04/15/86)
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! Easy. Just use repeated division by two to extract the bits, and multiplication by two to construct the result. -- David desJardins
dik@zuring.uucp (Dik T. Winter) (04/17/86)
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
dik@zuring.uucp (Dik T. Winter) (04/17/86)
In article <290@zuring.UUCP> dik@zuring.UUCP (Dik T. Winter) (I) write: >Balderdash. What is "(-1) and (1)"? Yes, 0 on 2's complement machines, >1 on 1's complement machines. To paraphrase myself: Balderdash. It is the other way 'round of course. Just got carried away by all those 0's and 1's. (Never post news at night.) -- 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