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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.236.110.3 with SMTP id t3mr1460971yhg.3.1390429578045; Wed, 22 Jan 2014 14:26:18 -0800 (PST) X-Received: by 10.50.154.99 with SMTP id vn3mr514545igb.8.1390429577804; Wed, 22 Jan 2014 14:26:17 -0800 (PST) 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!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!f11no131171qae.1!news-out.google.com!vg8ni5igb.0!nntp.google.com!c10no1233707igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 22 Jan 2014 14:26:17 -0800 (PST) In-Reply-To: <52e00586$0$6658$9b4e6d93@newsspool2.arcor-online.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: <52e00586$0$6658$9b4e6d93@newsspool2.arcor-online.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to round to the nearest fixed-point value? From: adambeneschan@gmail.com Injection-Date: Wed, 22 Jan 2014 22:26:17 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 2378 X-Received-Body-CRC: 1782246091 Xref: news.eternal-september.org comp.lang.ada:18252 Date: 2014-01-22T14:26:17-08:00 List-Id: On Wednesday, January 22, 2014 9:53:29 AM UTC-8, G.B. wrote: > 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; This rewrite has nothing to do with the OP's code. The OP's program does not perform High'Round anywhere, nor does it have any type conversions to which 4.6 would apply. -- Adam > 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.