From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Bitwise XOR?
Date: Sat, 04 Oct 2003 03:07:52 GMT
Date: 2003-10-04T03:07:52+00:00 [thread overview]
Message-ID: <3F7E3982.2070801@comcast.net> (raw)
In-Reply-To: mailman.28.1065177023.25614.comp.lang.ada@ada-france.org
Beard, Frank Randolph CIV wrote:
> You don't even need the Unchecked_Conversion.
>
> The following should work:
>
> function "xor"(Left,Right : in Integer) return Integer is
> pragma inline("xor");
> type Int_As_Mod is mod 2 ** Integer'size;
> begin
> return Integer( Int_As_Mod(Left) XOR Int_As_Mod(Right) );
> end "xor";
>
> Theoretically, Unchecked_Conversion should be faster I guess.
> Is that why you chose it, or did you do some timing tests
> that showed a noticeable difference?
First, the Unchecked_Conversion is correct. The above code will not do
what you expect with negative numbers, it will raise an exception. The
Unchecked_Conversion will not only prevent the "unnecessary" check, but
will also be faster.
--
Robert I. Eachus
"Quality is the Buddha. Quality is scientific reality. Quality is the
goal of Art. It remains to work these concepts into a practical,
down-to-earth context, and for this there is nothing more practical or
down-to-earth than what I have been talking about all along...the repair
of an old motorcycle." -- from Zen and the Art of Motorcycle
Maintenance by Robert Pirsig
next prev parent reply other threads:[~2003-10-04 3:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-03 10:28 Bitwise XOR? Beard, Frank Randolph CIV
2003-10-04 2:57 ` Steve
2003-10-04 3:07 ` Robert I. Eachus [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-10-02 1:35 David N. Maez
2003-10-02 2:03 ` sk
2003-10-02 9:01 ` John McCabe
2003-10-02 8:30 ` Adrian Knoth
2003-10-02 12:46 ` Marin David Condic
2003-10-02 12:53 ` Adrian Knoth
2003-10-02 18:15 ` Jeffrey Carter
2003-10-03 12:26 ` Marin David Condic
2003-10-03 20:32 ` Jeffrey Carter
2003-10-03 22:41 ` Marin David Condic
2003-10-03 3:14 ` Steve
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox