comp.lang.ada
 help / color / mirror / Atom feed
From: njb@res.eng.uiowa.edu (Nate Bohlmann)
Subject: Re: Help with type conversion needed
Date: 1996/01/08
Date: 1996-01-08T00:00:00+00:00	[thread overview]
Message-ID: <4cq6ku$l5a@flood.weeg.uiowa.edu> (raw)
In-Reply-To: dewar.821029372@schonberg

Robert Dewar (dewar@cs.nyu.edu) wrote:
: Nathan keeps worrying about some bias that needs to be added when
: converting unsigned values to signed and vice versa. The whole point
: of 2's complement notation is that no such bias is required.

: For example 16#FFFF# is either -1 or 65_535 depending on how you
: interprete it (signed or unsigned).

Right, and this is why I don't want it to be a noop.  If I have a range
of values from -32768 to 32767, and I want to shift that range to 0 to
65535, simply doing a noop is NOT sufficient..  i.e. -32768 maps to 0 
and 32767 maps to 65535.  -1 should map to 32767, NOT 65535.   

If I simply interpret the bit pattern as signed or unsigned I will not
keep the relative values that I need.. 

I guess this isn't really a type conversion question so much as a range
conversion question.  I fooled the 2.07 GNAT complier by adding 32767 and 1
and the compiler spit out the proper add but the 3.01 compiler complains
that the addition is out of range (as I think it probably should).

As far as a real example, I'm not quite sure I could give one other than
what I've said above.  It would just be a simple addition that fails in
the semantic checker because what I'm trying to add is out of range.

I think probably the best answer so far is to use a bigger (in terms of
bits).  Is this just a nasty side effect of the strong typing? (btw, I'm
a very strong supporter of the strong typing paradigm lest any of you
get the wrong idea.. :-)  I just would like to be able to do this eloquently
and can't seem to find a way to do it.

Nate

--
Nathan Bohlmann                           preferred->   njb@res.eng.uiowa.edu
Computer Engineering Graduate Student              njb@vu-alumni.elfwerks.com
University of Iowa, Iowa City, IA                           njb@eng.uiowa.edu
use PH at uiowa.edu for more info..                             (319)354-2634
   Dr. Alan Keyes for President! '96      http://sandh.com/keyes/index.html
                  http://vu-alumni.elfwerks.com/~njb




  parent reply	other threads:[~1996-01-08  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4ckmb7$vo0@flood.weeg.uiowa.edu>
     [not found] ` <DKrJpC.9HE.0.-s@inmet.camb.inmet.com>
     [not found]   ` <4cnivs$m1k@flood.weeg.uiowa.edu>
1996-01-08  0:00     ` Help with type conversion needed Tucker Taft
     [not found]     ` <dewar.821029372@schonberg>
1996-01-08  0:00       ` Nate Bohlmann [this message]
1996-01-08  0:00         ` Robert Dewar
1996-01-08  0:00           ` Keith Thompson
1996-01-09  0:00         ` Geert Bosch
     [not found]           ` <dewar.821197198@schonberg>
1996-01-09  0:00             ` Nate Bohlmann
replies disabled

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