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!news4.google.com!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!zen.net.uk!dedekind.zen.co.uk!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> <8e64f509-f6fe-4d86-ae1a-fe0b1c88555a@v5g2000pre.googlegroups.com> <9fa07f9b-90bf-4a28-bf8e-09c2152bd43f@o40g2000prn.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 18:34:10 -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: <496f7d3b$1_1@glkas0286.greenlnk.net> X-Original-NNTP-Posting-Host: glkas0286.greenlnk.net NNTP-Posting-Host: 20.133.0.1 X-Trace: 1232044475 news.gradwell.net 506 dnews/20.133.0.1:57163 X-Complaints-To: news-abuse@gradwell.net Xref: g2news2.google.com comp.lang.ada:4315 Date: 2009-01-15T18:34:10+00:00 List-Id: "ChristopherL" wrote in message news:a61abb30-bc60-4d13-b298-f369ddc8f741@z6g2000pre.googlegroups.com... > On Jan 15, 9:09 am, christoph.gr...@eurocopter.com wrote: > > On 15 Jan., 17:46, ChristopherL wrote: > > > > > Can some the Ada intelligent person modify this program to make it > > > correctly > > > put the value in variable "Arg" into the variable "Result". > > > > Can anybody please help me to seat 200 people in a bus with 127 seats. > > But, isn't 2^10 greater than 200! Yes it is. > So, is there some way to put 200.0 into the variable "Result". Not in a way that means Result has the value 200 because the declared type of Result (Short_integer1) is specified as having the range -128..127. If you want Result to hold values in the range 0..200 you need to declare its type accordingly. > Ideally, if I achieve my ultimate goal I would like to later look at > "Result" and be able to reconstruct "Arg" (200.0) from what is in > "Result". You don't say to what precision you want Arg to be restored - it would seem that you are only expecting to get whole number values. In which case, if you are wanting to keep all your definitions as they are, you might best be doing wrap around during the conversions. For example: if (Arg > 127.0) then Result := Short_integer1(127.0 - Arg); else Result := Short_integer1(Arg); end if: if (Result < 0) then Arg := A_float(127 - Result); -- I think the calculation will be done in the base type of Result (integer), -- if not you can use integer'(result) to be exlicit about it. else Arg := A_float(Result); end if; Of course, you should comment heavily to explain this odd-ball coding and why you don't simply declare the type to be in the range 0..200. Regards -- Stuart