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,f9957894e0bdf128 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!35g2000pry.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: How to put 200.0 (is float variable of 32 bits) into an integer sub-type of 10 bits (complete program included) Date: Thu, 15 Jan 2009 08:36:55 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <407ae64d-3cb3-4310-b59e-f1bbae9910a5@t39g2000prh.googlegroups.com> <71gqm49eatq868htrvd7eghm3m8su8kcbl@4ax.com> <7b017de2-951a-414a-8290-111353fe02f8@r15g2000prd.googlegroups.com> <3f1f2f67-5d69-4baf-8e8c-0d2b5f68475f@p36g2000prp.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1232037415 25071 127.0.0.1 (15 Jan 2009 16:36:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 15 Jan 2009 16:36:55 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 35g2000pry.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:4300 Date: 2009-01-15T08:36:55-08:00 List-Id: On Jan 15, 7:55 am, ChristopherL wrote: > After some size investigation here is what I found. > > Here is a program that impliments everything that I have been trying > to do. > > I want to put the value of variable "Arg" into variable "Result" > without changing > the definitions of these two variables. > > Arg is a variable with 32 bits and will never be negative or greater > than 200. > Result is a variable of 10 bits. > > When I try to do it using the below program, I get the below error > message. The reason why the CONSTRAINT_ERROR/Range_Check error message is happening has been explained to you, clearly, multiple times. If you still don't understand it, you're not going to understand it if we tell you again. -- Adam > > Chris L. > > --with Unchecked_Conversion; > > procedure test is > subtype Short_integer1 is INTEGER range -(2 ** 7)..((2 ** 7) - 1); > subtype A_Float is Float; > > subtype Short_integer2 is Integer range 0.. ((2 ** 8) - 1); > subtype A_Natural is Natural range 0..((2 ** 8) - 1); > > --FYI1 > Size_Of_Float : integer := Float'Size; -- 32 > Size_Of_short_int: integer := Short_integer1'Size; -- > 10 !!!!!!! Size is 10 > > --FYI2 > Size_Of_short_integer: integer := Short_integer2'Size; -- 8 > Size_Of_Natural: integer := A_Natural'Size; -- 8 > > Arg : A_Float; > Result : Short_integer1; > Begin > > Arg := 200.0; > > Result := Short_integer1(Arg); > > End test; > > --Run Time Error Message Follows > Unhandled exception: > > CONSTRAINT_ERROR raised in MAIN > > Range_Check_Failed > > Exception raised at code address: 0x412494 > +++ Program completed with exit code 1 at 01/15/09 07:37:44 > +++ > --------------------------------------------------------------------------------------------------------------