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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Wed, 22 Jan 2014 18:53:29 +0100 From: "G.B." User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to round to the nearest fixed-point value? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <52e00586$0$6658$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 22 Jan 2014 18:53:11 CET NNTP-Posting-Host: 98263bd0.newsspool2.arcor-online.net X-Trace: DXC=LYgRV0nmbJafF8a^:6>b7eA9EHlD;3Ycb4Fo<]lROoRa8kFjLh>_cHTX3jmJ;PjdjcWXRa X-Complaints-To: usenet-abuse@arcor.de Xref: news.eternal-september.org comp.lang.ada:18250 Date: 2014-01-22T18:53:11+01:00 List-Id: On 22.01.14 17:48, Natasha Kerensikova wrote: > function Convert (Value : High) return Low is > begin > return Low'Round (Value); > end Convert; In view of LRM 4.6, Numeric Type Conversion, I speculate that the compiler might be right. If only I knew how truncation might play a role(+): * If the target type is a decimal fixed point type, then the result is truncated (toward 0) if the value of the operand is not a multiple of the small of the target type. Then, rewriting, function Convert (Value : High) return Low is Result : constant High := High'Round (Value); begin return Low (Result); end Convert; Result has 0.999 exactly if this is a multiple of High'Small (it is, with GNAT on Intel), but converting to Low truncates because Low'Small is too big by a factor of 10. __ (+) Low'Round takes a universal_real (and returns Low'Base); does universality affect things?