comp.lang.ada
 help / color / mirror / Atom feed
* AND, OR & XOR on integers
  1986-03-18 16:55 ` Orphaned Response stt
@ 1986-03-23 16:12   ` Erland Sommarskog
  1986-03-31 14:34     ` stt
  0 siblings, 1 reply; 6+ messages in thread
From: Erland Sommarskog @ 1986-03-23 16:12 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: AND, OR & XOR on integers
@ 1986-03-25 16:20 Doug Bryan
  0 siblings, 0 replies; 6+ messages in thread
From: Doug Bryan @ 1986-03-25 16:20 UTC (permalink / raw)



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
-------

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: AND, OR & XOR on integers
  1986-03-23 16:12   ` AND, OR & XOR on integers Erland Sommarskog
@ 1986-03-31 14:34     ` stt
  1986-04-14 23:48       ` David desJardins
  0 siblings, 1 reply; 6+ messages in thread
From: stt @ 1986-03-31 14:34 UTC (permalink / raw)



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: AND, OR & XOR on integers
  1986-03-31 14:34     ` stt
@ 1986-04-14 23:48       ` David desJardins
  1986-04-17  2:09         ` Dik T. Winter
  0 siblings, 1 reply; 6+ messages in thread
From: David desJardins @ 1986-04-14 23:48 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: AND, OR & XOR on integers
  1986-04-14 23:48       ` David desJardins
@ 1986-04-17  2:09         ` Dik T. Winter
  1986-04-17  2:20           ` Dik T. Winter
  0 siblings, 1 reply; 6+ messages in thread
From: Dik T. Winter @ 1986-04-17  2:09 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: AND, OR & XOR on integers
  1986-04-17  2:09         ` Dik T. Winter
@ 1986-04-17  2:20           ` Dik T. Winter
  0 siblings, 0 replies; 6+ messages in thread
From: Dik T. Winter @ 1986-04-17  2:20 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1986-04-17  2:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-03-25 16:20 AND, OR & XOR on integers Doug Bryan
     [not found] <306@telesoft.UKE>
1986-03-18 16:55 ` Orphaned Response stt
1986-03-23 16:12   ` AND, OR & XOR on integers Erland Sommarskog
1986-03-31 14:34     ` stt
1986-04-14 23:48       ` David desJardins
1986-04-17  2:09         ` Dik T. Winter
1986-04-17  2:20           ` Dik T. Winter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox