From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bb791bffed99d85a X-Google-Attributes: gid103376,public From: njb@res.eng.uiowa.edu (Nate Bohlmann) Subject: Re: Help with type conversion needed Date: 1996/01/08 Message-ID: <4cq6ku$l5a@flood.weeg.uiowa.edu>#1/1 X-Deja-AN: 134430666 distribution: world references: <4ckmb7$vo0@flood.weeg.uiowa.edu> <4cnivs$m1k@flood.weeg.uiowa.edu> organization: University of Iowa, Iowa City, IA, USA newsgroups: comp.lang.ada Date: 1996-01-08T00:00:00+00:00 List-Id: 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