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-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!2g2000prl.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Type casting Date: Mon, 26 Oct 2009 13:09:12 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <4acc8c20$0$284$14726298@news.sunsite.dk> <4acdb7aa$0$283$14726298@news.sunsite.dk> <1256585214.3272.12.camel@HERMES> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1256587752 16199 127.0.0.1 (26 Oct 2009 20:09:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 26 Oct 2009 20:09:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 2g2000prl.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8796 Date: 2009-10-26T13:09:12-07:00 List-Id: On Oct 26, 12:26=A0pm, Bruno wrote: > Hi, > > I have a small mess with the conversion of numeric types in the > following program > > http://paste.ideaslabs.com/show/q6vOGqlyYJ > > I really do not know how to interpret the operation (E / 2) because > although the operation is composed of two numbers such as "Positive" > outcome can be of type "Float" and, of course, the "Integer" (attribute) > returns an integer but the closest to real number and what > need my program is that it returns the integer part regardless > the decimal part. No, the outcome of E / 2 cannot be of type float. In some other programming languages it can. But in Ada, if you divide two integers, the result is an integer and is always truncated downward---the remainder is thrown away. In this example, the type conversion Integer (E/2) is redundant since the result of E/2 is already an integer. If you say Integer (Float (E) / 2.0) then the result of the division would be a float, and it would round *upward* when converting to an integer (if E is odd). But that isn't what you want for this algorithm. > > I tried creating a small building under the following function > > http://paste.ideaslabs.com/show/7y97bn4G6 > > but by requiring Float type parameters for the algorithm does not work > prev. I'm not sure what you mean. It looks like this second example was trying to truncate a float to an integer (toward zero), and it appears that it works fine. But you can do the same thing much more easily with return Integer (Float'Truncation (F)); Float'Truncation truncates F to an integer, truncating toward zero, but it leaves the result as a Float; when you convert that to an integer, no truncation or rounding is necessary since the result of Float'Truncation already has an integral value. Anyway, I'm not sure what about this doesn't work. Hope this helps, -- Adam