comp.lang.ada
 help / color / mirror / Atom feed
From: Brian Drummond <brian_drummond@btconnect.com>
Subject: Re: What is the best way to convert Integer to Short_Short_Integer?
Date: Fri, 11 Jun 2010 13:31:55 +0100
Date: 2010-06-11T13:31:55+01:00	[thread overview]
Message-ID: <fla4169o7ns6l6u2m23m8d9epu3tpunlqt@4ax.com> (raw)
In-Reply-To: husneh$r0d$1@tornado.tornevall.net

On Fri, 11 Jun 2010 00:07:16 -0700, "Jeffrey R. Carter"
<spam.jrcarter.not@spam.acm.org> wrote:

>Adrian Hoe wrote:
>> 
>> I have a number which is in the range of -128..127 and is read as
>> Integer (32-bit). 
>>... we can use either method: type conversion
>> as Jeff suggested or use Unchecked_Conversion.
>
>Which byte of the 32-bit integer will Unchecked_Conversion return?

Good question. On which machine? :-)

>> Which is the preferred method? Short_Short_Integer (I) or
>> Unchecked_Conversion?
>
>A type conversion is preferred.

And it has no downside. If you need to distinguish between errors here and a
more general "constraint error", it is easy to wrap the conversion in a function
which locally handles "constraint error", and does something appropriate (e.g.
saturates, or raises "range error").

- Brian




      parent reply	other threads:[~2010-06-11 12:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-11  1:17 What is the best way to convert Integer to Short_Short_Integer? Adrian Hoe
2010-06-11  2:21 ` Adrian Hoe
2010-06-11  3:14 ` Jeffrey R. Carter
2010-06-11  4:26   ` Adrian Hoe
2010-06-11  7:07     ` Jeffrey R. Carter
2010-06-11  8:59       ` J-P. Rosen
2010-06-11 12:28       ` Maciej Sobczak
2010-06-11 19:05         ` Randy Brukardt
2010-06-13  4:26         ` BrianG
2010-06-13 18:07           ` Maciej Sobczak
2010-06-14  7:28             ` Georg Bauhaus
2010-06-14 16:45             ` Keith Thompson
2010-06-15  4:54               ` Martin Krischik
2010-06-22 21:48                 ` Keith Thompson
2010-06-15  2:24             ` BrianG
2010-06-15 21:21               ` Maciej Sobczak
2010-06-15 23:39                 ` Georg Bauhaus
2010-06-16  1:27                 ` BrianG
2010-06-11 12:31       ` Brian Drummond [this message]
replies disabled

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