comp.lang.ada
 help / color / mirror / Atom feed
From: dik@zuring.uucp (Dik T. Winter)
Subject: Re: AND, OR & XOR on integers
Date: Wed, 16-Apr-86 21:09:51 EST	[thread overview]
Date: Wed Apr 16 21:09:51 1986
Message-ID: <290@zuring.UUCP> (raw)
In-Reply-To: 13158@ucbvax.BERKELEY.EDU

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

  reply	other threads:[~1986-04-17  2:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
1986-04-17  2:20           ` Dik T. Winter
1986-03-25 16:20 Doug Bryan
replies disabled

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