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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8af7fe40dc0a55ae X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!i24g2000prf.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Restarting Tread: Why isn't this program working with Unchecked_Converstion Date: Thu, 15 Jan 2009 13:24:04 -0800 (PST) Organization: http://groups.google.com Message-ID: <6540d68e-2cc7-45aa-a5d2-ac16fa335822@i24g2000prf.googlegroups.com> References: 40239b21-b265-467f-9b27-5890fb2f4c67@w1g2000prm.googlegroups.com NNTP-Posting-Host: 81.156.241.243 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1232054644 28339 127.0.0.1 (15 Jan 2009 21:24:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 15 Jan 2009 21:24:04 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i24g2000prf.googlegroups.com; posting-host=81.156.241.243; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.5) Gecko/2008120121 Firefox/3.0.5,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:4327 Date: 2009-01-15T13:24:04-08:00 List-Id: On Jan 15, 8:53=A0pm, ChristopherL wrote: > I'm restarting the tread [How to put 200 into an integer sub-type of > 16 bits (code included)] with a new subject because the last was too > long! > > How can I be getting the below error message with > "Unchecked_Conversion". > > Isn't Unchecked_conversion just suppose to copy bits? > > I want to copy bits from an Ada float to a user defined short integer > maintaining the same bit representation. > > Arg:Float; =A0-- From this with a value of 200 > subtype Short_integer is Integer range -(2 ** 7) .. ((2 ** 7) - 1 ); > Result2: Short_integer; --to this, and I want to round Arg > > These 3 definitions of Arg and Result2 can not chanage. > > Arg will never be negative or greater than 200/201. > > Chris L. > > with Unchecked_Conversion; > > procedure test is > =A0 subtype Short_integer1 is Natural range 0.. ((2 ** 10) - 1); > =A0 subtype Short_integer2 is Integer range -(2 ** 7)..((2 ** 7) - 1); > > =A0 subtype A_Float is Float; > > =A0 subtype A_Natural is Natural range 0..((2 ** 8) - 1); > =A0 -- The next line of code (if used) gives compilation error message: > =A0 -- A_NATURAL does not denote a first subtype > =A0 -- for A_Natural'Size use Short_integer1'Size; > > =A0 Size_Of_Float : integer :=3D Float'Size; =A0 =A0 =A0--32 bits long > > =A0 Size_Of_short_integer: integer :=3D Short_integer1'Size;--10 bits > long > =A0 Size_Of_short_int: integer :=3D Short_integer2'Size;--10 bits long > > =A0 Size_Of_Natural: integer :=3D A_Natural'Size; =A0 =A0 =A0 --8 bits lo= ng Are you sure about those sizes? Try: Put_Line ("Float'Size =3D" & Integer'Image (Float'Size)); Put_Line ("Short_integer1'Size =3D" & Integer'Image (Short_integer1'Size)); Put_Line ("Short_integer2'Size =3D" & Integer'Image (Short_integer2'Size)); Put_Line ("Natural'Size =3D" & Integer'Image (Natural'Size)); An aside - probably wasted if you don't understand subtypes and ranges - but you don't have to assign everything to 'integer'. Instead you can store the constants like this: Size_Of_Float : constant :=3D Float'Size; The benefit is that you can mix this into just about any expression without having to bother about type conversions. > Result2 :=3D Get_Bits (Result1); Result2 is of type Short_integer2 - which _you_ defined to be of the range -128 to 127 (inclusive). Why are you surprised that 201 does fit??? And that's assuming the Unchecked_Conversion works - double check the actual sizes! Cheers -- Martin