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=-0.9 required=5.0 tests=BAYES_00,FROM_NUMERIC_TLD autolearn=no 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!news1.google.com!news.glorb.com!news-peer-lilac.gradwell.net!not-for-mail From: "Stuart" Newsgroups: comp.lang.ada 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> 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 17:50:14 -0000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350 Message-ID: <496f72f0$1_1@glkas0286.greenlnk.net> X-Original-NNTP-Posting-Host: glkas0286.greenlnk.net NNTP-Posting-Host: 20.133.0.1 X-Trace: 1232041823 news.gradwell.net 510 dnews/20.133.0.1:56421 X-Complaints-To: news-abuse@gradwell.net Xref: g2news2.google.com comp.lang.ada:4312 Date: 2009-01-15T17:50:14+00:00 List-Id: "ChristopherL" wrote in message news:d3b7ad53-af51-4ac5-9167-7cb99e61b2b1@v5g2000pre.googlegroups.com... On Jan 15, 7:55 am, ChristopherL wrote: > After some size investigation here is what I found. > 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. This is not really relevant, but to anything you have defined as a requirement (because you do not explicitly specify you want these sizes, they just happen to be what the system chose for you). > When I try to do it using the below program, I get the below error > message. ... > procedure test is > subtype Short_integer1 is INTEGER range -(2 ** 7)..((2 ** 7) - 1); rewriting this subtype Short_integer1 is integer range -128..127; > subtype A_Float is Float; > Arg : A_Float; > Result : Short_integer1; > Begin > > Arg := 200.0; > > Result := Short_integer1(Arg); Given that you have declared Short_integer1 to have a range of -128..127 what value do you think should be put in Result when you provide a value of 200.0? Are you, perhaps expecting wrap-around semantics? if (Arg > A_float(Short_integer1'last)) then Result := Short_integer1(A_float(Short_integer1'last) - Arg); else Result := Short_integer1(Arg); end if; > End test; > Can Ada intelligent person modify this program to make it correctly > put the value in variable "Arg" into the variable "Result". At the moment I would say no as we do not know how you think the contradiction of Result being in the -128..127 and you wanting the value 200 should be resolved. Ada is doing what it is meant to do and pointing out to you that the current behaviour is in error because you are exceeding the constraints (range of legal values) of Result. As there seems to be some difficulty communicating requirements in terms that both parties can understand, perhaps you can clarify your requirement by indicating what values you expect for a number of cases bearing in mind that with your current definition (which you don't want to change) Result must be an integer value in the range -128..127: Arg Result 0.00 0.49 0.50 0.51 1.00 1.49 1.50 1.51 126.50 126.51 127.00 127.01 127.49 127.50 127.51 128.00 199.49 199.50 199.51 199.99 200.00 -- Stuart