comp.lang.ada
 help / color / mirror / Atom feed
From: adambeneschan@gmail.com
Subject: Re: How to round to the nearest fixed-point value?
Date: Wed, 22 Jan 2014 14:26:17 -0800 (PST)
Date: 2014-01-22T14:26:17-08:00	[thread overview]
Message-ID: <f7232f44-2e75-4c14-9509-81458b67f28a@googlegroups.com> (raw)
In-Reply-To: <52e00586$0$6658$9b4e6d93@newsspool2.arcor-online.net>

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.

  reply	other threads:[~2014-01-22 22:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-22 16:48 How to round to the nearest fixed-point value? Natasha Kerensikova
2014-01-22 17:53 ` G.B.
2014-01-22 22:26   ` adambeneschan [this message]
2014-01-23  9:21     ` Georg Bauhaus
2014-01-22 22:45 ` adambeneschan
2014-01-23  5:29   ` J-P. Rosen
2014-01-23  7:00     ` Natasha Kerensikova
2014-01-23  9:42     ` Georg Bauhaus
2014-01-23  7:02   ` Natasha Kerensikova
2014-01-23 16:41     ` adambeneschan
2014-01-24  9:58 ` Natasha Kerensikova
2014-01-24 22:30   ` Randy Brukardt
2014-01-24 22:47     ` Randy Brukardt
2014-01-26 14:19     ` Natasha Kerensikova
2014-01-28 23:43       ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox